import { ChevronDown, ChevronUp } from "lucide-react"; import { useEffect, useState } from "react"; interface Props { stepSetter: (value: string) => void; currentStep: string; rangeSetter: (value: number) => void; currentRange: number; disableCache?: boolean; } export default function ActivityOptsSelector({ stepSetter, currentStep, rangeSetter, currentRange, disableCache = false, }: Props) { const stepPeriods = ['day', 'week', 'month', 'year']; const rangePeriods = [105, 182, 364]; const [collapsed, setCollapsed] = useState(true); const setMenuOpen = (val: boolean) => { setCollapsed(val) if (!disableCache) { localStorage.setItem('activity_configuring_' + window.location.pathname.split('/')[1], String(!val)); } } const setStep = (val: string) => { stepSetter(val); if (!disableCache) { localStorage.setItem('activity_step_' + window.location.pathname.split('/')[1], val); } }; const setRange = (val: number) => { rangeSetter(val); if (!disableCache) { localStorage.setItem('activity_range_' + window.location.pathname.split('/')[1], String(val)); } }; useEffect(() => { if (!disableCache) { const cachedRange = parseInt(localStorage.getItem('activity_range_' + window.location.pathname.split('/')[1]) ?? '35'); if (cachedRange) rangeSetter(cachedRange); const cachedStep = localStorage.getItem('activity_step_' + window.location.pathname.split('/')[1]); if (cachedStep) stepSetter(cachedStep); const cachedConfiguring = localStorage.getItem('activity_configuring_' + window.location.pathname.split('/')[1]); if (cachedStep) setMenuOpen(cachedConfiguring !== "true"); } }, []); return (
Step: {stepPeriods.map((p) => ( ))}
Range: {rangePeriods.map((r) => ( ))}
); }