mirror of https://github.com/VERT-sh/VERT.git
fix: restore format selection on navigation
This commit is contained in:
parent
c0ea06d87a
commit
3cd1989ecd
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { duration, fade, transition } from "$lib/animation";
|
import { duration, fade, transition } from "$lib/animation";
|
||||||
import { m } from "$lib/paraglide/messages";
|
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 type { Categories } from "$lib/types";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ChevronDown, SearchIcon } from "lucide-svelte";
|
import { ChevronDown, SearchIcon } from "lucide-svelte";
|
||||||
|
|
@ -167,6 +167,14 @@
|
||||||
selected = option;
|
selected = option;
|
||||||
open = false;
|
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
|
// find the category of this option if it's not in the current category
|
||||||
if (
|
if (
|
||||||
currentCategory &&
|
currentCategory &&
|
||||||
|
|
|
||||||
|
|
@ -417,6 +417,7 @@ export const gradientColor = writable("");
|
||||||
export const goingLeft = writable(false);
|
export const goingLeft = writable(false);
|
||||||
export const dropping = writable(false);
|
export const dropping = writable(false);
|
||||||
export const vertdLoaded = writable(false);
|
export const vertdLoaded = writable(false);
|
||||||
|
export const dropdownStates = writable<Record<string, string>>({});
|
||||||
|
|
||||||
export const isMobile = writable(false);
|
export const isMobile = writable(false);
|
||||||
export const effects = writable(true);
|
export const effects = writable(true);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
gradientColor,
|
gradientColor,
|
||||||
showGradient,
|
showGradient,
|
||||||
vertdLoaded,
|
vertdLoaded,
|
||||||
|
dropdownStates,
|
||||||
} from "$lib/store/index.svelte";
|
} from "$lib/store/index.svelte";
|
||||||
import { VertFile } from "$lib/types";
|
import { VertFile } from "$lib/types";
|
||||||
import {
|
import {
|
||||||
|
|
@ -31,6 +32,7 @@
|
||||||
import { Settings } from "$lib/sections/settings/index.svelte";
|
import { Settings } from "$lib/sections/settings/index.svelte";
|
||||||
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
|
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
|
||||||
import { GB } from "$lib/consts";
|
import { GB } from "$lib/consts";
|
||||||
|
import { log } from "$lib/logger";
|
||||||
|
|
||||||
let processedFileIds = $state(new Set<string>());
|
let processedFileIds = $state(new Set<string>());
|
||||||
|
|
||||||
|
|
@ -58,8 +60,16 @@
|
||||||
|
|
||||||
let targetFormat: string | undefined;
|
let targetFormat: string | undefined;
|
||||||
|
|
||||||
// use default format if enabled
|
// restore saved format (if navigated back to page for example)
|
||||||
if (settings.useDefaultFormat) {
|
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;
|
let defaultFormat: string | undefined;
|
||||||
const df = settings.defaultFormat;
|
const df = settings.defaultFormat;
|
||||||
if (category === "image") defaultFormat = df.image;
|
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) {
|
if (!targetFormat) {
|
||||||
const firstDiff = categories[category]?.formats.find(
|
const firstDiff = categories[category]?.formats.find(
|
||||||
(f) => f !== file.from,
|
(f) => f !== file.from,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue