feat(menu): allow only one theme of each mode to be enabled at a time

This commit is contained in:
dragonwocky 2023-01-23 23:56:09 +11:00
parent 7b6a244d72
commit c3317bd9ec
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8

View File

@ -43,6 +43,21 @@ function List({ id, mods, description }) {
const _get = () => isEnabled(mod.id), const _get = () => isEnabled(mod.id),
_set = async (enabled) => { _set = async (enabled) => {
await setEnabled(mod.id, enabled); await setEnabled(mod.id, enabled);
// only one theme of each mode may be
// enabled at a time ∴ disable others
// on theme of same mode enabled
if (enabled && id === "themes") {
const isDark = mod.tags.includes("dark"),
isLight = mod.tags.includes("light");
for (const other of mods) {
if (other.id === mod.id) continue;
const otherDark = other.tags.includes("dark"),
otherLight = other.tags.includes("light");
if ((isDark && otherDark) || (isLight && otherLight)) {
await setEnabled(other.id, false);
}
}
}
setState({ rerender: true, databaseUpdated: true }); setState({ rerender: true, databaseUpdated: true });
}; };
return html`<${Mod} ...${{ ...mod, _get, _set }} />`; return html`<${Mod} ...${{ ...mod, _get, _set }} />`;