import { useEffect } from "react" interface Props { setter: Function current: string disableCache?: boolean } export default function PeriodSelector({ setter, current, disableCache = false }: Props) { const periods = ['day', 'week', 'month', 'year', 'all_time'] const periodDisplay = (str: string) => { return str.split('_').map(w => w.split('').map((char, index) => index === 0 ? char.toUpperCase() : char).join('')).join(' ') } const setPeriod = (val: string) => { setter(val) if (!disableCache) { localStorage.setItem('period_selection_'+window.location.pathname.split('/')[1], val) } } useEffect(() => { if (!disableCache) { const cached = localStorage.getItem('period_selection_' + window.location.pathname.split('/')[1]); if (cached) { setter(cached); } } }, []); return (
Showing stats for:
{periods.map((p, i) => (