From 672eb203211eed1b3ffd1c428ef14f5293d7b5da Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 21 Mar 2021 23:45:59 +0100 Subject: [PATCH] Get it to work, if you change the input - there's still an issue on initial load --- ts/graphs/GraphsPage.svelte | 10 ++++------ ts/graphs/RangeBox.svelte | 13 +++++++------ ts/graphs/WithGraphData.svelte | 21 +++++++++++++++------ ts/graphs/asyncReactive.ts | 4 ++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index 92f536c57..c0f76cf02 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -3,10 +3,6 @@ import type { SvelteComponent } from "svelte/internal"; import type { I18n } from "anki/i18n"; - import type { PreferenceStore } from "./preferences"; - import type pb from "anki/backend_proto"; - import { getGraphData, RevlogRange, daysToRevlogRange } from "./graph-helpers"; - import { getPreferences } from "./preferences"; import { bridgeCommand } from "anki/bridgecommand"; import WithGraphData from "./WithGraphData.svelte"; @@ -36,16 +32,18 @@ {#if controller} - + {/if} - {#if !pending} + {#if !pending && sourceData && preferences} {#each graphs as graph} ; export let search: Writable; - let revlogRange = daysToRevlogRange(days); - let searchRange: SearchRange = - search === "deck:current" + let revlogRange = daysToRevlogRange($days); + let searchRange = $search === "deck:current" ? SearchRange.Deck - : search === "" + : $search === "" ? SearchRange.Collection : SearchRange.Custom; - let displayedSearch = search; + let displayedSearch = $search; $: { switch (searchRange as SearchRange) { case SearchRange.Deck: displayedSearch = "deck:current"; + console.log('search', search) search.set(displayedSearch); break; case SearchRange.Collection: - search = displayedSearch = ""; + displayedSearch = ""; + console.log('search', search) search.set(displayedSearch); break; } diff --git a/ts/graphs/WithGraphData.svelte b/ts/graphs/WithGraphData.svelte index 560c1b585..e5e94d542 100644 --- a/ts/graphs/WithGraphData.svelte +++ b/ts/graphs/WithGraphData.svelte @@ -14,11 +14,20 @@ const search = writable(initialSearch); const days = writable(initialDays); - const sourceData = useAsyncReactive(() => getGraphData($search, $days), [ + const { + pending: graphPending, + loading: graphLoading, + value: graphValue, + } = useAsyncReactive(() => getGraphData($search, $days), [ search, days, ]); - const preferences = useAsync(() => getPreferences()); + + const { + pending: prefsPending, + loading: prefsLoading, + value: prefsValue, + } = useAsync(() => getPreferences()); $: revlogRange = daysToRevlogRange($days); @@ -27,7 +36,7 @@ {search} {days} {revlogRange} - pending={$sourceData.pending || $preferences.pending} - loading={$sourceData.loading || $preferences.loading} - sourceData={$sourceData.value} - preferences={$preferences.value} /> + pending={$graphPending || $prefsPending} + loading={$graphLoading || $prefsLoading} + sourceData={$graphValue} + preferences={$prefsValue} /> diff --git a/ts/graphs/asyncReactive.ts b/ts/graphs/asyncReactive.ts index d53c14895..bb91f1fc7 100644 --- a/ts/graphs/asyncReactive.ts +++ b/ts/graphs/asyncReactive.ts @@ -38,7 +38,7 @@ function useAsyncReactive( const loading = derived( [value, error], - (_, set) => { + (_, set: (value: boolean) => void) => { set(false); return () => set(true); }, @@ -47,7 +47,7 @@ function useAsyncReactive( const success = derived( [value], - (_, set) => { + (_, set: (value: boolean) => void) => { set(true); return () => set(false); },