From f07269f4ea2afeaf8f5008d8f0db2fb9c41fb61d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 7 Feb 2024 19:52:15 +0500 Subject: [PATCH] web: fix monograph publishing popup --- apps/web/src/components/editor/toolbar.jsx | 2 +- apps/web/src/components/note/index.tsx | 2 +- apps/web/src/components/properties/index.tsx | 2 +- .../publish-view/{index.jsx => index.tsx} | 68 +++++++++++-------- 4 files changed, 41 insertions(+), 33 deletions(-) rename apps/web/src/components/publish-view/{index.jsx => index.tsx} (84%) diff --git a/apps/web/src/components/editor/toolbar.jsx b/apps/web/src/components/editor/toolbar.jsx index 2304e5e4b..fe32318a3 100644 --- a/apps/web/src/components/editor/toolbar.jsx +++ b/apps/web/src/components/editor/toolbar.jsx @@ -104,7 +104,7 @@ function Toolbar() { icon: isNotePublished ? Published : Publish, hidden: !sessionId || isDeleted, enabled: !isLocked, - onClick: () => showPublishView(store.get().session.id, "top") + onClick: () => showPublishView(store.get().session, "top") } ], [sessionId, isLocked, isNotePublished, isDeleted] diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsx index e60c8c64c..8c000dd1e 100644 --- a/apps/web/src/components/note/index.tsx +++ b/apps/web/src/components/note/index.tsx @@ -427,7 +427,7 @@ const menuItems: ( onClick: async () => { const isPublished = db.monographs.isPublished(note.id); if (isPublished) await db.monographs.unpublish(note.id); - else await showPublishView(note.id, "bottom"); + else await showPublishView(note, "bottom"); } }, { diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsx index 1b4728101..e6fc70546 100644 --- a/apps/web/src/components/properties/index.tsx +++ b/apps/web/src/components/properties/index.tsx @@ -209,7 +209,7 @@ function Colors({ noteId }: { noteId: string }) { px={2} sx={{ cursor: "pointer", - justifyContent: "center" + justifyContent: "start" }} > {result.status === "fulfilled" && diff --git a/apps/web/src/components/publish-view/index.jsx b/apps/web/src/components/publish-view/index.tsx similarity index 84% rename from apps/web/src/components/publish-view/index.jsx rename to apps/web/src/components/publish-view/index.tsx index 0dcbd5e69..24a47d27c 100644 --- a/apps/web/src/components/publish-view/index.jsx +++ b/apps/web/src/components/publish-view/index.tsx @@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import ReactDOM from "react-dom"; -import { Flex, Text, Button } from "@theme-ui/components"; +import { Flex, Text, Button, Link } from "@theme-ui/components"; import { Copy } from "../icons"; import Toggle from "../toggle"; import Field from "../field"; @@ -31,29 +31,34 @@ import { EV, EVENTS } from "@notesnook/core/dist/common"; import { useStore } from "../../stores/monograph-store"; import ReactModal from "react-modal"; import { DialogButton } from "../dialog"; +import { Note } from "@notesnook/core"; -function PublishView(props) { - const { noteId, onClose } = props; - const [publishId, setPublishId] = useState(); +type PublishViewProps = { + note: Note; + onClose: (result: boolean) => void; +}; +function PublishView(props: PublishViewProps) { + const { note, onClose } = props; + const [publishId, setPublishId] = useState( + db.monographs.monograph(note.id) + ); const [isPasswordProtected, setIsPasswordProtected] = useState(false); const [selfDestruct, setSelfDestruct] = useState(false); const [isPublishing, setIsPublishing] = useState(false); - const [processingStatus, setProcessingStatus] = useState(); + const [processingStatus, setProcessingStatus] = useState<{ + total?: number; + current: number; + }>(); + const passwordInput = useRef(null); const publishNote = useStore((store) => store.publish); const unpublishNote = useStore((store) => store.unpublish); - const noteTitle = useMemo(() => db.notes.note(noteId)?.title, [noteId]); - - useEffect(() => { - setPublishId(db.monographs.monograph(noteId)); - }, [noteId]); - useEffect(() => { const fileDownloadedEvent = EV.subscribe( EVENTS.fileDownloaded, ({ total, current, groupId }) => { - if (!groupId || !groupId.includes(noteId)) return; - if (current === total) setProcessingStatus(); + if (!groupId || !groupId.includes(note.id)) return; + if (current === total) setProcessingStatus(undefined); else setProcessingStatus({ total, current }); } ); @@ -61,7 +66,7 @@ function PublishView(props) { return () => { fileDownloadedEvent.unsubscribe(); }; - }, [noteId]); + }, [note.id]); return ( - {noteTitle} + {note.title} {isPublishing ? ( - {`https://monogr.ph/${publishId}`} - +