Remove "forced languages" from "LangSelect"

This commit is contained in:
schroda
2025-04-21 16:31:51 +02:00
parent a48febeda5
commit fef33f15f9
3 changed files with 8 additions and 34 deletions

View File

@@ -23,30 +23,18 @@ import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
import { cloneObject } from '@/util/cloneObject.tsx';
import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils.ts';
function removeAll(firstList: any[], secondList: any[]) {
secondList.forEach((item) => {
const index = firstList.indexOf(item);
if (index !== -1) {
firstList.splice(index, 1);
}
});
return firstList;
}
interface IProps {
shownLangs: string[];
setShownLangs: (arg0: string[]) => void;
allLangs: string[];
forcedLangs?: string[];
}
export function LangSelect(props: IProps) {
const { t } = useTranslation();
const { shownLangs, setShownLangs, allLangs, forcedLangs = [] } = props;
const { shownLangs, setShownLangs, allLangs } = props;
// hold a copy and only sate state on parent when OK pressed, improves performance
const [mShownLangs, setMShownLangs] = useState(removeAll(cloneObject(shownLangs), forcedLangs));
const [mShownLangs, setMShownLangs] = useState(cloneObject(shownLangs));
const [open, setOpen] = useState<boolean>(false);
const handleCancel = () => {