mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
implement back/forward for help view (#991)
This commit is contained in:
parent
b8e03e9628
commit
5d6b85cf54
@ -4,33 +4,41 @@
|
|||||||
import { getApi } from "@/app/store/global";
|
import { getApi } from "@/app/store/global";
|
||||||
import { WebView, WebViewModel } from "@/app/view/webview/webview";
|
import { WebView, WebViewModel } from "@/app/view/webview/webview";
|
||||||
import { NodeModel } from "@/layout/index";
|
import { NodeModel } from "@/layout/index";
|
||||||
import { WebviewTag } from "electron";
|
|
||||||
import { atom } from "jotai";
|
import { atom } from "jotai";
|
||||||
import { createRef } from "react";
|
|
||||||
import "./helpview.less";
|
import "./helpview.less";
|
||||||
|
|
||||||
class HelpViewModel extends WebViewModel {
|
class HelpViewModel extends WebViewModel {
|
||||||
viewType: string;
|
|
||||||
blockId: string;
|
|
||||||
webviewRef: React.RefObject<WebviewTag>;
|
|
||||||
|
|
||||||
constructor(blockId: string, nodeModel: NodeModel) {
|
constructor(blockId: string, nodeModel: NodeModel) {
|
||||||
super(blockId, nodeModel);
|
super(blockId, nodeModel);
|
||||||
this.getSettingsMenuItems = undefined;
|
this.getSettingsMenuItems = undefined;
|
||||||
this.viewText = atom([
|
this.viewText = atom((get) => {
|
||||||
|
// force a dependency on meta.url so we re-render the buttons when the url changes
|
||||||
|
let url = get(this.blockAtom)?.meta?.url || get(this.homepageUrl);
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
elemtype: "iconbutton",
|
||||||
|
icon: "chevron-left",
|
||||||
|
click: this.handleBack.bind(this),
|
||||||
|
disabled: this.shouldDisableBackButton(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
elemtype: "iconbutton",
|
||||||
|
icon: "chevron-right",
|
||||||
|
click: this.handleForward.bind(this),
|
||||||
|
disabled: this.shouldDisableForwardButton(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
elemtype: "iconbutton",
|
elemtype: "iconbutton",
|
||||||
icon: "house",
|
icon: "house",
|
||||||
click: this.handleHome.bind(this),
|
click: this.handleHome.bind(this),
|
||||||
disabled: this.shouldDisabledHomeButton(),
|
disabled: this.shouldDisableHomeButton(),
|
||||||
},
|
},
|
||||||
]);
|
];
|
||||||
|
});
|
||||||
this.homepageUrl = atom(getApi().getDocsiteUrl());
|
this.homepageUrl = atom(getApi().getDocsiteUrl());
|
||||||
this.viewType = "help";
|
this.viewType = "help";
|
||||||
this.blockId = blockId;
|
|
||||||
this.viewIcon = atom("circle-question");
|
this.viewIcon = atom("circle-question");
|
||||||
this.viewName = atom("Help");
|
this.viewName = atom("Help");
|
||||||
this.webviewRef = createRef<WebviewTag>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,19 +81,19 @@ export class WebViewModel implements ViewModel {
|
|||||||
elemtype: "iconbutton",
|
elemtype: "iconbutton",
|
||||||
icon: "chevron-left",
|
icon: "chevron-left",
|
||||||
click: this.handleBack.bind(this),
|
click: this.handleBack.bind(this),
|
||||||
disabled: this.shouldDisabledBackButton(),
|
disabled: this.shouldDisableBackButton(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
elemtype: "iconbutton",
|
elemtype: "iconbutton",
|
||||||
icon: "chevron-right",
|
icon: "chevron-right",
|
||||||
click: this.handleForward.bind(this),
|
click: this.handleForward.bind(this),
|
||||||
disabled: this.shouldDisabledForwardButton(),
|
disabled: this.shouldDisableForwardButton(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
elemtype: "iconbutton",
|
elemtype: "iconbutton",
|
||||||
icon: "house",
|
icon: "house",
|
||||||
click: this.handleHome.bind(this),
|
click: this.handleHome.bind(this),
|
||||||
disabled: this.shouldDisabledHomeButton(),
|
disabled: this.shouldDisableHomeButton(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
elemtype: "div",
|
elemtype: "div",
|
||||||
@ -142,7 +142,7 @@ export class WebViewModel implements ViewModel {
|
|||||||
* Whether the back button in the header should be disabled.
|
* Whether the back button in the header should be disabled.
|
||||||
* @returns True if the WebView cannot go back or if the WebView call fails. False otherwise.
|
* @returns True if the WebView cannot go back or if the WebView call fails. False otherwise.
|
||||||
*/
|
*/
|
||||||
shouldDisabledBackButton() {
|
shouldDisableBackButton() {
|
||||||
try {
|
try {
|
||||||
return !this.webviewRef.current?.canGoBack();
|
return !this.webviewRef.current?.canGoBack();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
@ -153,7 +153,7 @@ export class WebViewModel implements ViewModel {
|
|||||||
* Whether the forward button in the header should be disabled.
|
* Whether the forward button in the header should be disabled.
|
||||||
* @returns True if the WebView cannot go forward or if the WebView call fails. False otherwise.
|
* @returns True if the WebView cannot go forward or if the WebView call fails. False otherwise.
|
||||||
*/
|
*/
|
||||||
shouldDisabledForwardButton() {
|
shouldDisableForwardButton() {
|
||||||
try {
|
try {
|
||||||
return !this.webviewRef.current?.canGoForward();
|
return !this.webviewRef.current?.canGoForward();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
@ -164,7 +164,7 @@ export class WebViewModel implements ViewModel {
|
|||||||
* Whether the home button in the header should be disabled.
|
* Whether the home button in the header should be disabled.
|
||||||
* @returns True if the current url is the pinned url or the pinned url is not set. False otherwise.
|
* @returns True if the current url is the pinned url or the pinned url is not set. False otherwise.
|
||||||
*/
|
*/
|
||||||
shouldDisabledHomeButton() {
|
shouldDisableHomeButton() {
|
||||||
try {
|
try {
|
||||||
const homepageUrl = globalStore.get(this.homepageUrl);
|
const homepageUrl = globalStore.get(this.homepageUrl);
|
||||||
return !homepageUrl || this.getUrl() === homepageUrl;
|
return !homepageUrl || this.getUrl() === homepageUrl;
|
||||||
|
Loading…
Reference in New Issue
Block a user