fix: gif to video & format dropdown fixes

fixes #107 now fully
This commit is contained in:
Maya 2025-07-31 17:09:55 +03:00
parent 1cf69a061d
commit 1df50173e2
No known key found for this signature in database
1 changed files with 26 additions and 22 deletions

View File

@ -30,39 +30,43 @@
let currentCategory = $state<string | null>();
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 => {