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 { 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 @@
<WithGraphData
{search}
{days}
let:search={searchStore}
let:days={daysStore}
let:pending
let:loading
let:sourceData
let:preferences
let:revlogRange>
{#if controller}
<svelte:component this={controller} {i18n} {search} {days} {loading} />
<svelte:component this={controller} {i18n} search={searchStore} days={daysStore} {loading} />
{/if}
{#if !pending}
{#if !pending && sourceData && preferences}
{#each graphs as graph}
<svelte:component
this={graph}

View File

@ -19,24 +19,25 @@
export let days: Writable<number>;
export let search: Writable<string>;
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;
}

View File

@ -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);
</script>
@ -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} />

View File

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