diff --git a/src/app/insights/components/InsightsDisplay.tsx b/src/app/insights/components/InsightsDisplay.tsx index 8ff7087e..f4c55e50 100644 --- a/src/app/insights/components/InsightsDisplay.tsx +++ b/src/app/insights/components/InsightsDisplay.tsx @@ -33,7 +33,8 @@ export default function InsightsDisplay() { setSelectedButton(dateChoice); }; - const [selectedButton, setSelectedButton] = useState("day"); + const [selectedButton, setSelectedButton] = + useState("day"); /* Handler & State for Currently Unused "To Now" Button const [useNow, setUseNow] = useState(true); @@ -41,7 +42,7 @@ export default function InsightsDisplay() { const handleUseNowClick = () => { setUseNow((prevUseNow) => !prevUseNow); }; */ - + const [now, setNow] = useState(null); const getDateRange = (selected: keyof typeof dateOffsets) => { @@ -51,12 +52,12 @@ export default function InsightsDisplay() { const end = now; return { start, end }; }; - + const dateOffsets = { day: 24 * 60 * 60 * 1000, week: 7 * 24 * 60 * 60 * 1000, month: 30 * 24 * 60 * 60 * 1000, - year: 365 * 24 * 60 * 60 * 1000 + year: 365 * 24 * 60 * 60 * 1000, } as const; const [startOfRange, setStartOfRange] = useState(new Date()); @@ -68,7 +69,6 @@ export default function InsightsDisplay() { setStartOfRange(start); setEndOfRange(end); }, [/* useNow, */ selectedButton, now]); - const getInsights = async () => { const myInsights = await database.getFromDb("mood_records"); @@ -92,21 +92,26 @@ export default function InsightsDisplay() { } }; - useEffect(() => { - getInsights(); + useEffect(() => { + getInsights(); }, []); return ( <> -
+
{dateOptions.map((dateOption, index) => { const isActive = selectedButton === dateOption; return (