refactor: app settings

This commit is contained in:
reya
2024-10-30 10:57:43 +07:00
parent 11dcef4e87
commit 618a45d349
33 changed files with 617 additions and 629 deletions
+19 -1
View File
@@ -1,20 +1,38 @@
import { commands } from "@/commands.gen";
import { Spinner } from "@/components";
import type { Metadata, NostrEvent } from "@/types";
import type { QueryClient } from "@tanstack/react-query";
import { type QueryClient, queryOptions } from "@tanstack/react-query";
import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";
import { getCurrentWindow } from "@tauri-apps/api/window";
import type { OsType } from "@tauri-apps/plugin-os";
import type { Store } from "@tauri-apps/plugin-store";
import { useEffect } from "react";
interface RouterContext {
store: Store;
queryClient: QueryClient;
platform: OsType;
accounts?: string[];
}
export const settingsQueryOptions = queryOptions({
queryKey: ["settings"],
queryFn: async () => {
const res = await commands.getAppSettings();
if (res.status === "ok") {
return res.data;
} else {
throw new Error(res.error);
}
},
});
export const Route = createRootRouteWithContext<RouterContext>()({
component: Screen,
pendingComponent: Pending,
loader: ({ context }) =>
context.queryClient.ensureQueryData(settingsQueryOptions),
});
function Screen() {