Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(react/widgets): port shared_info
Elian Doranfbec6d887343
diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsxindex ab189f90da..5301702828 100644--- a/apps/client/src/layouts/desktop_layout.tsx+++ b/apps/client/src/layouts/desktop_layout.tsx@@ -17,7 +17,6 @@ import CreatePaneButton from "../widgets/buttons/create_pane_button.js";import ClosePaneButton from "../widgets/buttons/close_pane_button.js";import RightPaneContainer from "../widgets/containers/right_pane_container.js";import NoteWrapperWidget from "../widgets/note_wrapper.js";-import SharedInfoWidget from "../widgets/shared_info.js";import FindWidget from "../widgets/find.js";import TocWidget from "../widgets/toc.js";import HighlightsListWidget from "../widgets/highlights_list.js";@@ -42,6 +41,7 @@ import TitleBarButtons from "../widgets/title_bar_buttons.jsx";import LeftPaneToggle from "../widgets/buttons/left_pane_toggle.js";import ApiLog from "../widgets/api_log.jsx";import CloseZenModeButton from "../widgets/close_zen_button.jsx";+import SharedInfo from "../widgets/shared_info.jsx";export default class DesktopLayout {@@ -129,7 +129,7 @@ export default class DesktopLayout {.child(new CreatePaneButton())).child(<Ribbon />)- .child(new SharedInfoWidget())+ .child(<SharedInfo />).child(new WatchedFileUpdateStatusWidget()).child(<FloatingButtons items={DESKTOP_FLOATING_BUTTONS} />).child(diff --git a/apps/client/src/layouts/mobile_layout.tsx b/apps/client/src/layouts/mobile_layout.tsxindex cc721fa9a1..b7eceffa22 100644--- a/apps/client/src/layouts/mobile_layout.tsx+++ b/apps/client/src/layouts/mobile_layout.tsx@@ -143,7 +143,7 @@ export default class MobileLayout {.child(<NoteTitleWidget />).child(<MobileDetailMenu />))- .child(new SharedInfoWidget())+ .child(<SharedInfoWidget />).child(<FloatingButtons items={MOBILE_FLOATING_BUTTONS} />).child(new PromotedAttributesWidget()).child(diff --git a/apps/client/src/translations/cn/translation.json b/apps/client/src/translations/cn/translation.jsonindex 1c0a10e3ff..decb0aa841 100644--- a/apps/client/src/translations/cn/translation.json+++ b/apps/client/src/translations/cn/translation.json@@ -1440,8 +1440,8 @@"open-in-popup": "快速编辑"},"shared_info": {- "shared_publicly": "此笔记已公开分享于",- "shared_locally": "此笔记已在本地分享于",+ "shared_publicly": "",+ "shared_locally": "","help_link": "访问 <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a> 获取帮助。"},"note_types": {diff --git a/apps/client/src/translations/de/translation.json b/apps/client/src/translations/de/translation.jsonindex 0757a87f34..346228f654 100644--- a/apps/client/src/translations/de/translation.json+++ b/apps/client/src/translations/de/translation.json@@ -1404,8 +1404,8 @@"open-in-popup": "Schnellbearbeitung"},"shared_info": {- "shared_publicly": "Diese Notiz ist öffentlich geteilt auf",- "shared_locally": "Diese Notiz ist lokal geteilt auf",+ "shared_publicly": "Diese Notiz ist öffentlich geteilt auf {{- link}}",+ "shared_locally": "Diese Notiz ist lokal geteilt auf {{- link}}","help_link": "Für Hilfe besuche <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."},"note_types": {diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 461baa957a..d76843a270 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1602,8 +1602,8 @@"open-in-popup": "Quick edit"},"shared_info": {- "shared_publicly": "This note is shared publicly on",- "shared_locally": "This note is shared locally on",+ "shared_publicly": "This note is shared publicly on {{- link}}.",+ "shared_locally": "This note is shared locally on {{- link}}.","help_link": "For help visit <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."},"note_types": {diff --git a/apps/client/src/translations/es/translation.json b/apps/client/src/translations/es/translation.jsonindex 596864b6a5..545815a588 100644--- a/apps/client/src/translations/es/translation.json+++ b/apps/client/src/translations/es/translation.json@@ -1596,8 +1596,8 @@"open-in-popup": "Edición rápida"},"shared_info": {- "shared_publicly": "Esta nota está compartida públicamente en",- "shared_locally": "Esta nota está compartida localmente en",+ "shared_publicly": "Esta nota está compartida públicamente en {{- link}}",+ "shared_locally": "Esta nota está compartida localmente en {{- link}}","help_link": "Para obtener ayuda visite <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."},"note_types": {diff --git a/apps/client/src/translations/fr/translation.json b/apps/client/src/translations/fr/translation.jsonindex e085e10e84..82e41ae334 100644--- a/apps/client/src/translations/fr/translation.json+++ b/apps/client/src/translations/fr/translation.json@@ -1389,8 +1389,8 @@"convert-to-attachment-confirm": "Êtes-vous sûr de vouloir convertir les notes sélectionnées en pièces jointes de leurs notes parentes ?"},"shared_info": {- "shared_publicly": "Cette note est partagée publiquement sur",- "shared_locally": "Cette note est partagée localement sur",+ "shared_publicly": "Cette note est partagée publiquement sur {{- link}}",+ "shared_locally": "Cette note est partagée localement sur {{- link}}","help_link": "Pour obtenir de l'aide, visitez le <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."},"note_types": {diff --git a/apps/client/src/translations/ja/translation.json b/apps/client/src/translations/ja/translation.jsonindex d35501a375..aca33e683b 100644--- a/apps/client/src/translations/ja/translation.json+++ b/apps/client/src/translations/ja/translation.json@@ -977,8 +977,8 @@},"open-help-page": "ヘルプページを開く","shared_info": {- "shared_publicly": "このノートは一般公開されています",- "shared_locally": "このノートはローカルで共有されています",+ "shared_publicly": "",+ "shared_locally": "","help_link": "ヘルプについては、<a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>をご覧ください。"},"highlights_list_2": {diff --git a/apps/client/src/translations/pt_br/translation.json b/apps/client/src/translations/pt_br/translation.jsonindex feba4898ff..1275cda476 100644--- a/apps/client/src/translations/pt_br/translation.json+++ b/apps/client/src/translations/pt_br/translation.json@@ -2022,8 +2022,8 @@"handshake_failed": "Falha no handshake com o servidor de sincronização, erro: {{message}}"},"shared_info": {- "shared_publicly": "Esta nota é compartilhada publicamente",- "shared_locally": "Esta nota é compartilhada localmente",+ "shared_publicly": "",+ "shared_locally": "","help_link": "Para ajuda, visite a <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."}}diff --git a/apps/client/src/translations/ro/translation.json b/apps/client/src/translations/ro/translation.jsonindex 02c7834dcf..cc068831a8 100644--- a/apps/client/src/translations/ro/translation.json+++ b/apps/client/src/translations/ro/translation.json@@ -1373,8 +1373,8 @@},"shared_info": {"help_link": "Pentru informații vizitați <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki-ul</a>.",- "shared_locally": "Această notiță este partajată local la",- "shared_publicly": "Această notiță este partajată public la"+ "shared_locally": "Această notiță este partajată local la {{- link}}",+ "shared_publicly": "Această notiță este partajată public la {{- link}}"},"note_types": {"book": "Colecție",diff --git a/apps/client/src/translations/ru/translation.json b/apps/client/src/translations/ru/translation.jsonindex ab71bf7dc4..ceaf957ec5 100644--- a/apps/client/src/translations/ru/translation.json+++ b/apps/client/src/translations/ru/translation.json@@ -1974,8 +1974,8 @@},"shared_info": {"help_link": "Для получения справки посетите <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">вики</a>.",- "shared_locally": "Заметка общедоступна локально в",- "shared_publicly": "Заметка общедоступна публично в"+ "shared_locally": "Заметка общедоступна локально в {{- link}}",+ "shared_publicly": "Заметка общедоступна публично в {{- link}}"},"note_create": {"duplicated": "Создан дубль заметки \"{{title}}\"."diff --git a/apps/client/src/translations/tw/translation.json b/apps/client/src/translations/tw/translation.jsonindex 39ed2370f0..991ac115cf 100644--- a/apps/client/src/translations/tw/translation.json+++ b/apps/client/src/translations/tw/translation.json@@ -1399,8 +1399,8 @@"open-in-popup": "快速編輯"},"shared_info": {- "shared_publicly": "此筆記已公開分享在",- "shared_locally": "此筆記已在本地分享在",+ "shared_publicly": "",+ "shared_locally": "","help_link": "如需幫助,請訪問 <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>。"},"note_types": {diff --git a/apps/client/src/translations/uk/translation.json b/apps/client/src/translations/uk/translation.jsonindex 907828d910..7b64595a4d 100644--- a/apps/client/src/translations/uk/translation.json+++ b/apps/client/src/translations/uk/translation.json@@ -1909,8 +1909,8 @@"open-in-popup": "Швидке редагування"},"shared_info": {- "shared_publicly": "Ця нотатка опублікована на",- "shared_locally": "Цю нотатку опубліковано локально на",+ "shared_publicly": "Ця нотатка опублікована на {{- link}}",+ "shared_locally": "Цю нотатку опубліковано локально на {{- link}}","help_link": "Щоб отримати допомогу, відвідайте <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">вікі</a>."},"note_types": {diff --git a/apps/client/src/widgets/react/Alert.tsx b/apps/client/src/widgets/react/Alert.tsxindex e579601579..0dab00b4a1 100644--- a/apps/client/src/widgets/react/Alert.tsx+++ b/apps/client/src/widgets/react/Alert.tsx@@ -1,15 +1,17 @@import { ComponentChildren } from "preact";+import { CSSProperties } from "preact/compat";interface AlertProps {type: "info" | "danger" | "warning";title?: string;children: ComponentChildren;className?: string;+ style?: CSSProperties;}-export default function Alert({ title, type, children, className }: AlertProps) {+export default function Alert({ title, type, children, className, style }: AlertProps) {return (- <div className={`alert alert-${type} ${className ?? ""}`}>+ <div className={`alert alert-${type} ${className ?? ""}`} style={style}>{title && <h4>{title}</h4>}{children}diff --git a/apps/client/src/widgets/shared_info.ts b/apps/client/src/widgets/shared_info.tsdeleted file mode 100644index b6170a3c73..0000000000--- a/apps/client/src/widgets/shared_info.ts+++ /dev/null@@ -1,77 +0,0 @@-import NoteContextAwareWidget from "./note_context_aware_widget.js";-import options from "../services/options.js";-import attributeService from "../services/attributes.js";-import { t } from "../services/i18n.js";-import type FNote from "../entities/fnote.js";-import type { EventData } from "../components/app_context.js";--const TPL = /*html*/`-<div class="shared-info-widget alert alert-warning use-tn-links">- <style>- .shared-info-widget {- margin: 10px;- contain: none;- padding: 10px;- font-weight: bold;- }- </style>-- <span class="shared-text"></span> <a class="shared-link external"></a>. ${t("shared_info.help_link")}-</div>`;--export default class SharedInfoWidget extends NoteContextAwareWidget {-- private $sharedLink!: JQuery<HTMLElement>;- private $sharedText!: JQuery<HTMLElement>;-- isEnabled() {- return super.isEnabled() && this.noteId !== "_share" && this.note?.hasAncestor("_share");- }-- doRender() {- this.$widget = $(TPL);- this.$sharedLink = this.$widget.find(".shared-link");- this.$sharedText = this.$widget.find(".shared-text");- this.contentSized();- }-- async refreshWithNote(note: FNote) {- const syncServerHost = options.get("syncServerHost");- let link;-- const shareId = this.getShareId(note);-- if (syncServerHost) {- link = `${syncServerHost}/share/${shareId}`;- this.$sharedText.text(t("shared_info.shared_publicly"));- } else {- let host = location.host;- if (host.endsWith("/")) {- // seems like IE has trailing slash- // https://github.com/zadam/trilium/issues/3782- host = host.substr(0, host.length - 1);- }-- link = `${location.protocol}//${host}${location.pathname}share/${shareId}`;- this.$sharedText.text(t("shared_info.shared_locally"));- }-- this.$sharedLink.attr("href", link).text(link);- }-- getShareId(note: FNote) {- if (note.hasOwnedLabel("shareRoot")) {- return "";- }-- return note.getOwnedLabelValue("shareAlias") || note.noteId;- }-- entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {- if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {- this.refresh();- } else if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId)) {- this.refresh();- }- }-}diff --git a/apps/client/src/widgets/shared_info.tsx b/apps/client/src/widgets/shared_info.tsxnew file mode 100644index 0000000000..15bf53b1ae--- /dev/null+++ b/apps/client/src/widgets/shared_info.tsx@@ -0,0 +1,74 @@+import { useEffect, useState } from "preact/hooks";+import { t } from "../services/i18n";+import Alert from "./react/Alert";+import { useNoteContext, useTriliumEvent, useTriliumOption } from "./react/hooks";+import FNote from "../entities/fnote";+import attributes from "../services/attributes";+import RawHtml from "./react/RawHtml";+import HelpButton from "./react/HelpButton";++export default function SharedInfo() {+ const { note } = useNoteContext();+ const [ syncServerHost ] = useTriliumOption("syncServerHost");+ const [ link, setLink ] = useState<string>();++ function refresh() {+ if (!note) return;+ if (note.noteId === "_share" || !note?.hasAncestor("_share")) {+ setLink(undefined);+ return;+ }++ let link;+ const shareId = getShareId(note);++ if (syncServerHost) {+ link = `${syncServerHost}/share/${shareId}`;+ } else {+ let host = location.host;+ if (host.endsWith("/")) {+ // seems like IE has trailing slash+ // https://github.com/zadam/trilium/issues/3782+ host = host.substring(0, host.length - 1);+ }++ link = `${location.protocol}//${host}${location.pathname}share/${shareId}`;+ }++ setLink(`<a href="${link}" class="external">${link}</a>`);+ }++ useEffect(refresh, [ note ]);+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributes.isAffecting(attr, note))) {+ refresh();+ } else if (loadResults.getBranchRows().find((branch) => branch.noteId === note?.noteId)) {+ refresh();+ }+ });++ return (+ <Alert className="shared-info-widget" type="warning" style={{+ contain: "none",+ margin: "10px",+ padding: "10px",+ fontWeight: "bold",+ display: !link ? "none" : undefined+ }}>+ {link && (+ <RawHtml html={syncServerHost+ ? t("shared_info.shared_publicly", { link })+ : t("shared_info.shared_locally", { link })} />+ )}+ <HelpButton helpPage="R9pX4DGra2Vt" style={{ width: "24px", height: "24px" }} />+ </Alert>+ )+}++function getShareId(note: FNote) {+ if (note.hasOwnedLabel("shareRoot")) {+ return "";+ }++ return note.getOwnedLabelValue("shareAlias") || note.noteId;+}\ No newline at end of file