mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
Add WithGraphData
This commit is contained in:
parent
e11b31c29d
commit
36e14cd525
2 changed files with 32 additions and 0 deletions
31
ts/graphs/WithGraphData.svelte
Normal file
31
ts/graphs/WithGraphData.svelte
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<script lang="typescript">
|
||||||
|
import { writable } from "svelte/store";
|
||||||
|
import useAsync from "./async";
|
||||||
|
import useAsyncReactive from "./asyncReactive";
|
||||||
|
|
||||||
|
import { getGraphData, RevlogRange, daysToRevlogRange } from "./graph-helpers";
|
||||||
|
import { getPreferences } from "./preferences";
|
||||||
|
|
||||||
|
export let initialSearch: string;
|
||||||
|
export let initialDays: number;
|
||||||
|
|
||||||
|
const preferencesPromise = getPreferences();
|
||||||
|
|
||||||
|
const search = writable(initialSearch);
|
||||||
|
const days = writable(initialDays);
|
||||||
|
|
||||||
|
const sourceData = useAsyncReactive(() => getGraphData($search, $days), [search, days])
|
||||||
|
const preferences = useAsync(() => getPreferences())
|
||||||
|
|
||||||
|
$: revlogRange = daysToRevlogRange($days);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot
|
||||||
|
{search}
|
||||||
|
{days}
|
||||||
|
{revlogRange}
|
||||||
|
pending={$sourceData.pending || $preferences.pending}
|
||||||
|
sourceData={$sourceData.value}
|
||||||
|
preferences={$preferences.value}
|
||||||
|
>
|
||||||
|
</slot>
|
|
@ -27,6 +27,7 @@ function useAsyncReactive<T, E>(
|
||||||
promise,
|
promise,
|
||||||
($promise, set: (error: E | null) => void) => {
|
($promise, set: (error: E | null) => void) => {
|
||||||
$promise.catch((error: E) => set(error));
|
$promise.catch((error: E) => set(error));
|
||||||
|
return () => set(null);
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue