close modals on ECS

This commit is contained in:
Red Adaya 2024-03-12 09:31:35 +08:00
parent f850e3b728
commit 4c33d24a7b
7 changed files with 32 additions and 8 deletions

View File

@ -44,7 +44,7 @@ class AlertModal extends React.Component<{}, {}> {
<Markdown text={message?.message ?? ""} extraClassName="bottom-margin" /> <Markdown text={message?.message ?? ""} extraClassName="bottom-margin" />
</If> </If>
<If condition={!message?.markdown}>{message?.message}</If> <If condition={!message?.markdown}>{message?.message}</If>
<If condition={message.confirmflag}> <If condition={message?.confirmflag}>
<Checkbox <Checkbox
onChange={this.handleDontShowAgain} onChange={this.handleDontShowAgain}
label={"Don't show me this again"} label={"Don't show me this again"}

View File

@ -206,7 +206,7 @@ class BookmarksModel {
} }
handleDocKeyDown(e: any): void { handleDocKeyDown(e: any): void {
let waveEvent = adaptFromReactOrNativeKeyEvent(e); const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) { if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault(); e.preventDefault();
if (this.editingBookmark.get() != null) { if (this.editingBookmark.get() != null) {

View File

@ -3,6 +3,7 @@
import * as mobx from "mobx"; import * as mobx from "mobx";
import { Model } from "./model"; import { Model } from "./model";
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "@/util/keyutil";
class ClientSettingsViewModel { class ClientSettingsViewModel {
globalModel: Model; globalModel: Model;
@ -21,6 +22,15 @@ class ClientSettingsViewModel {
this.globalModel.activeMainView.set("clientsettings"); this.globalModel.activeMainView.set("clientsettings");
})(); })();
} }
handleDocKeyDown(e: any): void {
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
this.closeView();
return;
}
}
} }
export { ClientSettingsViewModel }; export { ClientSettingsViewModel };

View File

@ -3,6 +3,7 @@
import * as mobx from "mobx"; import * as mobx from "mobx";
import { Model } from "./model"; import { Model } from "./model";
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "@/util/keyutil";
class ConnectionsViewModel { class ConnectionsViewModel {
globalModel: Model; globalModel: Model;
@ -21,6 +22,15 @@ class ConnectionsViewModel {
this.globalModel.activeMainView.set("connections"); this.globalModel.activeMainView.set("connections");
})(); })();
} }
handleDocKeyDown(e: any): void {
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
this.closeView();
return;
}
}
} }
export { ConnectionsViewModel }; export { ConnectionsViewModel };

View File

@ -291,7 +291,7 @@ class HistoryViewModel {
} }
handleDocKeyDown(e: any): void { handleDocKeyDown(e: any): void {
let waveEvent = adaptFromReactOrNativeKeyEvent(e); const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) { if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault(); e.preventDefault();
this.closeView(); this.closeView();

View File

@ -18,10 +18,11 @@ class ModalsModel {
} }
} }
popModal() { popModal(callback?: () => void) {
mobx.action(() => { mobx.action(() => {
this.store.pop(); this.store.pop();
})(); })();
callback && callback();
} }
} }

View File

@ -457,7 +457,7 @@ class Model {
if (this.alertMessage.get() != null) { if (this.alertMessage.get() != null) {
if (checkKeyPressed(waveEvent, "Escape")) { if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault(); e.preventDefault();
this.cancelAlert(); this.modalsModel.popModal(() => this.cancelAlert());
return; return;
} }
if (checkKeyPressed(waveEvent, "Enter")) { if (checkKeyPressed(waveEvent, "Enter")) {
@ -467,6 +467,10 @@ class Model {
} }
return; return;
} }
if (checkKeyPressed(waveEvent, "Escape") && this.modalsModel.store.length > 0) {
this.modalsModel.popModal();
return;
}
if (this.activeMainView.get() == "bookmarks") { if (this.activeMainView.get() == "bookmarks") {
this.bookmarksModel.handleDocKeyDown(e); this.bookmarksModel.handleDocKeyDown(e);
return; return;
@ -476,14 +480,13 @@ class Model {
return; return;
} }
if (this.activeMainView.get() == "connections") { if (this.activeMainView.get() == "connections") {
this.historyViewModel.handleDocKeyDown(e); this.connectionViewModel.handleDocKeyDown(e);
return; return;
} }
if (this.activeMainView.get() == "clientsettings") { if (this.activeMainView.get() == "clientsettings") {
this.historyViewModel.handleDocKeyDown(e); this.clientSettingsViewModel.handleDocKeyDown(e);
return; return;
} }
if (checkKeyPressed(waveEvent, "Escape")) { if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault(); e.preventDefault();
if (this.activeMainView.get() == "webshare") { if (this.activeMainView.get() == "webshare") {