From f49a243009e227ea5ba673cd79a0f3b520f76862 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Tue, 24 Jun 2025 13:01:11 +0300 Subject: [PATCH] refactor(Settings): simplify handling for langs --- src/common/index.js | 2 ++ .../Dropdown => common}/useLanguageSorting.ts | 4 +--- .../MultiselectMenu/Dropdown/Dropdown.tsx | 6 ++--- .../Dropdown/Option/Option.less | 4 ---- .../Dropdown/Option/Option.tsx | 11 +-------- .../Settings/General/useGeneralOptions.ts | 15 ++++++++---- .../Settings/Player/usePlayerOptions.ts | 24 ++++++++++--------- 7 files changed, 29 insertions(+), 37 deletions(-) rename src/{components/MultiselectMenu/Dropdown => common}/useLanguageSorting.ts (90%) diff --git a/src/common/index.js b/src/common/index.js index 55ccfe045..3354a64e4 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -26,6 +26,7 @@ const useStreamingServer = require('./useStreamingServer'); const useTorrent = require('./useTorrent'); const useTranslate = require('./useTranslate'); const { default: useOrientation } = require('./useOrientation'); +const { default: useLanguageSorting } = require('./useLanguageSorting'); module.exports = { FileDropProvider, @@ -59,4 +60,5 @@ module.exports = { useTorrent, useTranslate, useOrientation, + useLanguageSorting, }; diff --git a/src/components/MultiselectMenu/Dropdown/useLanguageSorting.ts b/src/common/useLanguageSorting.ts similarity index 90% rename from src/components/MultiselectMenu/Dropdown/useLanguageSorting.ts rename to src/common/useLanguageSorting.ts index 3f1ed39d0..44c8927bd 100644 --- a/src/components/MultiselectMenu/Dropdown/useLanguageSorting.ts +++ b/src/common/useLanguageSorting.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react'; import interfaceLanguages from 'stremio/common/interfaceLanguages.json'; -const useLanguageSorting = (options?: MultiselectMenuOption[]) => { +const useLanguageSorting = (options: MultiselectMenuOption[]) => { const userLangCode = useMemo(() => { const lang = interfaceLanguages.find((l) => l.codes.includes(navigator.language || 'en-US')); if (lang) { @@ -17,8 +17,6 @@ const useLanguageSorting = (options?: MultiselectMenuOption[]) => { }, [options]); const sortedOptions = useMemo(() => { - if (!isLanguageDropdown || !options) return options; - const matchingIndex = options.findIndex((opt) => { const lang = interfaceLanguages.find((l) => l.name === opt.label); return userLangCode.some((code) => lang?.codes.includes(code)); diff --git a/src/components/MultiselectMenu/Dropdown/Dropdown.tsx b/src/components/MultiselectMenu/Dropdown/Dropdown.tsx index ecc0800cb..00fd3ff6a 100644 --- a/src/components/MultiselectMenu/Dropdown/Dropdown.tsx +++ b/src/components/MultiselectMenu/Dropdown/Dropdown.tsx @@ -7,7 +7,6 @@ import classNames from 'classnames'; import Option from './Option'; import Icon from '@stremio/stremio-icons/react'; import styles from './Dropdown.less'; -import useLanguageSorting from './useLanguageSorting'; type Props = { options: MultiselectMenuOption[]; @@ -20,7 +19,6 @@ type Props = { const Dropdown = ({ level, setLevel, options, onSelect, value, menuOpen }: Props) => { const { t } = useTranslation(); - const { isLanguageDropdown, sortedOptions } = useLanguageSorting(options); const optionsRef = useRef(new Map()); const containerRef = useRef(null); @@ -63,8 +61,8 @@ const Dropdown = ({ level, setLevel, options, onSelect, value, menuOpen }: Props : null } - {(isLanguageDropdown ? sortedOptions : options) - ?.filter((option: MultiselectMenuOption) => !option.hidden) + {options + .filter((option: MultiselectMenuOption) => !option.hidden) .map((option: MultiselectMenuOption) => (