aboutsummaryrefslogtreecommitdiff
path: root/src/lib/CommandPalette/syncActions.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-26 12:40:27 +0000
committerFuwn <[email protected]>2026-04-26 12:40:27 +0000
commit5accc4e512e9bbff8d4303cb732edccaccd9b5a3 (patch)
tree3c51680e1cabb45941a7716cb769d04b8cb56c06 /src/lib/CommandPalette/syncActions.ts
parentfix(tooltip): park off-screen on create, enable glide after first placement (diff)
downloaddue.moe-5accc4e512e9bbff8d4303cb732edccaccd9b5a3.tar.xz
due.moe-5accc4e512e9bbff8d4303cb732edccaccd9b5a3.zip
feat(command-palette): add quick toggles, sync, and auth actions
Adds 13 reactive quick toggles (24h time, animations, blur adult, cover modes, hover cover, schedule list, reverse sort, data saver, notifications, language, title format cycle, outbound link target cycle), three sync actions (push/pull/disable), and login/logout entries gated on auth state. Names reflect current state so the palette doubles as a status surface.
Diffstat (limited to 'src/lib/CommandPalette/syncActions.ts')
-rw-r--r--src/lib/CommandPalette/syncActions.ts106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/lib/CommandPalette/syncActions.ts b/src/lib/CommandPalette/syncActions.ts
new file mode 100644
index 00000000..c787f348
--- /dev/null
+++ b/src/lib/CommandPalette/syncActions.ts
@@ -0,0 +1,106 @@
+import { addNotification } from "$lib/Notification/store";
+import { options } from "$lib/Notification/options";
+import root from "$lib/Utility/root";
+import settings from "$stores/settings";
+import settingsSyncPulled from "$stores/settingsSyncPulled";
+import settingsSyncTimes from "$stores/settingsSyncTimes";
+import { get } from "svelte/store";
+import type { CommandPaletteAction } from "./actions";
+
+export const syncActions = (
+ identityId: number,
+ syncEnabled: boolean,
+): CommandPaletteAction[] => {
+ if (identityId <= 0) return [];
+
+ const actions: CommandPaletteAction[] = [
+ {
+ name: "Push Settings Now",
+ url: "#",
+ preventDefault: true,
+ tags: ["settings", "sync", "push", "upload", "remote"],
+ onClick: () => {
+ settings.setKey("settingsSync", true);
+
+ fetch(root(`/api/configuration`), {
+ method: "PUT",
+ body: JSON.stringify(get(settings)),
+ })
+ .then((response) => {
+ if (!response.ok) return;
+
+ addNotification(
+ options({
+ heading: "Settings Sync",
+ description: "Pushed local configuration to remote",
+ }),
+ );
+
+ settingsSyncTimes.update((times) => ({
+ ...times,
+ lastPush: new Date(),
+ }));
+ })
+ .catch((error) =>
+ console.error("Settings sync push failed", error),
+ );
+ },
+ },
+ {
+ name: "Pull Settings Now",
+ url: "#",
+ preventDefault: true,
+ tags: ["settings", "sync", "pull", "download", "remote"],
+ onClick: () => {
+ settings.setKey("settingsSync", true);
+
+ fetch(root(`/api/configuration?id=${identityId}`))
+ .then((response) => {
+ if (!response.ok) return;
+
+ return response.json().then((data) => {
+ if (!data?.configuration) {
+ addNotification(
+ options({
+ heading: "Settings Sync",
+ description: "No remote configuration found",
+ }),
+ );
+
+ return;
+ }
+
+ settings.set(data.configuration);
+ settingsSyncPulled.set(true);
+ settingsSyncTimes.set({
+ lastPull: new Date(),
+ lastPush: new Date(`${data.updated_at}Z`),
+ });
+
+ addNotification(
+ options({ heading: "Pulled remote configuration" }),
+ );
+ });
+ })
+ .catch((error) =>
+ console.error("Settings sync pull failed", error),
+ );
+ },
+ },
+ ];
+
+ if (syncEnabled)
+ actions.push({
+ name: "Disable Settings Sync",
+ url: "#",
+ preventDefault: true,
+ tags: ["settings", "sync", "disable", "off", "stop"],
+ onClick: () => {
+ settings.setKey("settingsSync", false);
+
+ addNotification(options({ heading: "Settings sync disabled" }));
+ },
+ });
+
+ return actions;
+};