/* * Copyright (C) Contributors to the Suwayomi project * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import React, { useState } from 'react'; import Button from '@mui/material/Button'; import DialogTitle from '@mui/material/DialogTitle'; import DialogContent from '@mui/material/DialogContent'; import DialogActions from '@mui/material/DialogActions'; import Dialog from '@mui/material/Dialog'; import Switch from '@mui/material/Switch'; import IconButton from '@mui/material/IconButton'; import FilterListIcon from '@mui/icons-material/FilterList'; import List from '@mui/material/List'; import ListItemText from '@mui/material/ListItemText'; import ListItem from '@mui/material/ListItem'; import { useTranslation } from 'react-i18next'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { cloneObject } from '@/util/cloneObject.tsx'; import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils.ts'; interface IProps { shownLangs: string[]; setShownLangs: (arg0: string[]) => void; allLangs: string[]; } export function LangSelect(props: IProps) { const { t } = useTranslation(); const { shownLangs, setShownLangs, allLangs } = props; // hold a copy and only sate state on parent when OK pressed, improves performance const [mShownLangs, setMShownLangs] = useState(cloneObject(shownLangs)); const [open, setOpen] = useState(false); const handleCancel = () => { setOpen(false); }; const handleOk = () => { setOpen(false); setShownLangs(mShownLangs); }; const handleChange = (event: React.ChangeEvent, lang: string) => { const { checked } = event.target as HTMLInputElement; if (checked) { setMShownLangs([...mShownLangs, lang]); } else { const clone = cloneObject(mShownLangs); clone.splice(clone.indexOf(lang), 1); setMShownLangs(clone); } }; return ( <> setOpen(true)} aria-label="display more actions" edge="end" color="inherit"> {t('global.language.title.enabled_languages')} {allLangs.map((lang) => ( handleChange(e, lang)} /> ))} ); }