Inline GraphData/GraphPreferences getters/setters into WithGraphData

This commit is contained in:
Henrik Giesel 2021-04-14 23:56:58 +02:00
parent 13decbe608
commit e3a3ca3f25
2 changed files with 28 additions and 33 deletions

View file

@ -4,23 +4,44 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import type { Writable } from "svelte/store";
import type { PreferencePayload } from "sveltelib/preferences";
import pb from "anki/backend_proto";
import { postRequest } from "anki/postrequest";
import useAsync from "sveltelib/async";
import useAsyncReactive from "sveltelib/asyncReactive";
import { getPreferences } from "sveltelib/preferences";
import {
getGraphData,
getGraphPreferences,
setGraphPreferences,
daysToRevlogRange,
} from "./graph-helpers";
import { daysToRevlogRange } from "./graph-helpers";
export let search: Writable<string>;
export let days: Writable<number>;
async function getGraphData(
search: string,
days: number
): Promise<pb.BackendProto.GraphsOut> {
return pb.BackendProto.GraphsOut.decode(
await postRequest("/_anki/graphData", JSON.stringify({ search, days }))
);
}
async function getGraphPreferences(): Promise<pb.BackendProto.GraphPreferences> {
return pb.BackendProto.GraphPreferences.decode(
await postRequest("/_anki/graphPreferences", JSON.stringify({}))
);
}
async function setGraphPreferences(
prefs: PreferencePayload<pb.BackendProto.GraphPreferences>
): Promise<void> {
await postRequest(
"/_anki/setGraphPreferences",
pb.BackendProto.GraphPreferences.encode(prefs).finish()
);
}
const {
loading: graphLoading,
error: graphError,

View file

@ -6,34 +6,8 @@
@typescript-eslint/no-explicit-any: "off",
@typescript-eslint/ban-ts-ignore: "off" */
import pb from "anki/backend_proto";
import type pb from "anki/backend_proto";
import type { Selection } from "d3";
import type { PreferencePayload } from "sveltelib/preferences";
import { postRequest } from "anki/postrequest";
export async function getGraphData(
search: string,
days: number
): Promise<pb.BackendProto.GraphsOut> {
return pb.BackendProto.GraphsOut.decode(
await postRequest("/_anki/graphData", JSON.stringify({ search, days }))
);
}
export async function getGraphPreferences(): Promise<pb.BackendProto.GraphPreferences> {
return pb.BackendProto.GraphPreferences.decode(
await postRequest("/_anki/graphPreferences", JSON.stringify({}))
);
}
export async function setGraphPreferences(
prefs: PreferencePayload<pb.BackendProto.GraphPreferences>
): Promise<void> {
await postRequest(
"/_anki/setGraphPreferences",
pb.BackendProto.GraphPreferences.encode(prefs).finish()
);
}
// amount of data to fetch from backend
export enum RevlogRange {