From b0c2e8c99cdd7bc0256a4a56e7642619024a8827 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 22 Jan 2021 14:56:41 +0100 Subject: [PATCH] Remve SeparateInactiveCheckbox and correctly use preferences values * Expose issue with non-existing calendar value in GraphPreferences --- ts/graphs/CalendarGraph.svelte | 4 +++- ts/graphs/CardCounts.svelte | 7 +++++-- ts/graphs/SeparateInactiveCheckbox.svelte | 14 -------------- ts/graphs/calendar.ts | 18 ++++++++++++------ ts/graphs/graph-helpers.ts | 11 ++++++++--- ts/graphs/preferences.ts | 7 ++++--- 6 files changed, 32 insertions(+), 29 deletions(-) delete mode 100644 ts/graphs/SeparateInactiveCheckbox.svelte diff --git a/ts/graphs/CalendarGraph.svelte b/ts/graphs/CalendarGraph.svelte index c11606c09..307bf1f5b 100644 --- a/ts/graphs/CalendarGraph.svelte +++ b/ts/graphs/CalendarGraph.svelte @@ -8,10 +8,12 @@ import type { I18n } from "anki/i18n"; export let sourceData: pb.BackendProto.GraphsOut | null = null; + export let preferences: pb.BackendProto.GraphsPreferencesOut | null = null; export let revlogRange: RevlogRange; export let i18n: I18n; export let nightMode: boolean; + let { calendarFirstDayOfWeek } = preferences; let graphData: GraphData | null = null; let bounds = defaultGraphBounds(); @@ -25,7 +27,7 @@ let targetYear = maxYear; $: if (sourceData) { - graphData = gatherData(sourceData); + graphData = gatherData(sourceData, $calendarFirstDayOfWeek); } $: { diff --git a/ts/graphs/CardCounts.svelte b/ts/graphs/CardCounts.svelte index cab4908ea..7835f7e10 100644 --- a/ts/graphs/CardCounts.svelte +++ b/ts/graphs/CardCounts.svelte @@ -5,7 +5,6 @@ import type { PreferenceStore } from "./preferences"; import type pb from "anki/backend_proto"; import type { I18n } from "anki/i18n"; - import SeparateInactiveCheckbox from "./SeparateInactiveCheckbox.svelte"; export let sourceData: pb.BackendProto.GraphsOut; export let i18n: I18n; @@ -26,6 +25,7 @@ tableData = renderCards(svg as any, bounds, graphData); } + const label = i18n.tr(i18n.TR.STATISTICS_COUNTS_SEPARATE_SUSPENDED_BURIED_CARDS); const total = i18n.tr(i18n.TR.STATISTICS_COUNTS_TOTAL_CARDS); @@ -58,7 +58,10 @@

{graphData.title}

- +
diff --git a/ts/graphs/SeparateInactiveCheckbox.svelte b/ts/graphs/SeparateInactiveCheckbox.svelte deleted file mode 100644 index 51ef6529f..000000000 --- a/ts/graphs/SeparateInactiveCheckbox.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - - diff --git a/ts/graphs/calendar.ts b/ts/graphs/calendar.ts index 49069b320..b01ede2d1 100644 --- a/ts/graphs/calendar.ts +++ b/ts/graphs/calendar.ts @@ -6,7 +6,7 @@ @typescript-eslint/no-explicit-any: "off", */ -import type pb from "anki/backend_proto"; +import pb from "anki/backend_proto"; import { interpolateBlues } from "d3-scale-chromatic"; import "d3-transition"; import { select, mouse } from "d3-selection"; @@ -41,7 +41,13 @@ interface DayDatum { date: Date; } -export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { +type WeekdayType = pb.BackendProto.GraphsPreferencesOut.Weekday; +const Weekday = pb.BackendProto.GraphsPreferencesOut.Weekday; /* enum */ + +export function gatherData( + data: pb.BackendProto.GraphsOut, + firstDayOfWeek: WeekdayType +): GraphData { const reviewCount = new Map(); for (const review of data.revlog as pb.BackendProto.RevlogEntry[]) { @@ -56,17 +62,17 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { } const timeFunction = - data.firstWeekday === 1 + firstDayOfWeek === Weekday.MONDAY ? timeMonday - : data.firstWeekday === 5 + : data.firstWeekday === Weekday.FRIDAY ? timeFriday - : data.firstWeekday === 6 + : data.firstWeekday === Weekday.SATURDAY ? timeSaturday : timeSunday; const weekdayLabels: number[] = []; for (let i = 0; i < 7; i++) { - weekdayLabels.push((data.firstWeekday + i) % 7); + weekdayLabels.push((firstDayOfWeek + i) % 7); } return { reviewCount, timeFunction, weekdayLabels }; diff --git a/ts/graphs/graph-helpers.ts b/ts/graphs/graph-helpers.ts index 456273c1b..fe54cfdc7 100644 --- a/ts/graphs/graph-helpers.ts +++ b/ts/graphs/graph-helpers.ts @@ -25,10 +25,15 @@ export async function getGraphPreferences(): Promise { +export async function setGraphPreferences( + prefs: pb.BackendProto.GraphsPreferencesOut +): Promise { return (async () => { - await postRequest("/_anki/setGraphPreferences", pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish()) - })() + await postRequest( + "/_anki/setGraphPreferences", + pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish() + ); + })(); } // amount of data to fetch from backend diff --git a/ts/graphs/preferences.ts b/ts/graphs/preferences.ts index 8906cced5..8b64a4b06 100644 --- a/ts/graphs/preferences.ts +++ b/ts/graphs/preferences.ts @@ -2,7 +2,6 @@ import type pb from "anki/backend_proto"; import { getGraphPreferences, setGraphPreferences } from "./graph-helpers"; import { writable, get } from "svelte/store"; - export interface CustomStore { subscribe: (getter: (value: T) => void) => () => void; set: (value: T) => void; @@ -29,7 +28,9 @@ function createPreference( }; } -function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferencesOut): PreferenceStore { +function preparePreferences( + graphsPreferences: pb.BackendProto.GraphsPreferencesOut +): PreferenceStore { const preferences: Partial = {}; function constructPreferences(): pb.BackendProto.GraphsPreferencesOut { @@ -53,5 +54,5 @@ function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferences export async function getPreferences() { const initialPreferences = await getGraphPreferences(); - return preparePreferences(initialPreferences) + return preparePreferences(initialPreferences); }