2020-06-22 11:11:50 +02:00
|
|
|
<script context="module">
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="typescript">
|
2020-12-27 02:04:45 +01:00
|
|
|
import type { SvelteComponent } from "svelte/internal";
|
2020-11-05 02:01:30 +01:00
|
|
|
import type { I18n } from "anki/i18n";
|
2021-01-21 13:45:49 +01:00
|
|
|
import type { PreferenceStore } from "./preferences";
|
2020-11-05 02:01:30 +01:00
|
|
|
import type pb from "anki/backend_proto";
|
2021-01-23 13:54:21 +01:00
|
|
|
import { getGraphData, RevlogRange, daysToRevlogRange } from "./graph-helpers";
|
2021-01-21 13:45:49 +01:00
|
|
|
import { getPreferences } from "./preferences";
|
2021-01-26 01:25:22 +01:00
|
|
|
import { bridgeCommand } from "anki/bridgecommand";
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-06-27 11:24:49 +02:00
|
|
|
export let i18n: I18n;
|
2020-06-30 08:23:46 +02:00
|
|
|
export let nightMode: boolean;
|
2020-12-26 14:40:55 +01:00
|
|
|
export let graphs: SvelteComponent[];
|
2020-06-27 11:24:49 +02:00
|
|
|
|
2020-12-22 22:25:47 +01:00
|
|
|
export let search: string;
|
2020-12-25 22:29:42 +01:00
|
|
|
export let days: number;
|
2020-12-29 06:19:21 +01:00
|
|
|
export let controller: SvelteComponent | null;
|
2020-12-22 22:25:47 +01:00
|
|
|
|
2020-12-26 00:16:54 +01:00
|
|
|
let active = false;
|
2020-12-25 22:59:11 +01:00
|
|
|
let sourceData: pb.BackendProto.GraphsOut | null = null;
|
2021-01-21 13:45:49 +01:00
|
|
|
let preferences: PreferenceStore | null = null;
|
2020-12-25 22:29:42 +01:00
|
|
|
let revlogRange: RevlogRange;
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2021-01-21 13:45:49 +01:00
|
|
|
const preferencesPromise = getPreferences();
|
|
|
|
|
2021-01-05 22:28:51 +01:00
|
|
|
const refreshWith = async (searchNew: string, days: number) => {
|
2021-01-06 13:40:05 +01:00
|
|
|
search = searchNew;
|
2021-01-05 22:28:51 +01:00
|
|
|
|
2020-12-26 00:16:54 +01:00
|
|
|
active = true;
|
2020-12-25 22:59:11 +01:00
|
|
|
try {
|
2021-01-21 13:45:49 +01:00
|
|
|
[sourceData, preferences] = await Promise.all([
|
|
|
|
getGraphData(search, days),
|
|
|
|
preferencesPromise,
|
|
|
|
]);
|
2021-01-23 13:54:21 +01:00
|
|
|
revlogRange = daysToRevlogRange(days);
|
2020-12-25 22:59:11 +01:00
|
|
|
} catch (e) {
|
|
|
|
sourceData = null;
|
2021-01-29 05:37:29 +01:00
|
|
|
alert(e);
|
2020-12-25 22:59:11 +01:00
|
|
|
}
|
2020-12-26 00:16:54 +01:00
|
|
|
active = false;
|
2020-12-26 18:24:24 +01:00
|
|
|
};
|
2020-06-22 12:28:36 +02:00
|
|
|
|
2020-12-25 22:59:11 +01:00
|
|
|
const refresh = (event: CustomEvent) => {
|
2020-12-26 18:24:24 +01:00
|
|
|
refreshWith(event.detail.search, event.detail.days);
|
|
|
|
};
|
2020-06-22 13:39:16 +02:00
|
|
|
|
2020-12-26 18:24:24 +01:00
|
|
|
refreshWith(search, days);
|
2021-01-05 22:28:51 +01:00
|
|
|
|
|
|
|
const browserSearch = (event: CustomEvent) => {
|
2021-01-06 13:40:05 +01:00
|
|
|
const query = `${search} ${event.detail.query}`;
|
|
|
|
bridgeCommand(`browserSearch:${query}`);
|
|
|
|
};
|
2020-06-22 11:11:50 +02:00
|
|
|
</script>
|
|
|
|
|
2020-12-26 14:40:55 +01:00
|
|
|
{#if controller}
|
2020-12-26 18:24:24 +01:00
|
|
|
<svelte:component
|
|
|
|
this={controller}
|
|
|
|
{i18n}
|
|
|
|
{search}
|
|
|
|
{days}
|
|
|
|
{active}
|
|
|
|
on:update={refresh} />
|
2020-12-22 22:36:39 +01:00
|
|
|
{/if}
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-12-25 22:59:11 +01:00
|
|
|
{#if sourceData}
|
|
|
|
<div tabindex="-1" class="no-focus-outline">
|
2020-12-26 14:40:55 +01:00
|
|
|
{#each graphs as graph}
|
2020-12-26 18:24:24 +01:00
|
|
|
<svelte:component
|
|
|
|
this={graph}
|
|
|
|
{sourceData}
|
2021-01-21 14:04:33 +01:00
|
|
|
{preferences}
|
2020-12-26 18:24:24 +01:00
|
|
|
{revlogRange}
|
|
|
|
{i18n}
|
2021-01-05 22:28:51 +01:00
|
|
|
{nightMode}
|
|
|
|
on:search={browserSearch} />
|
2020-12-25 22:59:11 +01:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|