v1.0.0
This commit is contained in:
47
frontend/src/lib/utils/localStorageHelper.ts
Normal file
47
frontend/src/lib/utils/localStorageHelper.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { GetConfig, SaveConfig } from "$lib/wailsjs/go/main/App";
|
||||
import type { utils } from "$lib/wailsjs/go/models"
|
||||
|
||||
async function loadConfig() {
|
||||
try {
|
||||
const config = await GetConfig();
|
||||
return config;
|
||||
} catch (error) {
|
||||
console.error("Failed to load config:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveConfig(config: utils.Config) {
|
||||
try {
|
||||
await SaveConfig(config);
|
||||
} catch (error) {
|
||||
console.error("Failed to save config:", error);
|
||||
}
|
||||
}
|
||||
|
||||
function saveToLocalStorage(key: string, value: string): boolean {
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Failed to save to localStorage:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getFromLocalStorage(key: string): string | null {
|
||||
try {
|
||||
return localStorage.getItem(key);
|
||||
} catch (error) {
|
||||
console.error("Failed to get from localStorage:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
loadConfig,
|
||||
saveConfig,
|
||||
saveToLocalStorage,
|
||||
getFromLocalStorage
|
||||
};
|
||||
|
||||
38
frontend/src/lib/utils/unsaved-changes-toast.ts
Normal file
38
frontend/src/lib/utils/unsaved-changes-toast.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { toast } from "svelte-sonner";
|
||||
|
||||
import UnsavedBar from "$lib/components/UnsavedBar.svelte";
|
||||
|
||||
const UNSAVED_CHANGES_TOAST_ID = "unsaved-changes";
|
||||
const ONE_YEAR_MS = 1000 * 60 * 60 * 24 * 365;
|
||||
|
||||
export type UnsavedChangesToastHandlers = {
|
||||
onSave: () => void;
|
||||
onReset: () => void;
|
||||
};
|
||||
|
||||
export function showUnsavedChangesToast(handlers: UnsavedChangesToastHandlers) {
|
||||
let toastId: string | number = UNSAVED_CHANGES_TOAST_ID;
|
||||
|
||||
toastId = toast.custom(UnsavedBar, {
|
||||
id: toastId,
|
||||
duration: ONE_YEAR_MS,
|
||||
dismissable: false,
|
||||
unstyled: true,
|
||||
componentProps: {
|
||||
onSave: () => {
|
||||
handlers.onSave();
|
||||
toast.dismiss(toastId);
|
||||
},
|
||||
onReset: () => {
|
||||
handlers.onReset();
|
||||
toast.dismiss(toastId);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return toastId;
|
||||
}
|
||||
|
||||
export function dismissUnsavedChangesToast() {
|
||||
toast.dismiss(UNSAVED_CHANGES_TOAST_ID);
|
||||
}
|
||||
Reference in New Issue
Block a user