Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix: restore format selection on navigation

Maya3cd1989ecd86
diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte
index 097a899..333770a 100644
--- a/src/lib/components/functional/FormatDropdown.svelte
+++ b/src/lib/components/functional/FormatDropdown.svelte
@@ -1,7 +1,7 @@
<script lang="ts">
import { duration, fade, transition } from "$lib/animation";
import { m } from "$lib/paraglide/messages";
- import { isMobile, files } from "$lib/store/index.svelte";
+ import { isMobile, files, dropdownStates } from "$lib/store/index.svelte";
import type { Categories } from "$lib/types";
import clsx from "clsx";
import { ChevronDown, SearchIcon } from "lucide-svelte";
@@ -167,6 +167,14 @@
selected = option;
open = false;
+ // save user's selection to dropdownStates for this session
+ if (file) {
+ dropdownStates.update((states) => {
+ const updated = { ...states, [file.name]: option };
+ return updated;
+ });
+ }
+
// find the category of this option if it's not in the current category
if (
currentCategory &&
diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts
index 6d4504e..db0269d 100644
--- a/src/lib/store/index.svelte.ts
+++ b/src/lib/store/index.svelte.ts
@@ -417,6 +417,7 @@ export const gradientColor = writable("");
export const goingLeft = writable(false);
export const dropping = writable(false);
export const vertdLoaded = writable(false);
+export const dropdownStates = writable<Record<string, string>>({});
export const isMobile = writable(false);
export const effects = writable(true);
diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte
index 8b93c9e..e6959f2 100644
--- a/src/routes/convert/+page.svelte
+++ b/src/routes/convert/+page.svelte
@@ -12,6 +12,7 @@
gradientColor,
showGradient,
vertdLoaded,
+ dropdownStates,
} from "$lib/store/index.svelte";
import { VertFile } from "$lib/types";
import {
@@ -31,6 +32,7 @@
import { Settings } from "$lib/sections/settings/index.svelte";
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
import { GB } from "$lib/consts";
+ import { log } from "$lib/logger";
let processedFileIds = $state(new Set<string>());
@@ -58,8 +60,16 @@
let targetFormat: string | undefined;
- // use default format if enabled
- if (settings.useDefaultFormat) {
+ // restore saved format (if navigated back to page for example)
+ const savedFormat = $dropdownStates[file.name];
+ if (
+ savedFormat &&
+ savedFormat !== file.from &&
+ categories[category]?.formats.includes(savedFormat)
+ ) {
+ targetFormat = savedFormat;
+ } else if (settings.useDefaultFormat) {
+ // else use default format if enabled
let defaultFormat: string | undefined;
const df = settings.defaultFormat;
if (category === "image") defaultFormat = df.image;
@@ -76,7 +86,7 @@
}
}
- // else use first available format (or if default format is same as input)
+ // or use first available format (or if default format is same as input)
if (!targetFormat) {
const firstDiff = categories[category]?.formats.find(
(f) => f !== file.from,