From 1df50173e223bd9cb8e94acb5254c63e3dad2922 Mon Sep 17 00:00:00 2001 From: Maya Date: Thu, 31 Jul 2025 17:09:55 +0300 Subject: [PATCH] fix: gif to video & format dropdown fixes fixes #107 now fully --- .../functional/FormatDropdown.svelte | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte index 2f181bc..c9525da 100644 --- a/src/lib/components/functional/FormatDropdown.svelte +++ b/src/lib/components/functional/FormatDropdown.svelte @@ -30,39 +30,43 @@ let currentCategory = $state(); let searchQuery = $state(""); let dropdownMenu: HTMLElement | undefined = $state(); + let rootCategory: string | null = null; // initialize current category $effect(() => { - if (!currentCategory) { - if (selected) { - const foundCat = Object.keys(categories).find((cat) => - categories[cat].formats.includes(selected), - ); - currentCategory = - foundCat || Object.keys(categories)[0] || null; - } else { - // find category based on file types - const fileFormats = files.files.map((f) => f.from); - const foundCat = Object.keys(categories).find((cat) => - fileFormats.some((format) => - categories[cat].formats.includes(format), - ), - ); - currentCategory = - foundCat || Object.keys(categories)[0] || null; - } + if (currentCategory) return; + let foundCat: string | undefined; + + if (selected) { + foundCat = Object.keys(categories).find((cat) => + categories[cat].formats.includes(selected), + ); + } else { + // find category based on file types + const fileFormats = files.files.map((f) => f.from); + foundCat = Object.keys(categories).find((cat) => + fileFormats.some((format) => + categories[cat].formats.includes(format), + ), + ); } + + currentCategory = foundCat || Object.keys(categories)[0] || null; + rootCategory = currentCategory; }); // other available categories based on current category (e.g. converting between video and audio) const availableCategories = $derived.by(() => { - if (!currentCategory) return Object.keys(categories); + if (!rootCategory) return Object.keys(categories); - return Object.keys(categories).filter( + let finalCategories = Object.keys(categories).filter( (cat) => - cat === currentCategory || - categories[cat].canConvertTo?.includes(currentCategory || ""), + cat === rootCategory || + categories[rootCategory!]?.canConvertTo?.includes(cat), ); + if (from === ".gif") finalCategories.push("video"); + + return finalCategories; }); const shouldInclude = (format: string, category: string): boolean => {