From 24a47496a55c6cd2e8662ef52c38c33873d6efbd Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Thu, 10 Oct 2024 11:48:44 -0400 Subject: [PATCH] save --- frontend/app/store/global.ts | 23 +++++++++++ frontend/app/store/keymodel.ts | 40 +++++++++++++++---- .../app/view/preview/directorypreview.tsx | 5 ++- frontend/wave.ts | 2 + 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 65abf14e7..2648758d4 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -398,6 +398,12 @@ async function openLink(uri: string, forceOpenInternally = false) { } } +function getActiveBlockId() { + const layoutModel = getLayoutModelForActiveTab(); + const focusedNode = globalStore.get(layoutModel.focusedNode); + return focusedNode?.data?.blockId; +} + function registerBlockComponentModel(blockId: string, bcm: BlockComponentModel) { blockComponentModelMap.set(blockId, bcm); } @@ -410,6 +416,11 @@ function getBlockComponentModel(blockId: string): BlockComponentModel { return blockComponentModelMap.get(blockId); } +function getActiveBlockComponentModel(): BlockComponentModel { + const blockId = getActiveBlockId(); + return getBlockComponentModel(blockId); +} + function refocusNode(blockId: string) { if (blockId == null) { return; @@ -457,6 +468,15 @@ async function loadConnStatus() { } } +function subscribeToBrowserEvents() { + window.addEventListener("hashchange", (e) => { + console.log("hashchange"); + }); + window.addEventListener("popstate", (e) => { + console.log("popstate"); + }); +} + function subscribeToConnEvents() { waveEventSubscribe({ eventType: "connchange", @@ -529,6 +549,8 @@ export { countersPrint, createBlock, fetchWaveFile, + getActiveBlockComponentModel, + getActiveBlockId, getApi, getBlockComponentModel, getConnStatusAtom, @@ -549,6 +571,7 @@ export { removeFlashError, setNodeFocus, setPlatform, + subscribeToBrowserEvents, subscribeToConnEvents, unregisterBlockComponentModel, useBlockAtom, diff --git a/frontend/app/store/keymodel.ts b/frontend/app/store/keymodel.ts index 048786f2e..dc4c36f61 100644 --- a/frontend/app/store/keymodel.ts +++ b/frontend/app/store/keymodel.ts @@ -1,7 +1,15 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { atoms, createBlock, getApi, getBlockComponentModel, globalStore, refocusNode, WOS } from "@/app/store/global"; +import { + atoms, + createBlock, + getActiveBlockComponentModel, + getApi, + globalStore, + refocusNode, + WOS, +} from "@/app/store/global"; import * as services from "@/app/store/services"; import { deleteLayoutModelForTab, @@ -163,11 +171,8 @@ function appHandleKeyDown(waveEvent: WaveKeyboardEvent): boolean { if (handled) { return true; } - const layoutModel = getLayoutModelForActiveTab(); - const focusedNode = globalStore.get(layoutModel.focusedNode); - const blockId = focusedNode?.data?.blockId; - if (blockId != null && shouldDispatchToBlock(waveEvent)) { - const bcm = getBlockComponentModel(blockId); + if (shouldDispatchToBlock(waveEvent)) { + const bcm = getActiveBlockComponentModel(); const viewModel = bcm?.viewModel; if (viewModel?.keyDownHandler) { const handledByBlock = viewModel.keyDownHandler(waveEvent); @@ -264,12 +269,33 @@ function registerGlobalKeys() { return true; }); globalKeyMap.set("Cmd:g", () => { - const bcm = getBlockComponentModel(getFocusedBlockInActiveTab()); + const bcm = getActiveBlockComponentModel(); if (bcm.openSwitchConnection != null) { bcm.openSwitchConnection(); return true; } }); + const onBrowserBack = () => { + console.log("onBrowserBack"); + const bcm = getActiveBlockComponentModel(); + const onBack = bcm?.viewModel?.onBack; + if (onBack != null) { + onBack(); + return true; + } + }; + globalKeyMap.set("BrowserBack", onBrowserBack); + globalKeyMap.set("GoBack", onBrowserBack); + const onBrowserForward = () => { + console.log("onBrowserForward"); + const bcm = getActiveBlockComponentModel(); + const onForward = bcm?.viewModel?.onForward; + + onForward(); + return true; + } + }; + globalKeyMap.set("BrowserForward", onBrowserForward); for (let idx = 1; idx <= 9; idx++) { globalKeyMap.set(`Cmd:${idx}`, () => { switchTabAbs(idx); diff --git a/frontend/app/view/preview/directorypreview.tsx b/frontend/app/view/preview/directorypreview.tsx index d8afe804d..196d03ce3 100644 --- a/frontend/app/view/preview/directorypreview.tsx +++ b/frontend/app/view/preview/directorypreview.tsx @@ -477,7 +477,10 @@ function TableBody({ model.goHistory(newFileName); setSearch(""); }} - onClick={() => setFocusIndex(idx)} + onClick={(e) => { + setFocusIndex(idx); + console.log("onclick", e.nativeEvent); + }} onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path"), row.getValue("mimetype"))} > {row.getVisibleCells().map((cell) => ( diff --git a/frontend/wave.ts b/frontend/wave.ts index d94bf14b7..4e0de3534 100644 --- a/frontend/wave.ts +++ b/frontend/wave.ts @@ -23,6 +23,7 @@ import { initGlobalWaveEventSubs, loadConnStatus, pushFlashError, + subscribeToBrowserEvents, subscribeToConnEvents, } from "@/store/global"; import * as WOS from "@/store/wos"; @@ -67,6 +68,7 @@ document.addEventListener("DOMContentLoaded", async () => { await loadConnStatus(); initGlobalWaveEventSubs(); subscribeToConnEvents(); + subscribeToBrowserEvents(); // ensures client/window/workspace are loaded into the cache before rendering const client = await WOS.loadAndPinWaveObject(WOS.makeORef("client", clientId));