import { useQuery } from "@tanstack/react-query"; import { getActivity, getInterest, type getActivityArgs, type getInterestArgs, type ListenActivityItem, } from "api/api"; import Popup from "./Popup"; import { useState } from "react"; import { useTheme } from "~/hooks/useTheme"; import ActivityOptsSelector from "./ActivityOptsSelector"; import type { Theme } from "~/styles/themes.css"; import { Area, AreaChart, Line, LineChart, Tooltip } from "recharts"; import { RechartsDevtools } from "@recharts/devtools"; function getPrimaryColor(theme: Theme): string { const value = theme.primary; const rgbMatch = value.match( /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/ ); if (rgbMatch) { const [, r, g, b] = rgbMatch.map(Number); return "#" + [r, g, b].map((n) => n.toString(16).padStart(2, "0")).join(""); } return value; } interface Props { buckets?: number; artistId?: number; albumId?: number; trackId?: number; } export default function InterestGraph({ buckets = 14, artistId = 0, albumId = 0, trackId = 0, }: Props) { const { isPending, isError, data, error } = useQuery({ queryKey: [ "interest", { buckets: buckets, artist_id: artistId, album_id: albumId, track_id: trackId, }, ], queryFn: ({ queryKey }) => getInterest(queryKey[1] as getInterestArgs), }); const { theme } = useTheme(); const color = getPrimaryColor(theme); if (isPending) { return (

Interest over time

Loading...

); } else if (isError) { return (

Interest over time

Error: {error.message}

); } return (

Interest over time

); }