Get it to work, if you change the input

- there's still an issue on initial load
This commit is contained in:
Henrik Giesel 2021-03-21 23:45:59 +01:00
parent 3f37153558
commit 672eb20321
4 changed files with 28 additions and 20 deletions

View File

@ -3,10 +3,6 @@
import type { SvelteComponent } from "svelte/internal"; import type { SvelteComponent } from "svelte/internal";
import type { I18n } from "anki/i18n"; 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 { bridgeCommand } from "anki/bridgecommand";
import WithGraphData from "./WithGraphData.svelte"; import WithGraphData from "./WithGraphData.svelte";
@ -36,16 +32,18 @@
<WithGraphData <WithGraphData
{search} {search}
{days} {days}
let:search={searchStore}
let:days={daysStore}
let:pending let:pending
let:loading let:loading
let:sourceData let:sourceData
let:preferences let:preferences
let:revlogRange> let:revlogRange>
{#if controller} {#if controller}
<svelte:component this={controller} {i18n} {search} {days} {loading} /> <svelte:component this={controller} {i18n} search={searchStore} days={daysStore} {loading} />
{/if} {/if}
{#if !pending} {#if !pending && sourceData && preferences}
{#each graphs as graph} {#each graphs as graph}
<svelte:component <svelte:component
this={graph} this={graph}

View File

@ -19,24 +19,25 @@
export let days: Writable<number>; export let days: Writable<number>;
export let search: Writable<string>; export let search: Writable<string>;
let revlogRange = daysToRevlogRange(days); let revlogRange = daysToRevlogRange($days);
let searchRange: SearchRange = let searchRange = $search === "deck:current"
search === "deck:current"
? SearchRange.Deck ? SearchRange.Deck
: search === "" : $search === ""
? SearchRange.Collection ? SearchRange.Collection
: SearchRange.Custom; : SearchRange.Custom;
let displayedSearch = search; let displayedSearch = $search;
$: { $: {
switch (searchRange as SearchRange) { switch (searchRange as SearchRange) {
case SearchRange.Deck: case SearchRange.Deck:
displayedSearch = "deck:current"; displayedSearch = "deck:current";
console.log('search', search)
search.set(displayedSearch); search.set(displayedSearch);
break; break;
case SearchRange.Collection: case SearchRange.Collection:
search = displayedSearch = ""; displayedSearch = "";
console.log('search', search)
search.set(displayedSearch); search.set(displayedSearch);
break; break;
} }

View File

@ -14,11 +14,20 @@
const search = writable(initialSearch); const search = writable(initialSearch);
const days = writable(initialDays); const days = writable(initialDays);
const sourceData = useAsyncReactive(() => getGraphData($search, $days), [ const {
pending: graphPending,
loading: graphLoading,
value: graphValue,
} = useAsyncReactive(() => getGraphData($search, $days), [
search, search,
days, days,
]); ]);
const preferences = useAsync(() => getPreferences());
const {
pending: prefsPending,
loading: prefsLoading,
value: prefsValue,
} = useAsync(() => getPreferences());
$: revlogRange = daysToRevlogRange($days); $: revlogRange = daysToRevlogRange($days);
</script> </script>
@ -27,7 +36,7 @@
{search} {search}
{days} {days}
{revlogRange} {revlogRange}
pending={$sourceData.pending || $preferences.pending} pending={$graphPending || $prefsPending}
loading={$sourceData.loading || $preferences.loading} loading={$graphLoading || $prefsLoading}
sourceData={$sourceData.value} sourceData={$graphValue}
preferences={$preferences.value} /> preferences={$prefsValue} />

View File

@ -38,7 +38,7 @@ function useAsyncReactive<T, E>(
const loading = derived( const loading = derived(
[value, error], [value, error],
(_, set) => { (_, set: (value: boolean) => void) => {
set(false); set(false);
return () => set(true); return () => set(true);
}, },
@ -47,7 +47,7 @@ function useAsyncReactive<T, E>(
const success = derived( const success = derived(
[value], [value],
(_, set) => { (_, set: (value: boolean) => void) => {
set(true); set(true);
return () => set(false); return () => set(false);
}, },