fix(Settings): correctly sort without matchingidx

This commit is contained in:
Timothy Z. 2025-06-25 16:59:16 +03:00
parent f7f97b551c
commit 652a042a55
2 changed files with 6 additions and 4 deletions

View file

@ -22,10 +22,12 @@ const useLanguageSorting = (options: MultiselectMenuOption[]) => {
return userLangCode.some((code) => lang?.codes.includes(code));
});
if (matchingIndex === -1) return options;
if (matchingIndex === -1) {
return [...options].sort((a, b) => a.label.localeCompare(b.label));
}
const matchingOption = options[matchingIndex];
const otherOptions = options.filter((_, index) => index !== matchingIndex);
const otherOptions = options.filter((_, idx) => idx !== matchingIndex).sort((a, b) => a.label.localeCompare(b.label));
return [matchingOption, ...otherOptions];
}, [options, userLangCode, isLanguageDropdown]);

View file

@ -20,7 +20,7 @@ const usePlayerOptions = (profile: Profile) => {
const subtitlesLanguageSelect = useMemo(() => ({
options: [
{ value: null, label: t('NONE') },
...sortedLanguageOptions.sort((a, b) => a.label.localeCompare(b.label))
...sortedLanguageOptions
],
value: profile.settings.subtitlesLanguage,
onSelect: (value: string) => {
@ -109,7 +109,7 @@ const usePlayerOptions = (profile: Profile) => {
}), [profile.settings]);
const audioLanguageSelect = useMemo(() => ({
options: sortedLanguageOptions.sort((a, b) => a.label.localeCompare(b.label)),
options: sortedLanguageOptions,
value: profile.settings.audioLanguage,
onSelect: (value: string) => {
core.transport.dispatch({