Pass in RangeBox as an argument, decoupling it from GraphsPage

This commit is contained in:
Henrik Giesel 2020-12-26 14:40:55 +01:00
parent fb33be70b5
commit c72e9e5329
3 changed files with 17 additions and 13 deletions

View file

@ -3,19 +3,18 @@
</script> </script>
<script lang="typescript"> <script lang="typescript">
import RangeBox from './RangeBox.svelte' import type { SvelteComnponent } from 'svelte/internal';
import type { I18n } from "anki/i18n"; import type { I18n } from "anki/i18n";
import type pb from "anki/backend_proto"; import type pb from "anki/backend_proto";
import { getGraphData, RevlogRange } from "./graph-helpers"; import { getGraphData, RevlogRange } from "./graph-helpers";
export let i18n: I18n; export let i18n: I18n;
export let nightMode: boolean; export let nightMode: boolean;
export let graphs: any[]; export let graphs: SvelteComponent[];
export let search: string; export let search: string;
export let days: number; export let days: number;
export let withRangeBox: boolean; export let controller: SvelteComponent;
let active = false; let active = false;
let sourceData: pb.BackendProto.GraphsOut | null = null; let sourceData: pb.BackendProto.GraphsOut | null = null;
@ -42,14 +41,14 @@
refreshWith(search, days) refreshWith(search, days)
</script> </script>
{#if withRangeBox} {#if controller}
<RangeBox {i18n} {search} {days} {active} on:update={refresh} /> <svelte:component this={controller} {i18n} {search} {days} {active} on:update={refresh} />
{/if} {/if}
{#if sourceData} {#if sourceData}
<div tabindex="-1" class="no-focus-outline"> <div tabindex="-1" class="no-focus-outline">
{#each graphs as Graph} {#each graphs as graph}
<Graph {sourceData} {revlogRange} {i18n} {nightMode} /> <svelte:component this={graph} {sourceData} {revlogRange} {i18n} {nightMode} />
{/each} {/each}
</div> </div>
{/if} {/if}

View file

@ -1,10 +1,13 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { SvelteComponent } from 'svelte/internal';
import { setupI18n } from "anki/i18n"; import { setupI18n } from "anki/i18n";
import GraphsPage from "./GraphsPage.svelte"; import GraphsPage from "./GraphsPage.svelte";
import { checkNightMode } from "anki/nightmode"; import { checkNightMode } from "anki/nightmode";
import { RevlogRange } from "./graph-helpers";
export { default as RangeBox } from './RangeBox.svelte';
export { default as IntervalsGraph } from "./IntervalsGraph.svelte"; export { default as IntervalsGraph } from "./IntervalsGraph.svelte";
export { default as EaseGraph } from "./EaseGraph.svelte"; export { default as EaseGraph } from "./EaseGraph.svelte";
@ -20,10 +23,10 @@ export { RevlogRange } from "./graph-helpers";
export function graphs( export function graphs(
target: HTMLDivElement, target: HTMLDivElement,
graphs: any[], { graphs: SvelteComponent[], {
search = "deck:current", search = "deck:current",
days = 365, days = 365,
withRangeBox = true, controller = null,
} = {}, } = {},
): void { ): void {
const nightMode = checkNightMode(); const nightMode = checkNightMode();
@ -37,7 +40,7 @@ export function graphs(
nightMode, nightMode,
search, search,
days, days,
withRangeBox, controller,
}, },
}); });
}); });

View file

@ -23,7 +23,9 @@
anki.HourGraph, anki.HourGraph,
anki.ButtonsGraph, anki.ButtonsGraph,
anki.AddedGraph, anki.AddedGraph,
], ], {
controller: anki.RangeBox,
}
); );
</script> </script>
</html> </html>