mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Inline GraphData/GraphPreferences getters/setters into WithGraphData
This commit is contained in:
parent
13decbe608
commit
e3a3ca3f25
2 changed files with 28 additions and 33 deletions
|
@ -4,23 +4,44 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { Writable } from "svelte/store";
|
import type { Writable } from "svelte/store";
|
||||||
|
import type { PreferencePayload } from "sveltelib/preferences";
|
||||||
|
|
||||||
import pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
|
import { postRequest } from "anki/postrequest";
|
||||||
|
|
||||||
import useAsync from "sveltelib/async";
|
import useAsync from "sveltelib/async";
|
||||||
import useAsyncReactive from "sveltelib/asyncReactive";
|
import useAsyncReactive from "sveltelib/asyncReactive";
|
||||||
import { getPreferences } from "sveltelib/preferences";
|
import { getPreferences } from "sveltelib/preferences";
|
||||||
|
|
||||||
import {
|
import { daysToRevlogRange } from "./graph-helpers";
|
||||||
getGraphData,
|
|
||||||
getGraphPreferences,
|
|
||||||
setGraphPreferences,
|
|
||||||
daysToRevlogRange,
|
|
||||||
} from "./graph-helpers";
|
|
||||||
|
|
||||||
export let search: Writable<string>;
|
export let search: Writable<string>;
|
||||||
export let days: Writable<number>;
|
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 {
|
const {
|
||||||
loading: graphLoading,
|
loading: graphLoading,
|
||||||
error: graphError,
|
error: graphError,
|
||||||
|
|
|
@ -6,34 +6,8 @@
|
||||||
@typescript-eslint/no-explicit-any: "off",
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
@typescript-eslint/ban-ts-ignore: "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 { 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
|
// amount of data to fetch from backend
|
||||||
export enum RevlogRange {
|
export enum RevlogRange {
|
||||||
|
|
Loading…
Reference in a new issue