fix: restore format selection on navigation

This commit is contained in:
Maya 2025-11-19 21:14:50 +03:00
parent c0ea06d87a
commit 3cd1989ecd
No known key found for this signature in database
3 changed files with 23 additions and 4 deletions

View File

@ -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 &&

View File

@ -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);

View File

@ -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,