fix: wrong formats showing

i forgot about isNative lmao

why am i programmer again
This commit is contained in:
JovannMC 2025-06-01 22:02:14 +03:00
parent 2af5651d19
commit c75441fdc9
No known key found for this signature in database
2 changed files with 19 additions and 71 deletions

View File

@ -20,9 +20,7 @@
disabled, disabled,
}: Props = $props(); }: Props = $props();
let open = $state(false); let open = $state(false);
let hover = $state(false);
let dropdown = $state<HTMLDivElement>(); let dropdown = $state<HTMLDivElement>();
let initialCategory = $state<string | null>();
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();
@ -36,7 +34,6 @@
); );
currentCategory = currentCategory =
foundCat || Object.keys(categories)[0] || null; foundCat || Object.keys(categories)[0] || null;
initialCategory = currentCategory;
} 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);
@ -47,7 +44,6 @@
); );
currentCategory = currentCategory =
foundCat || Object.keys(categories)[0] || null; foundCat || Object.keys(categories)[0] || null;
initialCategory = currentCategory;
} }
} }
}); });
@ -63,34 +59,6 @@
); );
}); });
const shouldShowFormat = (format: string, category: string): boolean => {
const currentFileExt = files.files[0]?.from;
if (!currentFileExt) return true;
if (category === initialCategory) {
return true;
} else if (
initialCategory &&
categories[initialCategory].formats.includes(format)
) {
return false;
}
const formatInOtherCategories = Object.keys(categories)
.filter((cat) => cat !== category)
.some((cat) => categories[cat].formats.includes(format));
if (formatInOtherCategories) {
const nativeCategory = Object.keys(categories).find((cat) =>
cat.toLowerCase().includes(format.slice(1)),
);
return category === nativeCategory;
}
return true;
};
const filteredData = $derived.by(() => { const filteredData = $derived.by(() => {
const normalize = (str: string) => str.replace(/^\./, "").toLowerCase(); const normalize = (str: string) => str.replace(/^\./, "").toLowerCase();
@ -99,9 +67,7 @@
return { return {
categories: availableCategories, categories: availableCategories,
formats: currentCategory formats: currentCategory
? categories[currentCategory].formats.filter((format) => ? categories[currentCategory].formats
shouldShowFormat(format, currentCategory || ""),
)
: [], : [],
}; };
} }
@ -109,10 +75,8 @@
// 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( categories[cat].formats.some((format) =>
(format) => normalize(format).includes(searchLower),
normalize(format).includes(searchLower) &&
shouldShowFormat(format, cat),
), ),
); );
if (matchingCategories.length === 0) { if (matchingCategories.length === 0) {
@ -122,22 +86,11 @@
}; };
} }
// find all matching formats across all categories
const allMatchingFormats = matchingCategories.flatMap((cat) => {
return categories[cat].formats
.filter(
(format) =>
normalize(format).includes(searchLower) &&
shouldShowFormat(format, cat),
)
.map((format) => ({ format, category: cat }));
});
// 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 &&
allMatchingFormats.some( matchingCategories.some(
(item) => item.category === currentCategory, (cat) => cat === currentCategory,
); );
if (!currentCategoryHasMatches && matchingCategories.length > 0) { if (!currentCategoryHasMatches && matchingCategories.length > 0) {
const newCategory = matchingCategories[0]; const newCategory = matchingCategories[0];
@ -146,10 +99,8 @@
// 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( ? categories[currentCategory].formats.filter((format) =>
(format) => normalize(format).includes(searchLower),
normalize(format).includes(searchLower) &&
shouldShowFormat(format, currentCategory || ""),
) )
: []; : [];
@ -205,20 +156,16 @@
if (query) { if (query) {
const queryLower = query.toLowerCase(); const queryLower = query.toLowerCase();
const categoriesWithMatches = availableCategories.filter((cat) => const categoriesWithMatches = availableCategories.filter((cat) =>
categories[cat].formats.some( categories[cat].formats.some((format) =>
(format) => format.toLowerCase().includes(queryLower),
format.toLowerCase().includes(queryLower) &&
shouldShowFormat(format, cat),
), ),
); );
if (categoriesWithMatches.length > 0) { if (categoriesWithMatches.length > 0) {
const currentHasMatches = const currentHasMatches =
currentCategory && currentCategory &&
categories[currentCategory].formats.some( categories[currentCategory].formats.some((format) =>
(format) => format.toLowerCase().includes(queryLower),
format.toLowerCase().includes(queryLower) &&
shouldShowFormat(format, currentCategory || ""),
); );
if (!currentHasMatches) { if (!currentHasMatches) {
@ -289,8 +236,6 @@
class="relative flex items-center justify-center w-full font-display px-3 py-3.5 bg-button rounded-full overflow-hidden cursor-pointer focus:!outline-none class="relative flex items-center justify-center w-full font-display px-3 py-3.5 bg-button rounded-full overflow-hidden cursor-pointer focus:!outline-none
{disabled ? 'opacity-50 cursor-auto' : 'cursor-pointer'}" {disabled ? 'opacity-50 cursor-auto' : 'cursor-pointer'}"
onclick={() => clickDropdown()} onclick={() => clickDropdown()}
onmouseenter={() => (hover = true)}
onmouseleave={() => (hover = false)}
{disabled} {disabled}
> >
<!-- <p>{selected}</p> --> <!-- <p>{selected}</p> -->
@ -348,7 +293,6 @@
bind:value={searchQuery} bind:value={searchQuery}
oninput={handleSearch} oninput={handleSearch}
onkeydown={onEnter} onkeydown={onEnter}
onfocus={() => {}}
id="format-search" id="format-search"
autocomplete="off" autocomplete="off"
/> />

View File

@ -31,19 +31,23 @@ export const categories: Categories = {
categories.audio.formats = categories.audio.formats =
converters converters
.find((c) => c.name === "ffmpeg") .find((c) => c.name === "ffmpeg")
?.formatStrings((f) => f.toSupported) || []; ?.supportedFormats.filter((f) => f.toSupported && f.isNative)
.map((f) => f.name) || [];
categories.video.formats = categories.video.formats =
converters converters
.find((c) => c.name === "vertd") .find((c) => c.name === "vertd")
?.formatStrings((f) => f.toSupported) || []; ?.supportedFormats.filter((f) => f.toSupported && f.isNative)
.map((f) => f.name) || [];
categories.image.formats = categories.image.formats =
converters converters
.find((c) => c.name === "libvips") .find((c) => c.name === "libvips")
?.formatStrings((f) => f.toSupported) || []; ?.supportedFormats.filter((f) => f.toSupported && f.isNative)
.map((f) => f.name) || [];
categories.docs.formats = categories.docs.formats =
converters converters
.find((c) => c.name === "pandoc") .find((c) => c.name === "pandoc")
?.formatStrings((f) => f.toSupported) || []; ?.supportedFormats.filter((f) => f.toSupported && f.isNative)
.map((f) => f.name) || [];
export const byNative = (format: string) => { export const byNative = (format: string) => {
return (a: Converter, b: Converter) => { return (a: Converter, b: Converter) => {