import { useQuery } from "@tanstack/react-query"; import { getInterest, type getInterestArgs } from "api/api"; import { useTheme } from "~/hooks/useTheme"; import type { Theme } from "~/styles/themes.css"; import { Area, AreaChart } 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 = 16, 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}

); } // Note: I would really like to have the animation for the graph, however // the line graph can get weirdly clipped before the animation is done // so I think I just have to remove it for now. return (

Interest over time

); }