Add esc keybinding to all modals, add update button in About modal (#514)

* Add esc keybinding to all modals, add update button in About modal

* move import
This commit is contained in:
Evan Simkowitz 2024-03-27 15:35:14 -07:00 committed by GitHub
parent 4eb215b99d
commit abe6d6a6ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 59 deletions

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import * as React from "react"; import * as React from "react";
import * as mobx from "mobx";
import { If } from "tsx-control-statements/components"; import { If } from "tsx-control-statements/components";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { Button } from "./button"; import { Button } from "./button";
@ -14,11 +13,15 @@ import { boundMethod } from "autobind-decorator";
interface ModalHeaderProps { interface ModalHeaderProps {
onClose?: () => void; onClose?: () => void;
keybindings?: boolean;
title: string; title: string;
} }
const ModalHeader: React.FC<ModalHeaderProps> = ({ onClose, title }) => ( const ModalHeader: React.FC<ModalHeaderProps> = ({ onClose, keybindings = true, title }) => (
<div className="wave-modal-header"> <div className="wave-modal-header">
<If condition={keybindings && onClose}>
<ModalKeybindings onCancel={onClose}></ModalKeybindings>
</If>
{<div className="wave-modal-title">{title}</div>} {<div className="wave-modal-title">{title}</div>}
<If condition={onClose}> <If condition={onClose}>
<Button className="secondary ghost" onClick={onClose}> <Button className="secondary ghost" onClick={onClose}>
@ -36,23 +39,27 @@ interface ModalFooterProps {
keybindings?: boolean; keybindings?: boolean;
} }
class ModalKeybindings extends React.Component<{ onOk; onCancel }, {}> { class ModalKeybindings extends React.Component<{ onOk?: () => void; onCancel?: () => void }, {}> {
curId: string; curId: string;
@boundMethod @boundMethod
componentDidMount(): void { componentDidMount(): void {
this.curId = uuidv4(); this.curId = uuidv4();
let domain = "modal-" + this.curId; const domain = "modal-" + this.curId;
let keybindManager = GlobalModel.keybindManager; const keybindManager = GlobalModel.keybindManager;
if (this.props.onOk) { if (this.props.onOk) {
keybindManager.registerKeybinding("modal", domain, "generic:confirm", (waveEvent) => { keybindManager.registerKeybinding("modal", domain, "generic:confirm", (waveEvent) => {
if (this.props.onOk) {
this.props.onOk(); this.props.onOk();
}
return true; return true;
}); });
} }
if (this.props.onCancel) { if (this.props.onCancel) {
keybindManager.registerKeybinding("modal", domain, "generic:cancel", (waveEvent) => { keybindManager.registerKeybinding("modal", domain, "generic:cancel", (waveEvent) => {
if (this.props.onCancel) {
this.props.onCancel(); this.props.onCancel();
}
return true; return true;
}); });
} }

View File

@ -63,18 +63,6 @@
} }
} }
.status.updated {
div {
display: flex;
align-items: center;
margin-bottom: 5px;
i {
color: var(--app-success-color);
}
}
}
.status.outdated { .status.outdated {
div { div {
i { i {

View File

@ -5,10 +5,12 @@ import * as React from "react";
import * as mobxReact from "mobx-react"; import * as mobxReact from "mobx-react";
import * as mobx from "mobx"; import * as mobx from "mobx";
import { boundMethod } from "autobind-decorator"; import { boundMethod } from "autobind-decorator";
import { GlobalModel } from "@/models"; import { GlobalModel, getApi } from "@/models";
import { Modal, LinkButton } from "@/elements"; import { Modal, LinkButton } from "@/elements";
import * as util from "@/util/util"; import * as util from "@/util/util";
import * as appconst from "@/app/appconst"; import * as appconst from "@/app/appconst";
import cn from "classnames";
import { If } from "tsx-control-statements/components";
import logo from "@/assets/waveterm-logo-with-bg.svg"; import logo from "@/assets/waveterm-logo-with-bg.svg";
import "./about.less"; import "./about.less";
@ -22,54 +24,35 @@ class AboutModal extends React.Component<{}, {}> {
})(); })();
} }
@boundMethod
isUpToDate(): boolean {
return true;
}
@boundMethod @boundMethod
updateApp(): void { updateApp(): void {
// GlobalCommandRunner.updateApp(); getApi().installAppUpdate();
} }
@boundMethod @boundMethod
getStatus(isUpToDate: boolean): JSX.Element { getClientVersion(): JSX.Element {
// TODO no up-to-date status reporting const clientData: ClientDataType = GlobalModel.clientData.get();
return ( const showUpdateStatus = clientData.clientopts.noreleasecheck !== true;
<div className="status updated"> const isUpToDate = !showUpdateStatus || GlobalModel.appUpdateStatus.get() !== "ready";
<div className="text-selectable">
Client Version {appconst.VERSION} ({appconst.BUILD})
</div>
</div>
);
if (isUpToDate) {
return ( return (
<div className="status updated"> <div className={cn("status", { outdated: !isUpToDate })}>
<div> <If condition={!isUpToDate}>
<i className="fa-sharp fa-solid fa-circle-check" />
<span>Up to Date</span>
</div>
<div className="selectable">
Client Version {appconst.VERSION} ({appconst.BUILD})
</div>
</div>
);
}
return (
<div className="status outdated">
<div> <div>
<i className="fa-sharp fa-solid fa-triangle-exclamation" /> <i className="fa-sharp fa-solid fa-triangle-exclamation" />
<span>Outdated Version</span> <span>Outdated Version</span>
</div> </div>
</If>
<div className="selectable"> <div className="selectable">
Client Version {appconst.VERSION} ({appconst.BUILD}) Client Version {appconst.VERSION} ({appconst.BUILD})
</div> </div>
<If condition={!isUpToDate}>
<div> <div>
<button onClick={this.updateApp} className="button color-green text-secondary"> <button onClick={this.updateApp} className="button color-green text-secondary">
Update Restart to Update
</button> </button>
</div> </div>
</If>
</div> </div>
); );
} }
@ -93,7 +76,7 @@ class AboutModal extends React.Component<{}, {}> {
</div> </div>
</div> </div>
</div> </div>
<div className="about-section text-standard">{this.getStatus(this.isUpToDate())}</div> <div className="about-section text-standard">{this.getClientVersion()}</div>
<div className="about-section"> <div className="about-section">
<LinkButton <LinkButton
className="secondary solid" className="secondary solid"