mirror of https://github.com/VERT-sh/VERT.git
feat: more dynamic settings system
This commit is contained in:
parent
64ab1288f4
commit
35e98a5971
|
@ -7,24 +7,32 @@
|
|||
import { RefreshCwIcon, SaveAllIcon } from "lucide-svelte";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let filenameFormat = "VERT_%name%";
|
||||
// let filenameFormat = "VERT_%name%";
|
||||
let settings = $state({
|
||||
filenameFormat: "VERT_%name%",
|
||||
});
|
||||
|
||||
function save() {
|
||||
log(["settings"], "Saving settings");
|
||||
log(["settings"], "saving settings");
|
||||
if (!browser) return;
|
||||
try {
|
||||
localStorage.setItem("filenameFormat", filenameFormat);
|
||||
log(["settings"], `Saving filename format: ${filenameFormat}`);
|
||||
addToast("success", "Settings saved!");
|
||||
localStorage.setItem("settings", JSON.stringify(settings));
|
||||
addToast("success", "settings saved!");
|
||||
} catch (error) {
|
||||
log(["settings", "error"], `Failed to save settings: ${error}`);
|
||||
log(["settings", "error"], `failed to save settings: ${error}`);
|
||||
addToast("error", "Failed to save settings!");
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const format = localStorage.getItem("filenameFormat");
|
||||
if (format) filenameFormat = format;
|
||||
const savedSettings = localStorage.getItem("settings");
|
||||
if (savedSettings) {
|
||||
const parsedSettings = JSON.parse(savedSettings);
|
||||
settings = {
|
||||
...settings,
|
||||
...parsedSettings,
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -59,7 +67,7 @@
|
|||
</div>
|
||||
<FancyTextInput
|
||||
placeholder="VERT_%name%"
|
||||
bind:value={filenameFormat}
|
||||
bind:value={settings.filenameFormat}
|
||||
extension=".ext"
|
||||
type="text"
|
||||
/>
|
||||
|
|
|
@ -186,8 +186,8 @@ class Files {
|
|||
const blob = await downloadZip(dlFiles, "converted.zip").blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const filenameFormat =
|
||||
localStorage.getItem("filenameFormat") ?? "VERT_%name%";
|
||||
const settings = JSON.parse(localStorage.getItem("settings") ?? "{}");
|
||||
const filenameFormat = settings.filenameFormat ?? "VERT_%name%";
|
||||
|
||||
const format = (name: string) => {
|
||||
const date = new Date().toISOString();
|
||||
|
|
|
@ -57,8 +57,8 @@ export class VertFile {
|
|||
public async download() {
|
||||
if (!this.result) throw new Error("No result found");
|
||||
|
||||
const filenameFormat =
|
||||
localStorage.getItem("filenameFormat") ?? "VERT_%name%";
|
||||
const settings = JSON.parse(localStorage.getItem("settings") ?? "{}");
|
||||
const filenameFormat = settings.filenameFormat ?? "VERT_%name%";
|
||||
|
||||
const format = (name: string) => {
|
||||
const date = new Date().toISOString();
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
const cachedContribs = sessionStorage.getItem("ghContribs");
|
||||
if (cachedContribs) {
|
||||
ghContribs = JSON.parse(cachedContribs);
|
||||
log(["about"], "Loaded GitHub contributors from cache");
|
||||
log(["about"], "loaded GitHub contributors from cache");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue