mirror of https://github.com/VERT-sh/VERT.git
parent
1cf69a061d
commit
1df50173e2
|
@ -30,39 +30,43 @@
|
||||||
let currentCategory = $state<string | null>();
|
let currentCategory = $state<string | null>();
|
||||||
let searchQuery = $state("");
|
let searchQuery = $state("");
|
||||||
let dropdownMenu: HTMLElement | undefined = $state();
|
let dropdownMenu: HTMLElement | undefined = $state();
|
||||||
|
let rootCategory: string | null = null;
|
||||||
|
|
||||||
// initialize current category
|
// initialize current category
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!currentCategory) {
|
if (currentCategory) return;
|
||||||
if (selected) {
|
let foundCat: string | undefined;
|
||||||
const foundCat = Object.keys(categories).find((cat) =>
|
|
||||||
categories[cat].formats.includes(selected),
|
if (selected) {
|
||||||
);
|
foundCat = Object.keys(categories).find((cat) =>
|
||||||
currentCategory =
|
categories[cat].formats.includes(selected),
|
||||||
foundCat || Object.keys(categories)[0] || null;
|
);
|
||||||
} else {
|
} else {
|
||||||
// find category based on file types
|
// find category based on file types
|
||||||
const fileFormats = files.files.map((f) => f.from);
|
const fileFormats = files.files.map((f) => f.from);
|
||||||
const foundCat = Object.keys(categories).find((cat) =>
|
foundCat = Object.keys(categories).find((cat) =>
|
||||||
fileFormats.some((format) =>
|
fileFormats.some((format) =>
|
||||||
categories[cat].formats.includes(format),
|
categories[cat].formats.includes(format),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
currentCategory =
|
|
||||||
foundCat || Object.keys(categories)[0] || null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentCategory = foundCat || Object.keys(categories)[0] || null;
|
||||||
|
rootCategory = currentCategory;
|
||||||
});
|
});
|
||||||
|
|
||||||
// other available categories based on current category (e.g. converting between video and audio)
|
// other available categories based on current category (e.g. converting between video and audio)
|
||||||
const availableCategories = $derived.by(() => {
|
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) =>
|
||||||
cat === currentCategory ||
|
cat === rootCategory ||
|
||||||
categories[cat].canConvertTo?.includes(currentCategory || ""),
|
categories[rootCategory!]?.canConvertTo?.includes(cat),
|
||||||
);
|
);
|
||||||
|
if (from === ".gif") finalCategories.push("video");
|
||||||
|
|
||||||
|
return finalCategories;
|
||||||
});
|
});
|
||||||
|
|
||||||
const shouldInclude = (format: string, category: string): boolean => {
|
const shouldInclude = (format: string, category: string): boolean => {
|
||||||
|
|
Loading…
Reference in New Issue