c039845c16
This allows for tree shaking, and reduces the congrats page from 150k with the old enum solution to about 80k.
48 lines
1.4 KiB
Svelte
48 lines
1.4 KiB
Svelte
<script lang="typescript">
|
|
import { RevlogRange, GraphRange } from "./graph-helpers";
|
|
import { timeSpan, MONTH, YEAR } from "anki/time";
|
|
|
|
import * as tr from "anki/i18n";
|
|
export let revlogRange: RevlogRange;
|
|
export let graphRange: GraphRange;
|
|
export let followRevlog: boolean = false;
|
|
|
|
function onFollowRevlog(revlogRange: RevlogRange) {
|
|
if (revlogRange === RevlogRange.All) {
|
|
graphRange = GraphRange.AllTime;
|
|
} else if (graphRange === GraphRange.AllTime) {
|
|
graphRange = GraphRange.Year;
|
|
}
|
|
}
|
|
|
|
$: if (followRevlog) {
|
|
// split into separate function so svelte does not
|
|
// run this when graphRange changes
|
|
onFollowRevlog(revlogRange);
|
|
}
|
|
|
|
const month = timeSpan(1 * MONTH);
|
|
const month3 = timeSpan(3 * MONTH);
|
|
const year = timeSpan(1 * YEAR);
|
|
const all = tr.statisticsRangeAllTime();
|
|
</script>
|
|
|
|
<label>
|
|
<input type="radio" bind:group={graphRange} value={GraphRange.Month} />
|
|
{month}
|
|
</label>
|
|
<label>
|
|
<input type="radio" bind:group={graphRange} value={GraphRange.ThreeMonths} />
|
|
{month3}
|
|
</label>
|
|
<label>
|
|
<input type="radio" bind:group={graphRange} value={GraphRange.Year} />
|
|
{year}
|
|
</label>
|
|
{#if revlogRange === RevlogRange.All}
|
|
<label>
|
|
<input type="radio" bind:group={graphRange} value={GraphRange.AllTime} />
|
|
{all}
|
|
</label>
|
|
{/if}
|