Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

implement back/forward for help view #991

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions frontend/app/view/helpview/helpview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@
import { getApi } from "@/app/store/global";
import { WebView, WebViewModel } from "@/app/view/webview/webview";
import { NodeModel } from "@/layout/index";
import { WebviewTag } from "electron";
import { atom } from "jotai";
import { createRef } from "react";
import "./helpview.less";

class HelpViewModel extends WebViewModel {
viewType: string;
blockId: string;
webviewRef: React.RefObject<WebviewTag>;

constructor(blockId: string, nodeModel: NodeModel) {
super(blockId, nodeModel);
this.getSettingsMenuItems = undefined;
this.viewText = atom([
{
elemtype: "iconbutton",
icon: "house",
click: this.handleHome.bind(this),
disabled: this.shouldDisabledHomeButton(),
},
]);
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",
icon: "house",
click: this.handleHome.bind(this),
disabled: this.shouldDisableHomeButton(),
},
];
});
this.homepageUrl = atom(getApi().getDocsiteUrl());
this.viewType = "help";
this.blockId = blockId;
this.viewIcon = atom("circle-question");
this.viewName = atom("Help");
this.webviewRef = createRef<WebviewTag>();
}
}

Expand Down
12 changes: 6 additions & 6 deletions frontend/app/view/webview/webview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ export class WebViewModel implements ViewModel {
elemtype: "iconbutton",
icon: "chevron-left",
click: this.handleBack.bind(this),
disabled: this.shouldDisabledBackButton(),
disabled: this.shouldDisableBackButton(),
},
{
elemtype: "iconbutton",
icon: "chevron-right",
click: this.handleForward.bind(this),
disabled: this.shouldDisabledForwardButton(),
disabled: this.shouldDisableForwardButton(),
},
{
elemtype: "iconbutton",
icon: "house",
click: this.handleHome.bind(this),
disabled: this.shouldDisabledHomeButton(),
disabled: this.shouldDisableHomeButton(),
},
{
elemtype: "div",
Expand Down Expand Up @@ -142,7 +142,7 @@ export class WebViewModel implements ViewModel {
* 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.
*/
shouldDisabledBackButton() {
shouldDisableBackButton() {
try {
return !this.webviewRef.current?.canGoBack();
} catch (_) {}
Expand All @@ -153,7 +153,7 @@ export class WebViewModel implements ViewModel {
* 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.
*/
shouldDisabledForwardButton() {
shouldDisableForwardButton() {
try {
return !this.webviewRef.current?.canGoForward();
} catch (_) {}
Expand All @@ -164,7 +164,7 @@ export class WebViewModel implements ViewModel {
* 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.
*/
shouldDisabledHomeButton() {
shouldDisableHomeButton() {
try {
const homepageUrl = globalStore.get(this.homepageUrl);
return !homepageUrl || this.getUrl() === homepageUrl;
Expand Down