Skip to content

Commit e1c8e4a

Browse files
authored
impr(settings): use dropdown for custom layoutfluid (@fehmer) (monkeytypegame#6445)
1 parent 4abcc8c commit e1c8e4a

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

frontend/src/html/pages/settings.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,7 @@
347347
Select which layouts you want the layoutfluid funbox to cycle through.
348348
</div>
349349
<div class="inputs">
350-
<div class="inputAndButton">
351-
<input
352-
type="text"
353-
placeholder="layouts (separated by space)"
354-
class="input"
355-
tabindex="0"
356-
/>
357-
<button class="save no-auto-handle">
358-
<i class="fas fa-save fa-fw"></i>
359-
</button>
360-
</div>
350+
<select multiple></select>
361351
</div>
362352
</div>
363353
<div class="sectionSpacer"></div>

frontend/src/ts/pages/settings.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as CustomBackgroundFilter from "../elements/custom-background-filter";
2323
import {
2424
ConfigValue,
2525
CustomBackgroundSchema,
26-
CustomLayoutFluid,
2726
} from "@monkeytype/contracts/schemas/configs";
2827
import {
2928
getAllFunboxes,
@@ -433,10 +432,6 @@ async function initGroups(): Promise<void> {
433432
UpdateConfig.setCustomBackgroundSize,
434433
"button"
435434
) as SettingsGroup<ConfigValue>;
436-
// groups.customLayoutfluid = new SettingsGroup(
437-
// "customLayoutfluid",
438-
// UpdateConfig.setCustomLayoutfluid
439-
// );
440435
}
441436

442437
function reset(): void {
@@ -693,6 +688,31 @@ async function fillSettingsPage(): Promise<void> {
693688
Config.customLayoutfluid.replace(/#/g, " ")
694689
);
695690

691+
const customLayoutfluidActive = Config.customLayoutfluid.split("#");
692+
const customLayoutfluidElement = document.querySelector(
693+
".pageSettings .section[data-config-name='customLayoutfluid'] select"
694+
) as Element;
695+
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+
);
712+
},
713+
},
714+
});
715+
696716
$(".pageSettings .section[data-config-name='tapeMargin'] input").val(
697717
Config.tapeMargin
698718
);
@@ -1324,29 +1344,6 @@ $(
13241344
}
13251345
});
13261346

1327-
const handleLayoutfluid = (): void => {
1328-
if (
1329-
UpdateConfig.setCustomLayoutfluid(
1330-
$(
1331-
".pageSettings .section[data-config-name='customLayoutfluid'] .inputAndButton input"
1332-
).val() as CustomLayoutFluid
1333-
)
1334-
) {
1335-
Notifications.add("Custom layoutfluid saved", 1);
1336-
}
1337-
};
1338-
$(
1339-
".pageSettings .section[data-config-name='customLayoutfluid'] .inputAndButton button.save"
1340-
).on("click", handleLayoutfluid);
1341-
1342-
$(
1343-
".pageSettings .section[data-config-name='customLayoutfluid'] .inputAndButton .input"
1344-
).on("keypress", (e) => {
1345-
if (e.key === "Enter") {
1346-
handleLayoutfluid();
1347-
}
1348-
});
1349-
13501347
$(".pageSettings .quickNav .links a").on("click", (e) => {
13511348
const settingsGroup = e.target.innerText;
13521349
const isClosed = $(`.pageSettings .settingsGroup.${settingsGroup}`).hasClass(

0 commit comments

Comments
 (0)