fix: show formats in current category when searching

also removes unused "settingsStyle" code
This commit is contained in:
JovannMC 2025-05-28 14:56:33 +03:00
parent f18af921ec
commit 12f2216baf
No known key found for this signature in database
1 changed files with 18 additions and 32 deletions

View File

@ -11,7 +11,6 @@
selected?: string; selected?: string;
onselect?: (option: string) => void; onselect?: (option: string) => void;
disabled?: boolean; disabled?: boolean;
settingsStyle?: boolean;
}; };
let { let {
@ -19,7 +18,6 @@
selected = $bindable(""), selected = $bindable(""),
onselect, onselect,
disabled, disabled,
settingsStyle,
}: Props = $props(); }: Props = $props();
let open = $state(false); let open = $state(false);
let hover = $state(false); let hover = $state(false);
@ -60,7 +58,6 @@
categories[cat].canConvertTo?.includes(currentCategory || ""), categories[cat].canConvertTo?.includes(currentCategory || ""),
); );
}); });
const filteredData = $derived.by(() => { const filteredData = $derived.by(() => {
if (!searchQuery) { if (!searchQuery) {
return { return {
@ -71,13 +68,6 @@
}; };
} }
// filter formats across all available categories
const allFormats = availableCategories.flatMap((cat) =>
categories[cat].formats.filter((format) =>
format.toLowerCase().includes(searchQuery.toLowerCase()),
),
);
// filter categories that have matching formats // filter categories that have matching formats
const matchingCategories = availableCategories.filter((cat) => const matchingCategories = availableCategories.filter((cat) =>
categories[cat].formats.some((format) => categories[cat].formats.some((format) =>
@ -85,9 +75,19 @@
), ),
); );
// only show formats from the current category that match the search
const filteredFormats =
currentCategory && categories[currentCategory]
? categories[currentCategory].formats.filter((format) =>
format
.toLowerCase()
.includes(searchQuery.toLowerCase()),
)
: [];
return { return {
categories: matchingCategories, categories: matchingCategories,
formats: allFormats, formats: filteredFormats,
}; };
}); });
@ -98,11 +98,8 @@
}; };
const selectCategory = (category: string) => { const selectCategory = (category: string) => {
if (categories[category]) { if (!categories[category]) return;
currentCategory = category; currentCategory = category;
// clear search when switching categories
searchQuery = "";
}
}; };
const handleSearch = (event: Event) => { const handleSearch = (event: Event) => {
@ -137,21 +134,13 @@
</script> </script>
<div <div
class="relative w-full min-w-fit {settingsStyle class="relative w-full min-w-fit text-xl font-medium text-center"
? 'font-normal'
: 'text-xl font-medium'} text-center"
bind:this={dropdown} bind:this={dropdown}
> >
<button <button
class="font-display w-full {settingsStyle class="font-display w-full justify-center overflow-hidden relative cursor-pointer px-3 py-3.5 bg-button {disabled
? 'justify-between'
: 'justify-center'} overflow-hidden relative cursor-pointer {settingsStyle
? 'px-4'
: 'px-3'} py-3.5 bg-button {disabled
? 'opacity-50 cursor-auto' ? 'opacity-50 cursor-auto'
: 'cursor-pointer'} flex items-center {settingsStyle : 'cursor-pointer'} flex items-center rounded-full focus:!outline-none"
? 'rounded-xl'
: 'rounded-full'} focus:!outline-none"
onclick={() => (open = !open)} onclick={() => (open = !open)}
onmouseenter={() => (hover = true)} onmouseenter={() => (hover = true)}
onmouseleave={() => (hover = false)} onmouseleave={() => (hover = false)}
@ -169,11 +158,7 @@
duration, duration,
easing: quintOut, easing: quintOut,
}} }}
class="col-start-1 row-start-1 {settingsStyle class="col-start-1 row-start-1 text-center font-body font-medium"
? 'text-left'
: 'text-center'} font-body {settingsStyle
? 'font-normal'
: 'font-medium'}"
> >
{selected} {selected}
</p> </p>
@ -195,6 +180,7 @@
: 0}deg); transition: transform {duration}ms {transition};" : 0}deg); transition: transform {duration}ms {transition};"
/> />
</button> </button>
{#if open} {#if open}
<!-- TODO: fix positioning for mobile --> <!-- TODO: fix positioning for mobile -->
<div <div