diff --git a/apps/client/src/widgets/dialogs/about.tsx b/apps/client/src/widgets/dialogs/about.tsx index 6638dc059..2b49add70 100644 --- a/apps/client/src/widgets/dialogs/about.tsx +++ b/apps/client/src/widgets/dialogs/about.tsx @@ -1,4 +1,3 @@ -import { openDialog } from "../../services/dialog.js"; import ReactBasicWidget from "../react/ReactBasicWidget.js"; import Modal from "../react/Modal.js"; import { t } from "../../services/i18n.js"; @@ -9,19 +8,26 @@ import openService from "../../services/open.js"; import { useState } from "preact/hooks"; import type { CSSProperties } from "preact/compat"; import type { AppInfo } from "@triliumnext/commons"; +import useTriliumEvent from "../react/hooks.jsx"; function AboutDialogComponent() { let [appInfo, setAppInfo] = useState(null); - - async function onShown() { - const appInfo = await server.get("app-info"); - setAppInfo(appInfo); - } - + let [shown, setShown] = useState(false); const forceWordBreak: CSSProperties = { wordBreak: "break-all" }; + useTriliumEvent("openAboutDialog", () => setShown(true)); + return ( - + { + const appInfo = await server.get("app-info"); + setAppInfo(appInfo); + }} + onHidden={() => setShown(false)} + > @@ -83,7 +89,4 @@ export default class AboutDialog extends ReactBasicWidget { return ; } - async openAboutDialogEvent() { - openDialog(this.$widget); - } } \ No newline at end of file diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx index 0a69794ed..7b8c512ac 100644 --- a/apps/client/src/widgets/dialogs/add_link.tsx +++ b/apps/client/src/widgets/dialogs/add_link.tsx @@ -1,5 +1,4 @@ -import { EventData } from "../../components/app_context"; -import { closeActiveDialog, openDialog } from "../../services/dialog"; +import { closeActiveDialog } from "../../services/dialog"; import { t } from "../../services/i18n"; import Modal from "../react/Modal"; import ReactBasicWidget from "../react/ReactBasicWidget"; @@ -10,24 +9,28 @@ import { useRef, useState } from "preact/hooks"; import tree from "../../services/tree"; import { useEffect } from "react"; import note_autocomplete, { Suggestion } from "../../services/note_autocomplete"; -import type { default as TextTypeWidget } from "../type_widgets/editable_text.js"; +import { default as TextTypeWidget } from "../type_widgets/editable_text.js"; import { logError } from "../../services/ws"; import FormGroup from "../react/FormGroup.js"; import { refToJQuerySelector } from "../react/react_utils"; +import useTriliumEvent from "../react/hooks"; type LinkType = "reference-link" | "external-link" | "hyper-link"; -interface AddLinkDialogProps { - text?: string; - textTypeWidget?: TextTypeWidget; -} - -function AddLinkDialogComponent({ text: _text, textTypeWidget }: AddLinkDialogProps) { - const [ text, setText ] = useState(_text ?? ""); +function AddLinkDialogComponent() { + const [ textTypeWidget, setTextTypeWidget ] = useState(); + const [ text, setText ] = useState(); const [ linkTitle, setLinkTitle ] = useState(""); const hasSelection = textTypeWidget?.hasSelection(); const [ linkType, setLinkType ] = useState(hasSelection ? "hyper-link" : "reference-link"); const [ suggestion, setSuggestion ] = useState(null); + const [ shown, setShown ] = useState(false); + + useTriliumEvent("showAddLinkDialog", ( { textTypeWidget, text }) => { + setTextTypeWidget(textTypeWidget); + setText(text); + setShown(true); + }); async function setDefaultLinkTitle(noteId: string) { const noteTitle = await tree.getNoteTitle(noteId); @@ -100,7 +103,11 @@ function AddLinkDialogComponent({ text: _text, textTypeWidget }: AddLinkDialogPr footer={