From 74f551b212a9ee3bcda1f98b92437e53e0d6a11c Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 30 Aug 2024 13:56:53 -0700 Subject: [PATCH] connstatus fix, update connection icons appropriately for status --- frontend/app/block/blockutil.tsx | 23 +++++++++++++++++---- frontend/app/store/global.ts | 15 +++++++++----- frontend/app/view/preview/preview.tsx | 5 +++++ frontend/types/gotypes.d.ts | 1 + frontend/util/util.ts | 6 +++--- pkg/remote/conncontroller/conncontroller.go | 2 +- pkg/waveobj/metaconsts.go | 2 ++ pkg/waveobj/wtypemeta.go | 1 + 8 files changed, 42 insertions(+), 13 deletions(-) diff --git a/frontend/app/block/blockutil.tsx b/frontend/app/block/blockutil.tsx index cef13f163..57e31f8a0 100644 --- a/frontend/app/block/blockutil.tsx +++ b/frontend/app/block/blockutil.tsx @@ -157,13 +157,14 @@ export const ConnectionButton = React.memo( const isLocal = util.isBlank(connection) || connection == "local"; const connStatusAtom = getConnStatusAtom(connection); const connStatus = jotai.useAtomValue(connStatusAtom); - const showDisconnectedSlash = !isLocal && !connStatus?.connected; + let showDisconnectedSlash = false; let connIconElem: React.ReactNode = null; let color = "#53b4ea"; const clickHandler = function () { setConnModalOpen(true); }; let titleText = null; + let shouldSpin = false; if (isLocal) { color = "var(--grey-text-color)"; titleText = "Connected to Local Machine"; @@ -175,13 +176,27 @@ export const ConnectionButton = React.memo( ); } else { titleText = "Connected to " + connection; - if (!connStatus?.connected) { + let iconName = "arrow-right-arrow-left"; + if (connStatus?.status == "connecting") { + color = "var(--warning-color)"; + titleText = "Connecting to " + connection; + iconName = "rotate"; + shouldSpin = true; + } else if (connStatus?.status == "error") { + color = "var(--error-color)"; + titleText = "Error connecting to " + connection; + if (connStatus?.error != null) { + titleText += " (" + connStatus.error + ")"; + } + showDisconnectedSlash = true; + } else if (!connStatus?.connected) { color = "var(--grey-text-color)"; titleText = "Disconnected from " + connection; + showDisconnectedSlash = true; } connIconElem = ( ); @@ -189,7 +204,7 @@ export const ConnectionButton = React.memo( return (
- + {connIconElem} { - const connStatus = event.data as ConnStatus; - if (connStatus == null || util.isBlank(connStatus.connection)) { - return; + try { + const connStatus = event.data as ConnStatus; + if (connStatus == null || util.isBlank(connStatus.connection)) { + console.log("connchange2 early return"); + return; + } + let curAtom = getConnStatusAtom(connStatus.connection); + globalStore.set(curAtom, connStatus); + } catch (e) { + console.log("connchange error", e); } - let curAtom = ConnStatusMap.get(connStatus.connection); - globalStore.set(curAtom, connStatus); }); } diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index e4fb9ef7f..c95b8c449 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -47,6 +47,7 @@ export class PreviewModel implements ViewModel { ceReadOnly: jotai.PrimitiveAtom; isCeView: jotai.PrimitiveAtom; previewTextRef: React.RefObject; + editMode: jotai.Atom; fileName: jotai.Atom; connection: jotai.Atom; @@ -114,6 +115,10 @@ export class PreviewModel implements ViewModel { const fileName = get(this.fileName); return iconForFile(mimeType, fileName); }); + this.editMode = jotai.atom((get) => { + const blockData = get(this.blockAtom); + return blockData?.meta?.edit ?? false; + }); this.viewName = jotai.atom("Preview"); this.viewText = jotai.atom((get) => { if (get(this.isCeView)) { diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index d1091facb..c544c9443 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -237,6 +237,7 @@ declare global { file?: string; url?: string; connection?: string; + edit?: boolean; history?: string[]; "history:forward"?: string[]; "display:name"?: string; diff --git a/frontend/util/util.ts b/frontend/util/util.ts index 994f3ed82..36735dcc9 100644 --- a/frontend/util/util.ts +++ b/frontend/util/util.ts @@ -81,19 +81,19 @@ function jsonDeepEqual(v1: any, v2: any): boolean { return false; } -function makeIconClass(icon: string, fw: boolean): string { +function makeIconClass(icon: string, fw: boolean, opts?: { spin: boolean }): string { if (icon == null) { return null; } if (icon.match(/^(solid@)?[a-z0-9-]+$/)) { // strip off "solid@" prefix if it exists icon = icon.replace(/^solid@/, ""); - return clsx(`fa fa-sharp fa-solid fa-${icon}`, fw ? "fa-fw" : null); + return clsx(`fa fa-sharp fa-solid fa-${icon}`, fw ? "fa-fw" : null, opts?.spin ? "fa-spin" : null); } if (icon.match(/^regular@[a-z0-9-]+$/)) { // strip off the "regular@" prefix if it exists icon = icon.replace(/^regular@/, ""); - return clsx(`fa fa-sharp fa-regular fa-${icon}`, fw ? "fa-fw" : null); + return clsx(`fa fa-sharp fa-regular fa-${icon}`, fw ? "fa-fw" : null, opts?.spin ? "fa-spin" : null); } return null; } diff --git a/pkg/remote/conncontroller/conncontroller.go b/pkg/remote/conncontroller/conncontroller.go index d29957c8b..ab2685999 100644 --- a/pkg/remote/conncontroller/conncontroller.go +++ b/pkg/remote/conncontroller/conncontroller.go @@ -84,7 +84,7 @@ func (conn *SSHConn) FireConnChangeEvent() { }, Data: status, } - log.Printf("sending event: %+#v", event) + log.Printf("connstatus change %q => %s\n", conn.GetName(), status.Status) wps.Broker.Publish(event) } diff --git a/pkg/waveobj/metaconsts.go b/pkg/waveobj/metaconsts.go index 7cfd72429..d6d18f468 100644 --- a/pkg/waveobj/metaconsts.go +++ b/pkg/waveobj/metaconsts.go @@ -18,6 +18,8 @@ const ( MetaKey_Connection = "connection" + MetaKey_Edit = "edit" + MetaKey_History = "history" MetaKey_HistoryForward = "history:forward" diff --git a/pkg/waveobj/wtypemeta.go b/pkg/waveobj/wtypemeta.go index cfd52e9e1..d964c2062 100644 --- a/pkg/waveobj/wtypemeta.go +++ b/pkg/waveobj/wtypemeta.go @@ -18,6 +18,7 @@ type MetaTSType struct { File string `json:"file,omitempty"` Url string `json:"url,omitempty"` Connection string `json:"connection,omitempty"` + Edit bool `json:"edit,omitempty"` History []string `json:"history,omitempty"` HistoryForward []string `json:"history:forward,omitempty"`