fix: don't show gifs in video category

This commit is contained in:
JovannMC 2025-06-01 23:57:23 +03:00
parent c75441fdc9
commit 332cd24dfc
No known key found for this signature in database
2 changed files with 24 additions and 8 deletions

View File

@ -8,6 +8,7 @@
type Props = { type Props = {
categories: Categories; categories: Categories;
from?: string;
selected?: string; selected?: string;
onselect?: (option: string) => void; onselect?: (option: string) => void;
disabled?: boolean; disabled?: boolean;
@ -15,6 +16,7 @@
let { let {
categories, categories,
from,
selected = $bindable(""), selected = $bindable(""),
onselect, onselect,
disabled, disabled,
@ -59,6 +61,15 @@
); );
}); });
const shouldInclude = (format: string, category: string): boolean => {
// if converting from audio to video, dont show gifs
if (categories["audio"]?.formats.includes(from ?? "") && format === ".gif") {
return false;
}
return true;
};
const filteredData = $derived.by(() => { const filteredData = $derived.by(() => {
const normalize = (str: string) => str.replace(/^\./, "").toLowerCase(); const normalize = (str: string) => str.replace(/^\./, "").toLowerCase();
@ -67,7 +78,9 @@
return { return {
categories: availableCategories, categories: availableCategories,
formats: currentCategory formats: currentCategory
? categories[currentCategory].formats ? categories[currentCategory].formats.filter((format) =>
shouldInclude(format, currentCategory!),
)
: [], : [],
}; };
} }
@ -75,8 +88,10 @@
// find all categories that have formats matching the search query // find all categories that have formats matching the search query
const matchingCategories = availableCategories.filter((cat) => const matchingCategories = availableCategories.filter((cat) =>
categories[cat].formats.some((format) => categories[cat].formats.some(
normalize(format).includes(searchLower), (format) =>
normalize(format).includes(searchLower) &&
shouldInclude(format, cat),
), ),
); );
if (matchingCategories.length === 0) { if (matchingCategories.length === 0) {
@ -89,9 +104,7 @@
// if current category has no matches, switch to first category that does // if current category has no matches, switch to first category that does
const currentCategoryHasMatches = const currentCategoryHasMatches =
currentCategory && currentCategory &&
matchingCategories.some( matchingCategories.some((cat) => cat === currentCategory);
(cat) => cat === currentCategory,
);
if (!currentCategoryHasMatches && matchingCategories.length > 0) { if (!currentCategoryHasMatches && matchingCategories.length > 0) {
const newCategory = matchingCategories[0]; const newCategory = matchingCategories[0];
currentCategory = newCategory; currentCategory = newCategory;
@ -99,8 +112,10 @@
// return formats only from the current category that match the search // return formats only from the current category that match the search
let filteredFormats = currentCategory let filteredFormats = currentCategory
? categories[currentCategory].formats.filter((format) => ? categories[currentCategory].formats.filter(
normalize(format).includes(searchLower), (format) =>
normalize(format).includes(searchLower) &&
shouldInclude(format, currentCategory!),
) )
: []; : [];

View File

@ -267,6 +267,7 @@
> >
<FormatDropdown <FormatDropdown
{categories} {categories}
from={file.from}
bind:selected={file.to} bind:selected={file.to}
onselect={(option) => handleSelect(option, file)} onselect={(option) => handleSelect(option, file)}
/> />