feat(settings): navigate to submenu when activating a menu
This commit is contained in:
@@ -14,22 +14,16 @@ import Selector from "~/components/Common/ButtonSelector.vue";
|
|||||||
const app = useAppStore();
|
const app = useAppStore();
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
type Menu = "options" | "clock" | "user" | "touchScreen";
|
const isMainMenu = (button: string): button is SettingsMenu =>
|
||||||
|
SETTINGS_MENUS.includes(button as SettingsMenu);
|
||||||
|
|
||||||
const MAIN_MENUS: Menu[] = ["options", "clock", "user", "touchScreen"];
|
const isSubMenu = (button: string): button is SettingsSubMenu =>
|
||||||
|
SETTINGS_SUB_MENUS.includes(button as SettingsSubMenu);
|
||||||
|
|
||||||
const isMainMenu = (button: string): button is Menu => {
|
const getParentMenu = (submenu: string): SettingsMenu => {
|
||||||
return MAIN_MENUS.includes(button as Menu);
|
|
||||||
};
|
|
||||||
|
|
||||||
const isSubMenu = (button: string): boolean => {
|
|
||||||
return /^(options|clock|user|touchScreen)[A-Z]/.test(button);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getParentMenu = (submenu: string): Menu => {
|
|
||||||
const match = submenu.match(/^(options|clock|user|touchScreen)/);
|
const match = submenu.match(/^(options|clock|user|touchScreen)/);
|
||||||
if (!match?.[1]) throw new Error(`Invalid submenu: '${submenu}'`);
|
if (!match?.[1]) throw new Error(`Invalid submenu: '${submenu}'`);
|
||||||
return match[1] as Menu;
|
return match[1] as SettingsMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { selectedButton: selected, selectorPosition } = useButtonNavigation({
|
const { selectedButton: selected, selectorPosition } = useButtonNavigation({
|
||||||
@@ -53,9 +47,14 @@ const { selectedButton: selected, selectorPosition } = useButtonNavigation({
|
|||||||
touchScreen: [175, 119, 49, 49],
|
touchScreen: [175, 119, 49, 49],
|
||||||
},
|
},
|
||||||
initialButton: "options",
|
initialButton: "options",
|
||||||
onButtonClick: (buttonName: string) => {
|
onButtonClick: (buttonName) => {
|
||||||
if (isSubMenu(buttonName)) {
|
if (isSubMenu(buttonName)) {
|
||||||
settingsStore.openSubMenu(buttonName);
|
settingsStore.openSubMenu(buttonName);
|
||||||
|
} else {
|
||||||
|
if (buttonName === "options") selected.value = "optionsLanguage";
|
||||||
|
if (buttonName === "clock") selected.value = "clockAlarm";
|
||||||
|
if (buttonName === "user") selected.value = "userName";
|
||||||
|
if (buttonName === "touchScreen") throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
navigation: {
|
navigation: {
|
||||||
|
|||||||
Reference in New Issue
Block a user