From 72be8f5924d5fac9bbd3c49948ec7ca63d2a08b5 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Thu, 21 Oct 2021 10:16:08 +0500 Subject: [PATCH] feat: show progress when downloading monograph images --- apps/web/src/components/editor/toolbar.js | 12 +++++- apps/web/src/components/icons/index.js | 1 + apps/web/src/components/publish-view/index.js | 43 +++++++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/editor/toolbar.js b/apps/web/src/components/editor/toolbar.js index 627953967..764ca1b63 100644 --- a/apps/web/src/components/editor/toolbar.js +++ b/apps/web/src/components/editor/toolbar.js @@ -8,9 +8,11 @@ import { useStore, store } from "../../stores/editor-store"; import { showToast } from "../../utils/toast"; import Animated from "../animated"; import { showPublishView } from "../publish-view"; +import { db } from "../../common/db"; function Toolbar(props) { const sessionState = useStore((store) => store.session.state); + const sessionId = useStore((store) => store.session.id); const isLocked = useStore((store) => store.session.locked); const [undoable, setUndoable] = useState(false); const [redoable, setRedoable] = useState(false); @@ -25,6 +27,11 @@ function Toolbar(props) { const toggleNightMode = useThemeStore((store) => store.toggleNightMode); const [isTitleVisible, setIsTitleVisible] = useState(false); + const isNotePublished = useMemo( + () => sessionId && db.monographs.isPublished(sessionId), + [sessionId] + ); + useEffect(() => { const editorScroll = document.querySelector(".editorScroll"); @@ -114,8 +121,8 @@ function Toolbar(props) { onClick: () => tinymce.activeEditor.execCommand("Redo"), }, { - title: "Publish", - icon: Icon.Publish, + title: isNotePublished ? "Published" : "Publish", + icon: isNotePublished ? Icon.Published : Icon.Publish, enabled: !isLocked, onClick: () => showPublishView(store.get().session.id, "top"), }, @@ -137,6 +144,7 @@ function Toolbar(props) { isLocked, theme, toggleNightMode, + isNotePublished, ] ); diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js index 7378caac8..ecf5eb6de 100644 --- a/apps/web/src/components/icons/index.js +++ b/apps/web/src/components/icons/index.js @@ -155,6 +155,7 @@ export const ExitFullscreen = createIcon(Icons.mdiFullscreenExit); export const Announcement = createIcon(Icons.mdiBullhorn); export const Publish = createIcon(Icons.mdiCloudUploadOutline); +export const Published = createIcon(Icons.mdiCloudCheckOutline); export const Copy = createIcon(Icons.mdiContentCopy); diff --git a/apps/web/src/components/publish-view/index.js b/apps/web/src/components/publish-view/index.js index 0df560d98..af280ec2c 100644 --- a/apps/web/src/components/publish-view/index.js +++ b/apps/web/src/components/publish-view/index.js @@ -8,6 +8,7 @@ import { db } from "../../common/db"; import * as clipboard from "clipboard-polyfill/text"; import ThemeProvider from "../theme-provider"; import { showToast } from "../../utils/toast"; +import { EV, EVENTS } from "notes-core/common"; function PublishView(props) { const { noteId, position, onClose } = props; @@ -15,6 +16,7 @@ function PublishView(props) { const [isPasswordProtected, setIsPasswordProtected] = useState(false); const [selfDestruct, setSelfDestruct] = useState(false); const [isPublishing, setIsPublishing] = useState(false); + const [processingStatus, setProcessingStatus] = useState(); const noteTitle = useMemo(() => db.notes.note(noteId)?.title, [noteId]); @@ -22,6 +24,21 @@ function PublishView(props) { setPublishId(db.monographs.monograph(noteId)); }, [noteId]); + useEffect(() => { + const attachmentsLoadingEvent = EV.subscribe( + EVENTS.attachmentsLoading, + ({ type, groupId, total, current }) => { + if (!groupId || !groupId.includes(noteId) || type !== "download") + return; + if (current === total) setProcessingStatus(); + else setProcessingStatus({ total, current }); + } + ); + return () => { + attachmentsLoadingEvent.unsubscribe(); + }; + }, [noteId]); + return ( - + {noteTitle} - Publish note - - This note will be published to a public URL. - - {publishId && ( + {publishId ? ( - This note is published. + This note is published at: + ) : ( + <> + Publish note + + This note will be published to a public URL. + + )} {isPasswordProtected && ( )} - + {processingStatus && ( + + Downloading images ({processingStatus.current}/ + {processingStatus.total}) + + )} +