Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: use new file upload/download events

Abdullah Atta6ba18c5bd106
diff --git a/apps/web/src/app-effects.tsx b/apps/web/src/app-effects.tsx
index 98a85f286..b5f0d2834 100644
--- a/apps/web/src/app-effects.tsx
+++ b/apps/web/src/app-effects.tsx
@@ -122,28 +122,35 @@ export default function AppEffects({ setShow }: AppEffectsProps) {
// }
// );
- const attachmentsLoadingEvent = EV.subscribe(
- EVENTS.attachmentsLoading,
- ({
- type,
- total,
- current
- }: {
- type: ProcessingType;
- total: number;
- current: number;
- }) => {
- const [key, status] = getProcessingStatusFromType(type);
+ function handleDownloadUploadProgress(
+ type: "download" | "upload",
+ total: number,
+ current: number
+ ) {
+ const [key, status] = getProcessingStatusFromType(type);
+
+ if (current === total) {
+ removeStatus(key);
+ } else {
+ updateStatus({
+ key,
+ status: `${status} attachments (${current}/${total})`,
+ progress: 0
+ });
+ }
+ }
- if (current === total) {
- removeStatus(key);
- } else {
- updateStatus({
- key,
- status: `${status} attachments (${current}/${total})`,
- progress: 0
- });
- }
+ const fileDownloadedEvent = EV.subscribe(
+ EVENTS.fileDownloaded,
+ ({ total, current }: { total: number; current: number }) => {
+ handleDownloadUploadProgress("download", total, current);
+ }
+ );
+
+ const fileUploadedEvent = EV.subscribe(
+ EVENTS.fileUploaded,
+ ({ total, current }: { total: number; current: number }) => {
+ handleDownloadUploadProgress("upload", total, current);
}
);
@@ -174,7 +181,8 @@ export default function AppEffects({ setShow }: AppEffectsProps) {
registerKeyMap();
return () => {
- attachmentsLoadingEvent.unsubscribe();
+ fileUploadedEvent.unsubscribe();
+ fileDownloadedEvent.unsubscribe();
progressEvent.unsubscribe();
// systemTimeInvalidEvent.unsubscribe();
};
diff --git a/apps/web/src/components/publish-view/index.jsx b/apps/web/src/components/publish-view/index.jsx
index bb0c18224..3a96c428b 100644
--- a/apps/web/src/components/publish-view/index.jsx
+++ b/apps/web/src/components/publish-view/index.jsx
@@ -49,17 +49,17 @@ function PublishView(props) {
}, [noteId]);
useEffect(() => {
- const attachmentsLoadingEvent = EV.subscribe(
- EVENTS.attachmentsLoading,
- ({ type, groupId, total, current }) => {
- if (!groupId || !groupId.includes(noteId) || type !== "download")
- return;
+ const fileDownloadedEvent = EV.subscribe(
+ EVENTS.fileDownloaded,
+ ({ total, current, groupId }) => {
+ if (!groupId || !groupId.includes(noteId)) return;
if (current === total) setProcessingStatus();
else setProcessingStatus({ total, current });
}
);
+
return () => {
- attachmentsLoadingEvent.unsubscribe();
+ fileDownloadedEvent.unsubscribe();
};
}, [noteId]);