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(share): offer only the static export in the mobile app
Elian Doranb2eeb806922c
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex efcd7f3caf..4643bb6cb0 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2514,7 +2514,8 @@"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>.",- "shared_preview": "This note is shared on {{- link}}, but only this browser can open that page, and only while Trilium is open in it. Publishing it for others needs a Trilium server."+ "shared_preview": "This note is shared on {{- link}}, but only this browser can open that page, and only while Trilium is open in it. Publishing it for others needs a Trilium server.",+ "shared_export_only": "This note is shared, but the mobile app cannot open shared pages. To publish it, export the subtree as \"{{format}}\" and host the files on any web server, or use a Trilium server."},"read-only-info": {"read-only-note": "Currently viewing a read-only note.",@@ -3770,7 +3771,9 @@"save_status_unsaved_tooltip": "There are unsaved changes. They will be saved automatically in a moment.","save_status_error_tooltip": "An error occurred while saving the note. If possible, try copying the note content elsewhere and reloading the application.","shared_preview": "Share preview",- "shared_preview_description": "Only this browser can open the shared page, and only while Trilium is open in it. To publish it, export the subtree as \"{{- format}}\" and host the files on any web server, or use a Trilium server."+ "shared_preview_description": "Only this browser can open the shared page, and only while Trilium is open in it. To publish it, export the subtree as \"{{- format}}\" and host the files on any web server, or use a Trilium server.",+ "shared_export_only": "Not published",+ "shared_export_only_description": "The mobile app cannot open shared pages. To publish this note, export the subtree as \"{{- format}}\" and host the files on any web server, or use a Trilium server."},"status_bar": {"language_title": "Change content language",diff --git a/apps/client/src/widgets/layout/NoteBadges.tsx b/apps/client/src/widgets/layout/NoteBadges.tsxindex 36a46d4c01..51aea38451 100644--- a/apps/client/src/widgets/layout/NoteBadges.tsx+++ b/apps/client/src/widgets/layout/NoteBadges.tsx@@ -83,25 +83,26 @@ function ShareBadge() {const { note } = useNoteContext();const [ , switchShareState ] = useShareState(note);const { scope, linkHref } = useShareInfo(note);+ const badge = SHARE_BADGES[scope];return (linkHref &&<BadgeWithDropdown- icon={SHARE_BADGES[scope].icon}- text={t(SHARE_BADGES[scope].text)}- tooltip={scope === "preview"- ? t("breadcrumb_badges.shared_preview_description", { format: t("export.format_share_name") })- : undefined}+ icon={badge.icon}+ text={t(badge.text)}+ tooltip={badge.tooltip && t(badge.tooltip, { format: t("export.format_share_name") })}className="share-badge">- <FormListItem- icon="bx bx-copy"- onClick={() => copyTextWithToast(linkHref)}- >{t("breadcrumb_badges.shared_copy_to_clipboard")}</FormListItem>- <FormListItem- icon="bx bx-link-external"- onClick={(e) => goToLinkExt(e, linkHref)}- >{t("breadcrumb_badges.shared_open_in_browser")}</FormListItem>- <FormDropdownDivider />+ {scope !== "export-only" && <>+ <FormListItem+ icon="bx bx-copy"+ onClick={() => copyTextWithToast(linkHref)}+ >{t("breadcrumb_badges.shared_copy_to_clipboard")}</FormListItem>+ <FormListItem+ icon="bx bx-link-external"+ onClick={(e) => goToLinkExt(e, linkHref)}+ >{t("breadcrumb_badges.shared_open_in_browser")}</FormListItem>+ <FormDropdownDivider />+ </>}<FormListItemicon="bx bx-unlink"onClick={() => switchShareState(false)}@@ -110,10 +111,19 @@ function ShareBadge() {);}-const SHARE_BADGES: Record<ShareScope, { icon: string; text: string }> = {+const SHARE_BADGES: Record<ShareScope, { icon: string; text: string; tooltip?: string }> = {public: { icon: "bx bx-world", text: "breadcrumb_badges.shared_publicly" },local: { icon: "bx bx-share-alt", text: "breadcrumb_badges.shared_locally" },- preview: { icon: "bx bx-show", text: "breadcrumb_badges.shared_preview" }+ preview: {+ icon: "bx bx-show",+ text: "breadcrumb_badges.shared_preview",+ tooltip: "breadcrumb_badges.shared_preview_description"+ },+ "export-only": {+ icon: "bx bx-export",+ text: "breadcrumb_badges.shared_export_only",+ tooltip: "breadcrumb_badges.shared_export_only_description"+ }};function ClippedNoteBadge() {diff --git a/apps/client/src/widgets/shared_info.spec.tsx b/apps/client/src/widgets/shared_info.spec.tsxindex 7eff6af18e..7ae7ebf1e1 100644--- a/apps/client/src/widgets/shared_info.spec.tsx+++ b/apps/client/src/widgets/shared_info.spec.tsx@@ -14,14 +14,17 @@ describe("buildShareLinkHtml", () => {});describe("getShareScope", () => {- it("tells a public share from a local one and from a standalone preview", () => {+ it("tells a public share from a local one, a standalone preview and one only an export publishes", () => {const syncServerHost = "https://sync.example.com";-- expect(getShareScope({ isElectron: false, isStandalone: false, syncServerHost: "" })).toBe("public");- expect(getShareScope({ isElectron: true, isStandalone: false, syncServerHost: "" })).toBe("local");- expect(getShareScope({ isElectron: true, isStandalone: false, syncServerHost })).toBe("public");- expect(getShareScope({ isElectron: false, isStandalone: true, syncServerHost: "" })).toBe("preview");- expect(getShareScope({ isElectron: false, isStandalone: true, syncServerHost })).toBe("public");+ const platform = { isElectron: false, isStandalone: false, isMobileApp: false };++ expect(getShareScope({ ...platform, syncServerHost: "" })).toBe("public");+ expect(getShareScope({ ...platform, isElectron: true, syncServerHost: "" })).toBe("local");+ expect(getShareScope({ ...platform, isElectron: true, syncServerHost })).toBe("public");+ expect(getShareScope({ ...platform, isStandalone: true, syncServerHost: "" })).toBe("preview");+ expect(getShareScope({ ...platform, isStandalone: true, syncServerHost })).toBe("public");+ expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost: "" })).toBe("export-only");+ expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost })).toBe("public");});});diff --git a/apps/client/src/widgets/shared_info.tsx b/apps/client/src/widgets/shared_info.tsxindex 209925cc92..c622c89bbf 100644--- a/apps/client/src/widgets/shared_info.tsx+++ b/apps/client/src/widgets/shared_info.tsx@@ -6,7 +6,7 @@ import FNote from "../entities/fnote";import attributes from "../services/attributes";import { t } from "../services/i18n";import { buildShareLink } from "../services/share_link";-import { escapeHtml, isElectron, isStandalone } from "../services/utils";+import { escapeHtml, isElectron, isMobileApp, isStandalone } from "../services/utils";import HelpButton from "./react/HelpButton";import { useNoteContext, useTriliumEvent, useTriliumOption } from "./react/hooks";import InfoBar from "./react/InfoBar";@@ -18,7 +18,7 @@ export default function SharedInfo() {return (<InfoBar className="shared-info-widget" type="subtle" style={{display: (!link) ? "none" : undefined}}>- {link && <RawHtml html={t(SCOPE_MESSAGES[scope], { link })} />}+ {link && <RawHtml html={t(SCOPE_MESSAGES[scope], { link, format: t("export.format_share_name") })} />}<HelpButton helpPage="R9pX4DGra2Vt" style={{ width: "24px", height: "24px" }} /></InfoBar>);@@ -55,25 +55,37 @@ export function useShareInfo(note: FNote | null | undefined) {return {link,linkHref,- scope: getShareScope({ isElectron: isElectron(), isStandalone: !!isStandalone, syncServerHost })+ scope: getShareScope({+ isElectron: isElectron(),+ isStandalone: !!isStandalone,+ isMobileApp: isMobileApp(),+ syncServerHost+ })};}/*** Where a shared note can be opened from. `local` is the desktop app without a sync server, which* serves the page on the loopback address. `preview` is the standalone build without a sync server,- * which renders the page in its own service worker, so only this browser can open it. A server- * cannot tell whether it is reachable from outside, so it always reports `public`.+ * which renders the page in its own service worker, so only this browser can open it. `export-only`+ * is the mobile app without a sync server: its link opens nowhere, so the static export is the only+ * way to publish the note. A server cannot tell whether it is reachable from outside, so it always+ * reports `public`.*/-export function getShareScope({ isElectron, isStandalone, syncServerHost }: {+export function getShareScope({ isElectron, isStandalone, isMobileApp, syncServerHost }: {isElectron: boolean;isStandalone: boolean;+ isMobileApp: boolean;syncServerHost: string | null | undefined;}): ShareScope {if (syncServerHost) {return "public";}+ if (isMobileApp) {+ return "export-only";+ }+if (isStandalone) {return "preview";}@@ -81,12 +93,13 @@ export function getShareScope({ isElectron, isStandalone, syncServerHost }: {return isElectron ? "local" : "public";}-export type ShareScope = "public" | "local" | "preview";+export type ShareScope = "public" | "local" | "preview" | "export-only";const SCOPE_MESSAGES: Record<ShareScope, string> = {public: "shared_info.shared_publicly",local: "shared_info.shared_locally",- preview: "shared_info.shared_preview"+ preview: "shared_info.shared_preview",+ "export-only": "shared_info.shared_export_only"};export function buildShareLinkHtml(link: string) {