force Local source at LangSelect

This commit is contained in:
Aria Moradi
2021-10-18 14:22:33 +03:30
parent 23c8e649a1
commit 35da3b76c8
2 changed files with 23 additions and 3 deletions

View File

@@ -28,16 +28,31 @@ const useStyles = makeStyles(() => createStyles({
}, },
})); }));
function removeAll(firstList: any[], secondList: any[]) {
console.log(secondList);
secondList.forEach((item) => {
const index = firstList.indexOf(item);
if (index !== -1) {
firstList.splice(index, 1);
}
});
return firstList;
}
interface IProps { interface IProps {
shownLangs: string[] shownLangs: string[]
setShownLangs: (arg0: string[]) => void setShownLangs: (arg0: string[]) => void
allLangs: string[] allLangs: string[]
forcedLangs?: string[]
} }
export default function ExtensionLangSelect(props: IProps) { export default function ExtensionLangSelect(props: IProps) {
const { shownLangs, setShownLangs, allLangs } = props; const {
shownLangs, setShownLangs, allLangs, forcedLangs,
} = props;
// hold a copy and only sate state on parent when OK pressed, improves performance // hold a copy and only sate state on parent when OK pressed, improves performance
const [mShownLangs, setMShownLangs] = useState(shownLangs); const [mShownLangs, setMShownLangs] = useState(removeAll(shownLangs, forcedLangs!));
const classes = useStyles(); const classes = useStyles();
const [open, setOpen] = useState<boolean>(false); const [open, setOpen] = useState<boolean>(false);
@@ -109,3 +124,7 @@ export default function ExtensionLangSelect(props: IProps) {
</> </>
); );
} }
ExtensionLangSelect.defaultProps = {
forcedLangs: [] as string[],
};

View File

@@ -59,7 +59,7 @@ export default function MangaSources() {
}); });
} }
}); });
}, [shownLangs]); }, []);
useEffect(() => { useEffect(() => {
setTitle('Sources'); setTitle('Sources');
@@ -68,6 +68,7 @@ export default function MangaSources() {
shownLangs={shownLangs} shownLangs={shownLangs}
setShownLangs={setShownLangs} setShownLangs={setShownLangs}
allLangs={sourceToLangList(sources)} allLangs={sourceToLangList(sources)}
forcedLangs={sourceForcedDefaultLangs()}
/>, />,
); );
}, [shownLangs, sources]); }, [shownLangs, sources]);