connstatus fix, update connection icons appropriately for status

This commit is contained in:
sawka 2024-08-30 13:56:53 -07:00
parent ef95fd20ed
commit 74f551b212
8 changed files with 42 additions and 13 deletions

View File

@ -157,13 +157,14 @@ export const ConnectionButton = React.memo(
const isLocal = util.isBlank(connection) || connection == "local"; const isLocal = util.isBlank(connection) || connection == "local";
const connStatusAtom = getConnStatusAtom(connection); const connStatusAtom = getConnStatusAtom(connection);
const connStatus = jotai.useAtomValue(connStatusAtom); const connStatus = jotai.useAtomValue(connStatusAtom);
const showDisconnectedSlash = !isLocal && !connStatus?.connected; let showDisconnectedSlash = false;
let connIconElem: React.ReactNode = null; let connIconElem: React.ReactNode = null;
let color = "#53b4ea"; let color = "#53b4ea";
const clickHandler = function () { const clickHandler = function () {
setConnModalOpen(true); setConnModalOpen(true);
}; };
let titleText = null; let titleText = null;
let shouldSpin = false;
if (isLocal) { if (isLocal) {
color = "var(--grey-text-color)"; color = "var(--grey-text-color)";
titleText = "Connected to Local Machine"; titleText = "Connected to Local Machine";
@ -175,13 +176,27 @@ export const ConnectionButton = React.memo(
); );
} else { } else {
titleText = "Connected to " + connection; 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)"; color = "var(--grey-text-color)";
titleText = "Disconnected from " + connection; titleText = "Disconnected from " + connection;
showDisconnectedSlash = true;
} }
connIconElem = ( connIconElem = (
<i <i
className={clsx(util.makeIconClass("arrow-right-arrow-left", false), "fa-stack-1x")} className={clsx(util.makeIconClass(iconName, false), "fa-stack-1x")}
style={{ color: color, marginRight: 2 }} style={{ color: color, marginRight: 2 }}
/> />
); );
@ -189,7 +204,7 @@ export const ConnectionButton = React.memo(
return ( return (
<div ref={ref} className={clsx("connection-button")} onClick={clickHandler} title={titleText}> <div ref={ref} className={clsx("connection-button")} onClick={clickHandler} title={titleText}>
<span className="fa-stack connection-icon-box"> <span className={clsx("fa-stack connection-icon-box", shouldSpin ? "fa-spin" : null)}>
{connIconElem} {connIconElem}
<i <i
className="fa-slash fa-solid fa-stack-1x" className="fa-slash fa-solid fa-stack-1x"

View File

@ -568,12 +568,17 @@ async function loadConnStatus() {
function subscribeToConnEvents() { function subscribeToConnEvents() {
waveEventSubscribe("connchange", null, (event: WaveEvent) => { waveEventSubscribe("connchange", null, (event: WaveEvent) => {
try {
const connStatus = event.data as ConnStatus; const connStatus = event.data as ConnStatus;
if (connStatus == null || util.isBlank(connStatus.connection)) { if (connStatus == null || util.isBlank(connStatus.connection)) {
console.log("connchange2 early return");
return; return;
} }
let curAtom = ConnStatusMap.get(connStatus.connection); let curAtom = getConnStatusAtom(connStatus.connection);
globalStore.set(curAtom, connStatus); globalStore.set(curAtom, connStatus);
} catch (e) {
console.log("connchange error", e);
}
}); });
} }

View File

@ -47,6 +47,7 @@ export class PreviewModel implements ViewModel {
ceReadOnly: jotai.PrimitiveAtom<boolean>; ceReadOnly: jotai.PrimitiveAtom<boolean>;
isCeView: jotai.PrimitiveAtom<boolean>; isCeView: jotai.PrimitiveAtom<boolean>;
previewTextRef: React.RefObject<HTMLDivElement>; previewTextRef: React.RefObject<HTMLDivElement>;
editMode: jotai.Atom<boolean>;
fileName: jotai.Atom<string>; fileName: jotai.Atom<string>;
connection: jotai.Atom<string>; connection: jotai.Atom<string>;
@ -114,6 +115,10 @@ export class PreviewModel implements ViewModel {
const fileName = get(this.fileName); const fileName = get(this.fileName);
return iconForFile(mimeType, 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.viewName = jotai.atom("Preview");
this.viewText = jotai.atom((get) => { this.viewText = jotai.atom((get) => {
if (get(this.isCeView)) { if (get(this.isCeView)) {

View File

@ -237,6 +237,7 @@ declare global {
file?: string; file?: string;
url?: string; url?: string;
connection?: string; connection?: string;
edit?: boolean;
history?: string[]; history?: string[];
"history:forward"?: string[]; "history:forward"?: string[];
"display:name"?: string; "display:name"?: string;

View File

@ -81,19 +81,19 @@ function jsonDeepEqual(v1: any, v2: any): boolean {
return false; return false;
} }
function makeIconClass(icon: string, fw: boolean): string { function makeIconClass(icon: string, fw: boolean, opts?: { spin: boolean }): string {
if (icon == null) { if (icon == null) {
return null; return null;
} }
if (icon.match(/^(solid@)?[a-z0-9-]+$/)) { if (icon.match(/^(solid@)?[a-z0-9-]+$/)) {
// strip off "solid@" prefix if it exists // strip off "solid@" prefix if it exists
icon = icon.replace(/^solid@/, ""); 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-]+$/)) { if (icon.match(/^regular@[a-z0-9-]+$/)) {
// strip off the "regular@" prefix if it exists // strip off the "regular@" prefix if it exists
icon = icon.replace(/^regular@/, ""); 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; return null;
} }

View File

@ -84,7 +84,7 @@ func (conn *SSHConn) FireConnChangeEvent() {
}, },
Data: status, Data: status,
} }
log.Printf("sending event: %+#v", event) log.Printf("connstatus change %q => %s\n", conn.GetName(), status.Status)
wps.Broker.Publish(event) wps.Broker.Publish(event)
} }

View File

@ -18,6 +18,8 @@ const (
MetaKey_Connection = "connection" MetaKey_Connection = "connection"
MetaKey_Edit = "edit"
MetaKey_History = "history" MetaKey_History = "history"
MetaKey_HistoryForward = "history:forward" MetaKey_HistoryForward = "history:forward"

View File

@ -18,6 +18,7 @@ type MetaTSType struct {
File string `json:"file,omitempty"` File string `json:"file,omitempty"`
Url string `json:"url,omitempty"` Url string `json:"url,omitempty"`
Connection string `json:"connection,omitempty"` Connection string `json:"connection,omitempty"`
Edit bool `json:"edit,omitempty"`
History []string `json:"history,omitempty"` History []string `json:"history,omitempty"`
HistoryForward []string `json:"history:forward,omitempty"` HistoryForward []string `json:"history:forward,omitempty"`