fix: all categories/formats fallback

fall back to showing everything if there is no formats returned for some reason & add more logging. some people are seeing this for some reason and idk why
This commit is contained in:
Maya 2026-02-21 19:49:34 +03:00
parent 3dbb80a309
commit ff7456b8b9
No known key found for this signature in database
3 changed files with 60 additions and 4 deletions

View File

@ -79,7 +79,8 @@
"image": "Image", "image": "Image",
"placeholder": "Search format", "placeholder": "Search format",
"no_formats": "No formats available", "no_formats": "No formats available",
"no_results": "No formats match your search" "no_results": "No formats match your search",
"fallback": "An error occurred loading available categories & formats, showing everything."
}, },
"settings": { "settings": {
"settings": "Settings", "settings": "Settings",

View File

@ -9,6 +9,7 @@
import { quintOut } from "svelte/easing"; import { quintOut } from "svelte/easing";
import { VertFile } from "$lib/types"; import { VertFile } from "$lib/types";
import SettingsModal from "./SettingsModal.svelte"; import SettingsModal from "./SettingsModal.svelte";
import { log } from "$lib/util/logger";
type Props = { type Props = {
categories: Categories; categories: Categories;
@ -41,6 +42,11 @@
$effect(() => { $effect(() => {
if (currentCategory) return; if (currentCategory) return;
log(
["dropdown", "init"],
`initializing category, file: ${file?.name}, from: ${from}`,
);
// find the category whose formats overlap most with the converters for this file (or all files) // find the category whose formats overlap most with the converters for this file (or all files)
// this finds the best matching category based on the formats supported by the converters // this finds the best matching category based on the formats supported by the converters
const pickCategoryFromConverters = ( const pickCategoryFromConverters = (
@ -72,6 +78,12 @@
: file.converters : file.converters
: files.files.flatMap((f) => f.converters); : files.files.flatMap((f) => f.converters);
log(
["dropdown", "init"],
`checking converters:`,
convertersToCheck.map((c) => c.formatStrings()),
);
// if file is provided, first try to find its category by input format // if file is provided, first try to find its category by input format
let detectedCategory: string | null = null; let detectedCategory: string | null = null;
if (file && from) { if (file && from) {
@ -79,6 +91,11 @@
Object.keys(categories).find((cat) => Object.keys(categories).find((cat) =>
categories[cat].formats.includes(from), categories[cat].formats.includes(from),
) || null; ) || null;
log(
["dropdown", "init"],
`detected category from input format (${from}):`,
detectedCategory,
);
} }
// fallback to category with most converter overlap if input category not found // fallback to category with most converter overlap if input category not found
@ -87,6 +104,8 @@
pickCategoryFromConverters(convertersToCheck) || pickCategoryFromConverters(convertersToCheck) ||
Object.keys(categories)[0]; Object.keys(categories)[0];
log(["dropdown", "init"], `final detected category:`, detectedCategory);
currentCategory = detectedCategory; currentCategory = detectedCategory;
rootCategory = detectedCategory; rootCategory = detectedCategory;
}); });
@ -143,9 +162,33 @@
) )
: []; : [];
// if no formats found at all, show everything
if (formats.length !== 0) {
const allCategories = Object.keys(categories);
// show formats for current category if set, otherwise all formats
const fallbackFormats =
currentCategory && allCategories.includes(currentCategory)
? categories[currentCategory].formats
: allCategories.flatMap(
(cat) => categories[cat].formats,
);
log(
["dropdown", "filter"],
`no formats found for category ${currentCategory}, showing all categories and formats as fallback`,
);
return {
categories: allCategories,
formats: fallbackFormats,
isFallback: true,
};
}
return { return {
categories: availableCategories, categories: availableCategories,
formats, formats,
isFallback: false,
}; };
} }
const searchLower = normalize(searchQuery); const searchLower = normalize(searchQuery);
@ -162,6 +205,7 @@
return { return {
categories: availableCategories, categories: availableCategories,
formats: [], formats: [],
isFallback: false,
}; };
} }
@ -198,6 +242,7 @@
? matchingCategories ? matchingCategories
: availableCategories, : availableCategories,
formats: filteredFormats, formats: filteredFormats,
isFallback: false,
}; };
}); });
@ -451,16 +496,21 @@
<input <input
type="text" type="text"
placeholder={m["convert.dropdown.placeholder"]()} placeholder={m["convert.dropdown.placeholder"]()}
class="flex-grow w-full !pl-11 !pr-3 rounded-lg bg-panel text-foreground" class="flex-grow w-full !pl-11 !pr-3 rounded-lg bg-panel text-foreground {filteredData.isFallback
? 'opacity-50 cursor-not-allowed'
: ''}"
bind:value={searchQuery} bind:value={searchQuery}
oninput={handleSearch} oninput={handleSearch}
onkeydown={onEnter} onkeydown={onEnter}
onfocus={() => {}} onfocus={() => {}}
id="format-search" id="format-search"
autocomplete="off" autocomplete="off"
disabled={filteredData.isFallback}
/> />
<span <span
class="absolute left-4 top-1/2 -translate-y-1/2 flex items-center" class="absolute left-4 top-1/2 -translate-y-1/2 flex items-center {filteredData.isFallback
? 'opacity-50'
: ''}"
> >
<SearchIcon class="w-4 h-4" /> <SearchIcon class="w-4 h-4" />
</span> </span>
@ -477,6 +527,12 @@
{/if} {/if}
</div> </div>
</div> </div>
<!-- fallback message -->
{#if filteredData.isFallback}
<div class="pb-4 text-center text-muted text-base">
{m["convert.dropdown.fallback"]()}
</div>
{/if}
<!-- available categories --> <!-- available categories -->
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
{#each filteredData.categories as category} {#each filteredData.categories as category}

View File

@ -32,7 +32,6 @@
import { Settings } from "$lib/sections/settings/index.svelte"; import { Settings } from "$lib/sections/settings/index.svelte";
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte"; import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
import { GB } from "$lib/util/consts"; import { GB } from "$lib/util/consts";
import { log } from "$lib/util/logger";
let processedFileIds = $state(new Set<string>()); let processedFileIds = $state(new Set<string>());