diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index 5b0749c01..e6e63c9ce 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -9,7 +9,7 @@ import TabManager from "./tab_manager.js"; import Component from "./component.js"; import keyboardActionsService from "../services/keyboard_actions.js"; import linkService, { ViewScope } from "../services/link.js"; -import MobileScreenSwitcherExecutor from "./mobile_screen_switcher.js"; +import MobileScreenSwitcherExecutor, { Screen } from "./mobile_screen_switcher.js"; import MainTreeExecutors from "./main_tree_executors.js"; import toast from "../services/toast.js"; import ShortcutComponent from "./shortcut_component.js"; @@ -157,6 +157,9 @@ export type CommandMappings = { moveBranchIdsTo: CommandData & { branchIds: string[]; }; + setActiveScreen: CommandData & { + screen: Screen; + } } type EventMappings = { @@ -188,6 +191,11 @@ export type EventListener = { [key in T as `${key}Event`]: (data: EventData) => void } +export type CommandListener = { + [key in T as `${key}Command`]: (data: CommandListenerData) => void +} + +export type CommandListenerData = CommandMappings[T]; export type EventData = EventMappings[T]; type CommandAndEventMappings = (CommandMappings & EventMappings); diff --git a/src/public/app/components/mobile_screen_switcher.js b/src/public/app/components/mobile_screen_switcher.ts similarity index 61% rename from src/public/app/components/mobile_screen_switcher.js rename to src/public/app/components/mobile_screen_switcher.ts index fe0af1a32..0a779f372 100644 --- a/src/public/app/components/mobile_screen_switcher.js +++ b/src/public/app/components/mobile_screen_switcher.ts @@ -1,8 +1,14 @@ import Component from "./component.js"; -import appContext from "./app_context.js"; +import appContext, { CommandListener, CommandListenerData } from "./app_context.js"; -export default class MobileScreenSwitcherExecutor extends Component { - setActiveScreenCommand({screen}) { +export type Screen = "detail" | "tree"; + +export default class MobileScreenSwitcherExecutor extends Component + implements CommandListener<"setActiveScreen"> +{ + private activeScreen?: Screen; + + setActiveScreenCommand({screen}: CommandListenerData<"setActiveScreen">) { if (screen !== this.activeScreen) { this.activeScreen = screen;