import { useEffect } 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, 365]; const stepDisplay = (str: string): string => { return str.split('_').map(w => w.split('').map((char, index) => index === 0 ? char.toUpperCase() : char).join('') ).join(' '); }; const rangeDisplay = (r: number): string => { return `${r}` } 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); } } }, []); return (

Step:

{stepPeriods.map((p, i) => (
{i !== stepPeriods.length - 1 ? '|' : ''}
))}

Range:

{rangePeriods.map((r, i) => (
{i !== rangePeriods.length - 1 ? '|' : ''}
))}
); }