diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index e60c8b67f..92f536c57 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -9,6 +9,8 @@ import { getPreferences } from "./preferences"; import { bridgeCommand } from "anki/bridgecommand"; + import WithGraphData from "./WithGraphData.svelte"; + export let i18n: I18n; export let nightMode: boolean; export let graphs: SvelteComponent[]; @@ -17,39 +19,8 @@ export let days: number; export let controller: SvelteComponent | null; - let active = false; - let sourceData: pb.BackendProto.GraphsOut | null = null; - let preferences: PreferenceStore | null = null; - let revlogRange: RevlogRange; - - const preferencesPromise = getPreferences(); - - const refreshWith = async (searchNew: string, days: number) => { - search = searchNew; - - active = true; - try { - [sourceData, preferences] = await Promise.all([ - getGraphData(search, days), - preferencesPromise, - ]); - revlogRange = daysToRevlogRange(days); - } catch (e) { - sourceData = null; - alert(e); - } - active = false; - }; - - const refresh = (event: CustomEvent) => { - refreshWith(event.detail.search, event.detail.days); - }; - - refreshWith(search, days); - - const browserSearch = (event: CustomEvent) => { - const query = `${search} ${event.detail.query}`; - bridgeCommand(`browserSearch:${query}`); + const browserSearch = (search: string, query: string) => { + bridgeCommand(`browserSearch:${search} ${query}`); }; @@ -59,30 +30,32 @@ font-size: 12px; } } -
- {#if controller} - - {/if} + + {#if controller} + + {/if} - {#if sourceData} - {#each graphs as graph} - - {/each} - {/if} + {#if !pending} + {#each graphs as graph} + browserSearch(search, event.detail.query)} /> + {/each} + {/if} +
diff --git a/ts/graphs/RangeBox.svelte b/ts/graphs/RangeBox.svelte index 553cca1c0..75d015a4b 100644 --- a/ts/graphs/RangeBox.svelte +++ b/ts/graphs/RangeBox.svelte @@ -1,5 +1,6 @@ - + {search} + {days} + {revlogRange} + pending={$sourceData.pending || $preferences.pending} + loading={$sourceData.loading || $preferences.loading} + sourceData={$sourceData.value} + preferences={$preferences.value} />