2024-08-01 07:22:52 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-10-04 05:28:05 +02:00
|
|
|
import { getApi } from "@/app/store/global";
|
2024-10-08 02:20:18 +02:00
|
|
|
import { WebView, WebViewModel } from "@/app/view/webview/webview";
|
|
|
|
import { NodeModel } from "@/layout/index";
|
2024-10-09 21:42:33 +02:00
|
|
|
import { fireAndForget } from "@/util/util";
|
|
|
|
import { atom, useAtomValue } from "jotai";
|
|
|
|
import { useEffect } from "react";
|
2024-08-01 07:22:52 +02:00
|
|
|
import "./helpview.less";
|
|
|
|
|
2024-10-08 02:20:18 +02:00
|
|
|
class HelpViewModel extends WebViewModel {
|
|
|
|
constructor(blockId: string, nodeModel: NodeModel) {
|
|
|
|
super(blockId, nodeModel);
|
|
|
|
this.getSettingsMenuItems = undefined;
|
2024-10-09 01:54:41 +02:00
|
|
|
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(),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|
2024-10-08 02:20:18 +02:00
|
|
|
this.homepageUrl = atom(getApi().getDocsiteUrl());
|
2024-09-05 06:15:39 +02:00
|
|
|
this.viewType = "help";
|
2024-10-08 02:20:18 +02:00
|
|
|
this.viewIcon = atom("circle-question");
|
|
|
|
this.viewName = atom("Help");
|
2024-09-05 06:15:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-08 02:20:18 +02:00
|
|
|
function makeHelpViewModel(blockId: string, nodeModel: NodeModel) {
|
|
|
|
return new HelpViewModel(blockId, nodeModel);
|
2024-09-05 06:15:39 +02:00
|
|
|
}
|
|
|
|
|
2024-10-06 22:55:26 +02:00
|
|
|
function HelpView({ model }: { model: HelpViewModel }) {
|
2024-10-09 21:42:33 +02:00
|
|
|
const homepageUrl = useAtomValue(model.homepageUrl);
|
|
|
|
useEffect(
|
|
|
|
() =>
|
|
|
|
fireAndForget(async () => {
|
|
|
|
const curDocsiteUrl = getApi().getDocsiteUrl();
|
|
|
|
if (curDocsiteUrl !== homepageUrl) {
|
|
|
|
await model.setHomepageUrl(curDocsiteUrl, "block");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
[]
|
|
|
|
);
|
2024-10-04 05:28:05 +02:00
|
|
|
return (
|
|
|
|
<div className="help-view">
|
2024-10-08 02:20:18 +02:00
|
|
|
<WebView blockId={model.blockId} model={model} />
|
2024-10-04 05:28:05 +02:00
|
|
|
</div>
|
|
|
|
);
|
2024-08-01 07:22:52 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 06:15:39 +02:00
|
|
|
export { HelpView, HelpViewModel, makeHelpViewModel };
|