Skip to content

Commit 312813c

Browse files
authored
fix(settings): Update layoutfluid on config change (@fehmer) (monkeytypegame#6462)
When changing the layoutfluid settings via cmdline the settings page did not update. This also happens on prod so it is not directly related to the change monkeytypegame#6445
1 parent 55e7de7 commit 312813c

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

frontend/src/ts/pages/settings.ts

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ import {
3232
import { getActiveFunboxNames } from "../test/funbox/list";
3333
import { SnapshotPreset } from "../constants/default-snapshot";
3434
import { LayoutsList } from "../constants/layouts";
35+
import { DataArrayPartial } from "slim-select/store";
3536

3637
type SettingsGroups<T extends ConfigValue> = Record<string, SettingsGroup<T>>;
3738

39+
let customLayoutFluidSelect: SlimSelect | undefined;
40+
3841
export const groups: SettingsGroups<ConfigValue> = {};
3942

4043
async function initGroups(): Promise<void> {
@@ -684,34 +687,24 @@ async function fillSettingsPage(): Promise<void> {
684687
Config.keymapSize
685688
);
686689

687-
$(".pageSettings .section[data-config-name='customLayoutfluid'] input").val(
688-
Config.customLayoutfluid.replace(/#/g, " ")
689-
);
690-
691-
const customLayoutfluidActive = Config.customLayoutfluid.split("#");
692690
const customLayoutfluidElement = document.querySelector(
693691
".pageSettings .section[data-config-name='customLayoutfluid'] select"
694692
) as Element;
695693

696-
new SlimSelect({
697-
select: customLayoutfluidElement,
698-
data: [
699-
...customLayoutfluidActive,
700-
...LayoutsList.filter((it) => !customLayoutfluidActive.includes(it)),
701-
].map((layout) => ({
702-
text: layout.replace(/_/g, " "),
703-
value: layout,
704-
selected: customLayoutfluidActive.includes(layout),
705-
})),
706-
settings: { keepOrder: true },
707-
events: {
708-
afterChange: (newVal): void => {
709-
void UpdateConfig.setCustomLayoutfluid(
710-
newVal.map((it) => it.value).join("#")
711-
);
694+
if (customLayoutFluidSelect === undefined) {
695+
customLayoutFluidSelect = new SlimSelect({
696+
select: customLayoutfluidElement,
697+
settings: { keepOrder: true },
698+
events: {
699+
afterChange: (newVal): void => {
700+
const customLayoutfluid = newVal.map((it) => it.value).join("#");
701+
if (customLayoutfluid !== Config.customLayoutfluid) {
702+
void UpdateConfig.setCustomLayoutfluid(customLayoutfluid);
703+
}
704+
},
712705
},
713-
},
714-
});
706+
});
707+
}
715708

716709
$(".pageSettings .section[data-config-name='tapeMargin'] input").val(
717710
Config.tapeMargin
@@ -911,6 +904,13 @@ export async function update(groupUpdate = true): Promise<void> {
911904
$(".pageSettings .tip").html(`
912905
tip: You can also change all these settings quickly using the
913906
command line (<key>${commandKey}</key> or <key>${modifierKey}</key> + <key>shift</key> + <key>p</key>)`);
907+
908+
if (
909+
customLayoutFluidSelect !== undefined &&
910+
customLayoutFluidSelect.getSelected().join("#") !== Config.customLayoutfluid
911+
) {
912+
customLayoutFluidSelect.setData(getLayoutfluidDropdownData());
913+
}
914914
}
915915
function toggleSettingsGroup(groupName: string): void {
916916
const groupEl = $(`.pageSettings .settingsGroup.${groupName}`);
@@ -1359,6 +1359,18 @@ export function setEventDisabled(value: boolean): void {
13591359
configEventDisabled = value;
13601360
}
13611361

1362+
function getLayoutfluidDropdownData(): DataArrayPartial {
1363+
const customLayoutfluidActive = Config.customLayoutfluid.split("#");
1364+
return [
1365+
...customLayoutfluidActive,
1366+
...LayoutsList.filter((it) => !customLayoutfluidActive.includes(it)),
1367+
].map((layout) => ({
1368+
text: layout.replace(/_/g, " "),
1369+
value: layout,
1370+
selected: customLayoutfluidActive.includes(layout),
1371+
}));
1372+
}
1373+
13621374
ConfigEvent.subscribe((eventKey, eventValue) => {
13631375
if (eventKey === "fullConfigChange") setEventDisabled(true);
13641376
if (eventKey === "fullConfigChangeFinished") setEventDisabled(false);

0 commit comments

Comments
 (0)