diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsx index ab189f90d..530170282 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() - .child(new SharedInfoWidget()) + .child() .child(new WatchedFileUpdateStatusWidget()) .child() .child( diff --git a/apps/client/src/layouts/mobile_layout.tsx b/apps/client/src/layouts/mobile_layout.tsx index cc721fa9a..b7eceffa2 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() .child() ) - .child(new SharedInfoWidget()) + .child() .child() .child(new PromotedAttributesWidget()) .child( diff --git a/apps/client/src/translations/cn/translation.json b/apps/client/src/translations/cn/translation.json index 1c0a10e3f..decb0aa84 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": "访问 wiki 获取帮助。" }, "note_types": { diff --git a/apps/client/src/translations/de/translation.json b/apps/client/src/translations/de/translation.json index 0757a87f3..346228f65 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 wiki." }, "note_types": { diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 461baa957..d76843a27 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 wiki." }, "note_types": { diff --git a/apps/client/src/translations/es/translation.json b/apps/client/src/translations/es/translation.json index 596864b6a..545815a58 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 wiki." }, "note_types": { diff --git a/apps/client/src/translations/fr/translation.json b/apps/client/src/translations/fr/translation.json index e085e10e8..82e41ae33 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 wiki." }, "note_types": { diff --git a/apps/client/src/translations/ja/translation.json b/apps/client/src/translations/ja/translation.json index d35501a37..aca33e683 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": "ヘルプについては、wikiをご覧ください。" }, "highlights_list_2": { diff --git a/apps/client/src/translations/pt_br/translation.json b/apps/client/src/translations/pt_br/translation.json index feba4898f..1275cda47 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 wiki." } } diff --git a/apps/client/src/translations/ro/translation.json b/apps/client/src/translations/ro/translation.json index 02c7834dc..cc068831a 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 wiki-ul.", - "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.json index ab71bf7dc..ceaf957ec 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": "Для получения справки посетите вики.", - "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.json index 39ed2370f..991ac115c 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": "如需幫助,請訪問 wiki。" }, "note_types": { diff --git a/apps/client/src/translations/uk/translation.json b/apps/client/src/translations/uk/translation.json index 907828d91..7b64595a4 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": "Щоб отримати допомогу, відвідайте вікі." }, "note_types": { diff --git a/apps/client/src/widgets/react/Alert.tsx b/apps/client/src/widgets/react/Alert.tsx index e57960157..0dab00b4a 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 ( -
+
{title &&

{title}

} {children} diff --git a/apps/client/src/widgets/shared_info.ts b/apps/client/src/widgets/shared_info.ts deleted file mode 100644 index b6170a3c7..000000000 --- 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*/` -`; - -export default class SharedInfoWidget extends NoteContextAwareWidget { - - private $sharedLink!: JQuery; - private $sharedText!: JQuery; - - 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.tsx new file mode 100644 index 000000000..15bf53b1a --- /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(); + + 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(`${link}`); + } + + 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 ( + + {link && ( + + )} + + + ) +} + +function getShareId(note: FNote) { + if (note.hasOwnedLabel("shareRoot")) { + return ""; + } + + return note.getOwnedLabelValue("shareAlias") || note.noteId; +} \ No newline at end of file