From c3317bd9ec69c11902d000f8d875aa6acc820574 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 23 Jan 2023 23:56:09 +1100 Subject: [PATCH] feat(menu): allow only one theme of each mode to be enabled at a time --- src/core/menu/islands/List.mjs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/menu/islands/List.mjs b/src/core/menu/islands/List.mjs index c1ad16c..21315fb 100644 --- a/src/core/menu/islands/List.mjs +++ b/src/core/menu/islands/List.mjs @@ -43,6 +43,21 @@ function List({ id, mods, description }) { const _get = () => isEnabled(mod.id), _set = async (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 }); }; return html`<${Mod} ...${{ ...mod, _get, _set }} />`;