anki/ts/graphs/WithGraphData.svelte

45 lines
1.0 KiB
Svelte
Raw Normal View History

2021-03-21 22:06:25 +01:00
<script lang="typescript">
2021-03-22 15:41:43 +01:00
import type { Writable } from "svelte/store";
import useAsync from "sveltelib/async";
import useAsyncReactive from "sveltelib/asyncReactive";
2021-03-21 22:06:25 +01:00
2021-03-22 15:41:43 +01:00
import { getGraphData, daysToRevlogRange } from "./graph-helpers";
2021-03-21 22:06:25 +01:00
import { getPreferences } from "./preferences";
export let search: Writable<string>;
export let days: Writable<number>;
2021-03-21 22:06:25 +01:00
const {
loading: graphLoading,
error: graphError,
value: graphValue,
} = useAsyncReactive(() => getGraphData($search, $days), [search, days]);
2021-03-22 15:25:49 +01:00
const {
loading: prefsLoading,
error: prefsError,
value: prefsValue,
} = useAsync(() => getPreferences());
2021-03-21 22:06:25 +01:00
$: revlogRange = daysToRevlogRange($days);
$: {
if ($graphError) {
alert($graphError);
}
}
$: {
if ($prefsError) {
alert($prefsError);
}
}
2021-03-21 22:06:25 +01:00
</script>
<slot
2021-03-21 22:35:53 +01:00
{revlogRange}
loading={$graphLoading || $prefsLoading}
sourceData={$graphValue}
preferences={$prefsValue} />