AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(web): keep note sharing available while reading is locked (#428)
tianma-ifbf0d51a02d95
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex ef75278f..54d3e152 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -2608,6 +2608,7 @@ const RichEditorPane = ({shareOpen,wechatCopyState,} = useEditorDocumentActions({+ canShareMemo: Boolean(memo && !readOnly),documentActionRequest,editor,effectiveReadOnly,@@ -3530,18 +3531,33 @@ const RichEditorPane = ({/><div className="flex shrink-0 items-center gap-1">- {isMemoShared && (- <button- className="inline-flex h-8 items-center gap-1.5 rounded-full bg-emerald-50 px-2 text-xs font-semibold text-emerald-700 ring-1 ring-inset ring-emerald-200 transition-colors hover:bg-emerald-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500"+ {isMemoShared && !readOnly && (+ <Button+ className="h-8 gap-1.5 rounded-full bg-emerald-50 px-2 text-xs font-semibold text-emerald-700 ring-1 ring-inset ring-emerald-200 hover:bg-emerald-100 hover:text-emerald-800 focus-visible:ring-emerald-500"+ size="sm"+ variant="ghost"type="button"title={t("sharing.manage")}aria-label={t("sharing.manage")}- disabled={effectiveReadOnly}onClick={() => setShareOpen(true)}><Share2 className="h-3.5 w-3.5" aria-hidden="true" /><span className="hidden sm:inline">{t("sharing.active")}</span>- </button>+ </Button>+ )}+ {!readOnly && !isMemoShared && !mobileEditingActive && (+ <Button+ className="h-8 w-8 text-slate-500 sm:hidden"+ size="icon"+ variant="ghost"+ type="button"+ title={t(isLocalMemoId(memo.id) ? "sharing.afterSync" : "sharing.action")}+ aria-label={t(isLocalMemoId(memo.id) ? "sharing.afterSync" : "sharing.action")}+ disabled={isLocalMemoId(memo.id)}+ onClick={() => setShareOpen(true)}+ >+ <Share2 className="h-4 w-4" aria-hidden="true" />+ </Button>)}<spanclassName="hidden whitespace-nowrap px-1.5 text-xs tabular-nums text-slate-400 sm:inline-flex"@@ -3753,7 +3769,7 @@ const RichEditorPane = ({<History className="h-4 w-4 text-slate-500" />{t("editor.versionHistory")}</DropdownMenuItem>- {!effectiveReadOnly && (+ {!readOnly && (<DropdownMenuItemclassName={cn("flex h-9 w-full items-center gap-2 px-3 text-left text-sm hover:bg-slate-50 cursor-pointer outline-none",diff --git a/apps/web/src/components/editor/useEditorDocumentActions.ts b/apps/web/src/components/editor/useEditorDocumentActions.tsindex a2f13c9e..6b5027d7 100644--- a/apps/web/src/components/editor/useEditorDocumentActions.ts+++ b/apps/web/src/components/editor/useEditorDocumentActions.ts@@ -17,6 +17,7 @@ import { isEditorReady } from "./editor-pane-helpers";export type WechatCopyState = "idle" | "copying" | "copied" | "error";export const useEditorDocumentActions = ({+ canShareMemo,documentActionRequest,editor,effectiveReadOnly,@@ -32,6 +33,7 @@ export const useEditorDocumentActions = ({useMarkdownSourceEditor,useMobilePlainTextEditor,}: {+ canShareMemo: boolean;documentActionRequest?: MemoDocumentActionRequest | null;editor: Editor | null;effectiveReadOnly: boolean;@@ -232,16 +234,16 @@ export const useEditorDocumentActions = ({exportPdf: handleExportPdf,saveAsTemplate: handleSaveAsTemplate,share: () => {- if (!effectiveReadOnly) setShareOpen(true);+ if (canShareMemo) setShareOpen(true);},shareImage: handleOpenImageShare,},documentActionRequest.printWindow,);}, [+ canShareMemo,documentActionRequest,editor,- effectiveReadOnly,handleExportHtml,handleExportMarkdown,handleExportPdf,diff --git a/tests/note-sharing-menu.test.ts b/tests/note-sharing-menu.test.tsindex 11762521..19468dd2 100644--- a/tests/note-sharing-menu.test.ts+++ b/tests/note-sharing-menu.test.ts@@ -6,11 +6,21 @@ import { zhCN } from "../packages/shared/src/i18n/zh-CN";const readSource = (path: string) => readFileSync(new URL(path, import.meta.url), "utf8");const editorSource = readSource("../apps/web/src/components/EditorPane.tsx");+const editorActionsSource = readSource("../apps/web/src/components/editor/useEditorDocumentActions.ts");const memoListSource = readSource("../apps/web/src/components/MemoListPane.tsx");const shareDialogSource = readSource("../apps/web/src/components/dialogs/ShareMemoDialog.tsx");const publicShareSource = readSource("../apps/web/src/components/PublicSharePage.tsx");describe("note sharing menu", () => {+ test("keeps sharing available while reading is locked and on the phone", () => {+ expect(editorActionsSource).toContain("if (canShareMemo) setShareOpen(true)");+ expect(editorActionsSource).not.toContain("if (!effectiveReadOnly) setShareOpen(true)");+ expect(editorSource).toContain("canShareMemo: Boolean(memo && !readOnly)");+ expect(editorSource).toContain("{!readOnly && (\n <DropdownMenuItem");+ expect(editorSource).toContain('className="h-8 w-8 text-slate-500 sm:hidden"');+ expect(editorSource).toContain('title={t(isLocalMemoId(memo.id) ? "sharing.afterSync" : "sharing.action")}');+ });+test("explains why sharing a newly created local note is disabled", () => {expect(zhCN.sharing.afterSync).toBe("同步后可分享笔记");expect(enUS.sharing.afterSync).toBe("Share note after sync");