Skip to content

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

feat: add upload/download attachment progress

thecodrr638b3a7c0605
diff --git a/apps/web/src/app-effects.js b/apps/web/src/app-effects.js
index 3408ea1c9..f604f5ba1 100644
--- a/apps/web/src/app-effects.js
+++ b/apps/web/src/app-effects.js
@@ -1,9 +1,9 @@
import React, { useEffect } from "react";
-import { useStore } from "./stores/app-store";
+import { useStore, store } from "./stores/app-store";
import { useStore as useUserStore } from "./stores/user-store";
import { useStore as useNotesStore } from "./stores/note-store";
import { resetReminders } from "./common/reminders";
-import { introduceFeatures } from "./common";
+import { AppEventManager, AppEvents, introduceFeatures } from "./common";
import { db } from "./common/db";
import { CHECK_IDS, EV, EVENTS } from "notes-core/common";
import { registerKeyMap } from "./common/key-map";
@@ -13,6 +13,7 @@ function AppEffects({ isMobile, isTablet, setShow, slideToIndex }) {
const refreshColors = useStore((store) => store.refreshColors);
const refreshMenuPins = useStore((store) => store.refreshMenuPins);
const updateLastSynced = useStore((store) => store.updateLastSynced);
+ const setProcessingStatus = useStore((store) => store.setProcessingStatus);
const isFocusMode = useStore((store) => store.isFocusMode);
const isEditorOpen = useStore((store) => store.isEditorOpen);
const toggleSideMenu = useStore((store) => store.toggleSideMenu);
@@ -46,22 +47,65 @@ function AppEffects({ isMobile, isTablet, setShow, slideToIndex }) {
);
useEffect(() => {
- EV.subscribe(EVENTS.userCheckStatus, async (type) => {
- if (isUserPremium()) {
- return { type, result: true };
- } else {
- if (type !== CHECK_IDS.databaseSync)
- await import("./common/dialogcontroller").then((dialogs) =>
- dialogs.showBuyDialog()
- );
- return { type, result: false };
+ const userCheckStatusEvent = EV.subscribe(
+ EVENTS.userCheckStatus,
+ async (type) => {
+ if (isUserPremium()) {
+ return { type, result: true };
+ } else {
+ if (type !== CHECK_IDS.databaseSync)
+ await import("./common/dialogcontroller").then((dialogs) =>
+ dialogs.showBuyDialog()
+ );
+ return { type, result: false };
+ }
}
- });
+ );
+
+ const attachmentsLoadingEvent = EV.subscribe(
+ EVENTS.attachmentsLoading,
+ ({ type, total, current }) => {
+ const key =
+ type === "download"
+ ? "downloadingAttachments"
+ : "uploadingAttachments";
+
+ if (current === total) {
+ setProcessingStatus(key);
+ return;
+ }
+ const status =
+ type === "download"
+ ? `Downloading attachments (${current}/${total})`
+ : `Uploading attachments (${current}/${total})`;
+ setProcessingStatus(key, status, 0);
+ }
+ );
+
+ const progressEvent = AppEventManager.subscribe(
+ AppEvents.UPDATE_ATTACHMENT_PROGRESS,
+ ({ type, total, loaded }) => {
+ const key =
+ type === "download"
+ ? "downloadingAttachments"
+ : "uploadingAttachments";
+ const { status } = store.get().processingStatuses[key];
+ const percent = Math.round((loaded / total) * 100);
+ if (loaded === total) {
+ setProcessingStatus(key, status, 100);
+ return;
+ }
+ setProcessingStatus(key, status, percent);
+ }
+ );
+
registerKeyMap();
return () => {
- EV.unsubscribeAll();
+ userCheckStatusEvent.unsubscribe();
+ attachmentsLoadingEvent.unsubscribe();
+ progressEvent.unsubscribe();
};
- }, []);
+ }, [setProcessingStatus]);
useEffect(() => {
if (isFocusMode) {
diff --git a/apps/web/src/common/db.js b/apps/web/src/common/db.js
index a73f79bc2..7101b9421 100644
--- a/apps/web/src/common/db.js
+++ b/apps/web/src/common/db.js
@@ -26,16 +26,16 @@ async function initializeDatabase() {
SSE_HOST: "https://events.streetwriters.co",
});
} else {
- // db.host({
- // API_HOST: "http://localhost:5264",
- // AUTH_HOST: "http://localhost:8264",
- // SSE_HOST: "http://localhost:7264",
- // });
db.host({
- API_HOST: "http://192.168.10.29:5264",
- AUTH_HOST: "http://192.168.10.29:8264",
- SSE_HOST: "http://192.168.10.29:7264",
+ API_HOST: "http://localhost:5264",
+ AUTH_HOST: "http://localhost:8264",
+ SSE_HOST: "http://localhost:7264",
});
+ // db.host({
+ // API_HOST: "http://192.168.10.29:5264",
+ // AUTH_HOST: "http://192.168.10.29:8264",
+ // SSE_HOST: "http://192.168.10.29:7264",
+ // });
}
await db.init();
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index 33c31da75..46b2adce5 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -13,6 +13,7 @@ import { hashNavigate, getCurrentHash } from "../navigation";
import { db } from "./db";
import { sanitizeFilename } from "../utils/filename";
import { isTesting } from "../utils/platform";
+import EventManager from "notes-core/utils/eventmanager";
export const COLORS = [
"Red",
@@ -135,3 +136,8 @@ export async function verifyAccount() {
return db.user.verifyPassword(password);
});
}
+
+export const AppEventManager = new EventManager();
+export const AppEvents = {
+ UPDATE_ATTACHMENT_PROGRESS: "updateAttachmentProgress",
+};
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.js
index 2c72c558e..e494321a9 100644
--- a/apps/web/src/common/selectionoptions.js
+++ b/apps/web/src/common/selectionoptions.js
@@ -23,7 +23,7 @@ function createOption(key, title, icon, onClick) {
onClick: async () => {
await onClick.call(this, selectionStore.get());
selectionStore.toggleSelectionMode(false);
- appStore.setProcessingStatus();
+ appStore.setProcessingStatus(key);
},
};
}
@@ -47,7 +47,7 @@ const DeleteOption = createOption(
const statusText = `${
item.dateDeleted ? `Permanently deleting` : `Deleting`
} ${state.selectedItems.length} items...`;
- appStore.setProcessingStatus(statusText);
+ appStore.setProcessingStatus("deleteOption", statusText);
var isAnyNoteOpened = false;
const items = state.selectedItems.map((item) => {
@@ -87,6 +87,7 @@ const UnfavoriteOption = createOption(
Icon.Star,
function (state) {
appStore.setProcessingStatus(
+ "unfavoriteOption",
`Unfavoriting ${state.selectedItems.length} notes...`
);
@@ -105,6 +106,7 @@ const AddToNotebookOption = createOption(
Icon.AddToNotebook,
async function (state) {
appStore.setProcessingStatus(
+ "atnOption",
`Adding ${state.selectedItems.length} notes to notebooks...`
);
@@ -120,6 +122,7 @@ const ExportOption = createOption(
Icon.Export,
async function (state) {
appStore.setProcessingStatus(
+ "exportOption",
`Exporting ${state.selectedItems.length} notes...`
);
@@ -136,6 +139,7 @@ const RestoreOption = createOption(
Icon.Restore,
async function (state) {
appStore.setProcessingStatus(
+ "restoreOption",
`Restoring ${state.selectedItems.length} items...`
);
diff --git a/apps/web/src/components/editor/editor.css b/apps/web/src/components/editor/editor.css
index e5e539644..67aeda9f5 100644
--- a/apps/web/src/components/editor/editor.css
+++ b/apps/web/src/components/editor/editor.css
@@ -92,3 +92,122 @@
.mce-content-body hr {
border-color: #b1b1b1 !important;
}
+
+span.attachment {
+ overflow: hidden;
+ position: relative;
+ z-index: 1;
+ user-select: none;
+ display: inline-flex;
+ align-items: center;
+ background-color: var(--bgSecondary);
+ padding: 0px 5px 0px 22px;
+ border-radius: 5px;
+ border: 1px solid var(--border);
+ font-size: 0.85rem;
+ cursor: pointer !important;
+}
+
+span.attachment::before {
+ display: inline-block;
+ z-index: -1;
+ position: absolute;
+ top: 0;
+ left: 0;
+ content: "";
+ width: var(--progress, 0px);
+ height: 100%;
+
+ transition: width 100ms ease-in;
+
+ background-size: 15px 15px;
+ background-repeat: no-repeat;
+ background-position: 5px 1.5px;
+ background-color: var(--border);
+}
+
+span.attachment:hover {
+ background-color: var(--hover);
+}
+
+span.attachment:not([data-progress])::after {
+ content: attr(data-size);
+ color: var(--fontTertiary);
+ margin-left: 5px;
+ font-size: 0.7rem;
+}
+
+span.attachment[data-progress]::after {
+ content: attr(data-progress);
+ color: var(--fontTertiary);
+ margin-left: 5px;
+ font-size: 0.7rem;
+}
+
+span.attachment em::before {
+ content: "";
+ position: absolute;
+ width: 15px;
+ height: 15px;
+ left: 5px;
+ top: 1.5px;
+ background-color: var(--text);
+ mask-size: 15px 15px;
+ mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M7.5,18A5.5,5.5 0 0,1 2,12.5A5.5,5.5 0 0,1 7.5,7H18A4,4 0 0,1 22,11A4,4 0 0,1 18,15H9.5A2.5,2.5 0 0,1 7,12.5A2.5,2.5 0 0,1 9.5,10H17V11.5H9.5A1,1 0 0,0 8.5,12.5A1,1 0 0,0 9.5,13.5H18A2.5,2.5 0 0,0 20.5,11A2.5,2.5 0 0,0 18,8.5H7.5A4,4 0 0,0 3.5,12.5A4,4 0 0,0 7.5,16.5H17V18H7.5Z'%3E%3C/path%3E%3C/svg%3E");
+}
+
+img {
+ border-radius: 5px;
+ max-width: 100% !important;
+ height: auto !important;
+ background-color: var(--bgSecondary);
+}
+
+img[style="float: right;"] {
+ margin-left: 10px;
+}
+
+img[style="float: left;"] {
+ margin-right: 10px;
+}
+
+iframe {
+ max-width: 100% !important;
+}
+
+table {
+ display: block !important;
+ overflow-x: auto !important;
+ white-space: nowrap !important;
+ max-width: 100% !important;
+ width: 100% !important;
+ height: auto !important;
+}
+
+td {
+ min-width: 20vw !important;
+}
+
+.mce-content-body [data-mce-selected] {
+ outline: none !important;
+ box-shadow: 0px 0px 0px 2px var(--primary);
+}
+
+.mce-content-body div.mce-resizehandle {
+ background-color: transparent !important;
+ border-color: transparent !important;
+ border-radius: 50px;
+ width: 15px !important;
+ height: 15px !important;
+}
+
+::-moz-selection {
+ /* Code for Firefox */
+ color: var(--fontSecondary);
+ background: var(--primary);
+}
+
+::selection {
+ color: var(--fontSecondary);
+ background: var(--primary);
+}
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 15806a412..4592d08eb 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -13,6 +13,7 @@ import useMobile from "../../utils/use-mobile";
import useTablet from "../../utils/use-tablet";
import Toolbar from "./toolbar";
import EditorLoading from "./loading";
+import { db } from "../../common/db";
const ReactMCE = React.lazy(() => import("./tinymce"));
@@ -57,17 +58,20 @@ function Editor({ noteId, nonce }) {
if (sessionState === SESSION_STATES.new) {
editorstore.set((state) => (state.session.state = SESSION_STATES.stale));
const {
+ id,
content: { data },
} = editorstore.get().session;
const editor = editorRef.current?.editor;
if (!editor) return;
- function setContents() {
+ async function setContents() {
// NOTE: workaround to not fire onEditorChange event on content load
editor.isLoading = true;
editor.setContent(data, { format: "html" });
editor.undoManager.reset();
editor.setDirty(false);
+
+ await db.attachments.download(id);
}
if (!isMobile) editor.focus();
diff --git a/apps/web/src/components/editor/plugins/attachments.js b/apps/web/src/components/editor/plugins/attachments.js
new file mode 100644
index 000000000..d0fb6cdce
--- /dev/null
+++ b/apps/web/src/components/editor/plugins/attachments.js
@@ -0,0 +1,78 @@
+function register(editor) {
+ editor.addCommand("mceAttachImage", function (image) {
+ insertImage(editor, image);
+ });
+
+ editor.addCommand("mceAttachFile", function (file) {
+ insertFile(editor, file);
+ });
+
+ editor.addCommand("mceReplaceImage", function (image) {
+ const { hash, src } = image;
+ console.log("mceReplaceImage", hash, src);
+ const element = editor.dom.$(`img[data-hash="${hash}"]`);
+ if (!element || !src || !hash) return;
+ element.attr("src", src);
+ });
+
+ editor.addCommand("mceUpdateAttachmentProgress", function (progressState) {
+ const { hash, total, loaded } = progressState;
+ const element = document.querySelector(
+ `span.attachment[data-hash="${hash}"]`
+ );
+ if (!element || !total || !loaded) return;
+ if (total === loaded) {
+ element.removeAttribute("data-progress");
+ element.style.removeProperty("--progress");
+ } else {
+ const percent = Math.round((loaded / total) * 100);
+ element.setAttribute("data-progress", `${percent}%`);
+ element.style.setProperty("--progress", `${percent}%`);
+ }
+ });
+}
+
+async function insertImage(editor, image) {
+ var content = `
+ <img class="attachment"
+ alt="${image.filename || image.hash}"
+ data-mime="${image.type}"
+ data-hash="${image.hash}"
+ data-filename="${image.filename}"
+ src="${image.dataurl}"
+ data-size="${image.size}"
+ style="float: left;"/>`;
+ editor.insertContent(content);
+}
+
+async function insertFile(editor, file) {
+ var content = `
+ <span
+ class="attachment"
+ contenteditable="false"
+ title="${file.filename}"
+ data-mime="${file.type}"
+ data-filename="${file.filename}"
+ data-hash="${file.hash}"
+ data-size="${formatBytes(file.size, 1)}">
+ <em>&nbsp;</em>
+ ${file.filename}
+ </span>`;
+ editor.insertContent(content);
+}
+
+function formatBytes(bytes, decimals = 2) {
+ if (bytes === 0) return "0B";
+
+ const k = 1024;
+ const dm = decimals < 0 ? 0 : decimals;
+ const sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
+
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
+
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i];
+}
+
+(function init() {
+ global.tinymce.PluginManager.add("attachments", register);
+})();
diff --git a/apps/web/src/components/editor/plugins/attachmentpicker.js b/apps/web/src/components/editor/plugins/picker.js
similarity index 83%
rename from apps/web/src/components/editor/plugins/attachmentpicker.js
rename to apps/web/src/components/editor/plugins/picker.js
index 57a23ef32..5e1728451 100644
--- a/apps/web/src/components/editor/plugins/attachmentpicker.js
+++ b/apps/web/src/components/editor/plugins/picker.js
@@ -14,30 +14,22 @@ function register(editor) {
tooltip: "Insert image",
onAction: () => insertImage(editor),
});
-
- editor.addCommand("InsertImage", function () {
- insertImage(editor);
- });
}
async function insertImage(editor) {
const image = await pickImage();
if (!image) return;
-
- var content = `<img class="attachment" data-mime="${image.type}" data-hash="${image.hash}" data-filename="${image.filename}" src="${image.dataurl}" data-size="${image.size}"/>`;
- editor.insertContent(content);
+ editor.execCommand("mceAttachImage", image);
}
async function insertFile(editor) {
const file = await pickFile();
if (!file) return;
-
- var content = `<span class="attachment" data-mime="${file.type}" data-filename="${file.filename}" data-hash="${file.hash}" data-size="${file.size}"/>`;
- editor.insertContent(content);
+ editor.execCommand("mceAttachFile", file);
}
(function init() {
- global.tinymce.PluginManager.add("attachmentpicker", register);
+ global.tinymce.PluginManager.add("picker", register);
})();
async function pickFile() {
@@ -89,7 +81,7 @@ async function pickImage() {
hash: output.hash,
filename: selectedImage.name,
type: selectedImage.type,
- size: output.length,
+ size: selectedImage.length,
dataurl,
};
}
@@ -97,7 +89,7 @@ async function pickImage() {
async function getEncryptionKey() {
const key = await db.user.getEncryptionKey();
if (!key) throw new Error("No encryption key found. Are you logged in?");
- return key;
+ return key; // { password: "helloworld" };
}
/**
@@ -128,7 +120,8 @@ function compressImage(file, type) {
new Compressor(file, {
quality: 0.8,
mimeType: file.type,
- width: 1920,
+ maxWidth: 2000,
+ maxHeight: 2000,
/**
*
* @param {Blob} result
diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.js
index 9ea92bc13..23df86b51 100644
--- a/apps/web/src/components/editor/tinymce.js
+++ b/apps/web/src/components/editor/tinymce.js
@@ -8,7 +8,6 @@ import "tinymce/icons/default";
import "tinymce/themes/silver";
import "tinymce/plugins/table";
import "tinymce/plugins/autoresize";
-import "tinymce/plugins/quickbars";
import "tinymce/plugins/searchreplace";
import "tinymce/plugins/lists";
import "tinymce/plugins/advlist";
@@ -30,7 +29,8 @@ import "@streetwritersco/tinymce-plugins/collapsibleheaders";
import "@streetwritersco/tinymce-plugins/paste";
import "@streetwritersco/tinymce-plugins/shortcuts";
import "@streetwritersco/tinymce-plugins/keyboardquirks";
-import "./plugins/attachmentpicker";
+import "./plugins/picker";
+import "./plugins/attachments";
import "./plugins/icons";
import { Editor } from "@tinymce/tinymce-react";
import { showBuyDialog } from "../../common/dialog-controller";
@@ -38,6 +38,8 @@ import { useStore as useThemeStore } from "../../stores/theme-store";
import { isTablet } from "../../utils/dimensions";
import { showToast } from "../../utils/toast";
import { useIsUserPremium } from "../../hooks/use-is-user-premium";
+import { AppEventManager, AppEvents } from "../../common";
+import { EV, EVENTS } from "notes-core/common";
const markdownPatterns = [
{ start: "```", replacement: "<pre></pre>" },
@@ -108,9 +110,9 @@ function useSkin() {
const plugins = {
default:
- "importcss searchreplace autolink directionality media table hr advlist lists imagetools noneditable quickbars autoresize",
+ "importcss searchreplace autolink directionality media table hr advlist lists imagetools noneditable autoresize",
custom:
- "icons keyboardquirks collapsibleheaders shortlink attachmentpicker paste codeblock inlinecode shortcuts checklist",
+ "icons keyboardquirks collapsibleheaders shortlink attachments picker paste codeblock inlinecode shortcuts checklist",
pro: "textpattern",
};
@@ -147,11 +149,38 @@ function TinyMCE(props) {
);
}, [tinymceRef, newSkin, oldSkin]);
+ useEffect(() => {
+ const event = AppEventManager.subscribe(
+ AppEvents.UPDATE_ATTACHMENT_PROGRESS,
+ (progressState) => {
+ tinymceRef.current.editor.execCommand(
+ "mceUpdateAttachmentProgress",
+ progressState
+ );
+ }
+ );
+
+ const mediaAttachmentDownloadedEvent = EV.subscribe(
+ EVENTS.mediaAttachmentDownloaded,
+ (arg) => {
+ console.log("downloaded attachment", arg);
+ tinymceRef.current.editor.execCommand("mceReplaceImage", arg);
+ }
+ );
+ return () => {
+ event.unsubscribe();
+ mediaAttachmentDownloadedEvent.unsubscribe();
+ };
+ }, [tinymceRef]);
+
return (
<Editor
ref={tinymceRef}
onFocus={onFocus}
- onInit={onInit}
+ onInit={(args, editor) => {
+ editor.serializer.addTempAttr("data-progress");
+ onInit(args, editor);
+ }}
initialValue={initialValue}
init={{
//experimental
@@ -168,37 +197,8 @@ function TinyMCE(props) {
],
toolbar_mode: isTablet() ? "scrolling" : "sliding",
contextmenu: false,
- quickbars_insert_toolbar: false,
skin_url: newSkin,
inline_boundaries_selector: "a[href]",
- // content_css: "",
- content_style: `
- pre.codeblock {
- overflow-x: auto;
- }
-
- img {
- max-width:100% !important;
- height:auto !important;
- }
-
- iframe {
- max-width:100% !important;
- }
-
- table {
- display: block !important;
- overflow-x: auto !important;
- white-space: nowrap !important;
- max-width:100% !important;
- width:100% !important;
- height:auto !important;
- }
-
- td {
- min-width:20vw !important;
- }
-`,
toolbar: simple
? false
: `bold italic underline strikethrough inlinecode | blockquote codeblock | fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent subscript superscript | numlist bullist checklist | forecolor backcolor removeformat | hr | image attachment media link table | ltr rtl | searchreplace`,
@@ -212,7 +212,8 @@ function TinyMCE(props) {
placeholder: placeholder || "Start writing your note here...",
target_list: false,
link_title: false,
- imagetools_toolbar: "rotateleft rotateright | flipv fliph",
+ imagetools_toolbar:
+ "rotateleft rotateright | flipv fliph | alignleft aligncenter alignright",
setup: (editor) => {
editor.on("ScrollIntoView", (e) => {
e.preventDefault();
@@ -231,6 +232,9 @@ function TinyMCE(props) {
const { node } = args;
processPastedContent(node);
},
+ invalid_styles: {
+ span: "--progress",
+ },
}}
onBeforeExecCommand={async (command) => {
const isPremiumCommand = premiumCommands.some((cmd) => {
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index 4525cb942..070f38d06 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -17,7 +17,9 @@ function StatusBar() {
const lastSynced = useAppStore((state) => state.lastSynced);
const isLoggedIn = useUserStore((state) => state.isLoggedIn);
const isSyncing = useAppStore((state) => state.isSyncing);
- const processingStatus = useAppStore((state) => state.processingStatus);
+ const processingStatuses = useAppStore((state) =>
+ Object.values(state.processingStatuses)
+ );
const updateStatus = useAutoUpdater();
return (
@@ -80,14 +82,14 @@ function StatusBar() {
</Text>
</Button>
)}
- {processingStatus && (
+ {processingStatuses?.map(({ status, progress }) => (
<Flex ml={1} alignItems="center" justifyContent="center">
<Icon.Loading size={12} />
<Text variant="subBody" color="bgSecondaryText" ml={1}>
- {processingStatus}
+ {progress ? `${progress}% ${status}` : status}
</Text>
</Flex>
- )}
+ ))}
{updateStatus && (
<Button
diff --git a/apps/web/src/interfaces/fs.js b/apps/web/src/interfaces/fs.js
index 0b8a0fdc8..01c89239f 100644
--- a/apps/web/src/interfaces/fs.js
+++ b/apps/web/src/interfaces/fs.js
@@ -2,7 +2,9 @@ import NNCrypto from "./nncrypto/index";
import localforage from "localforage";
import { xxhash3 } from "hash-wasm";
import axios from "axios";
+import { AppEventManager, AppEvents } from "../common";
+const PLACEHOLDER = `data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMzUuNDcgMTM1LjQ3Ij48ZyBmaWxsPSJncmF5Ij48cGF0aCBkPSJNNjUuNjMgNjUuODZhNC40OCA0LjQ4IDAgMSAwLS4wMS04Ljk2IDQuNDggNC40OCAwIDAgMCAwIDguOTZ6bTAtNi4zM2ExLjg1IDEuODUgMCAxIDEgMCAzLjcgMS44NSAxLjg1IDAgMCAxIDAtMy43em0wIDAiLz48cGF0aCBkPSJNODguNDkgNDguNTNINDYuOThjLS45IDAtMS42NC43My0xLjY0IDEuNjRWODUuM2MwIC45Ljc0IDEuNjQgMS42NCAxLjY0aDQxLjVjLjkxIDAgMS42NC0uNzQgMS42NC0xLjY0VjUwLjE3YzAtLjktLjczLTEuNjQtMS42My0xLjY0Wm0tLjk5IDIuNjJ2MjAuNzdsLTguMjUtOC4yNWExLjM4IDEuMzggMCAwIDAtMS45NSAwTDY1LjYzIDc1LjM0bC03LjQ2LTcuNDZhMS4zNyAxLjM3IDAgMCAwLTEuOTUgMGwtOC4yNSA4LjI1VjUxLjE1Wk00Ny45NyA4NC4zMXYtNC40N2w5LjIyLTkuMjIgNy40NiA3LjQ1YTEuMzcgMS4zNyAwIDAgMCAxLjk1IDBMNzguMjcgNjYuNGw5LjIzIDkuMjN2OC42OHptMCAwIi8+PC9nPjwvc3ZnPg==`;
const crypto = new NNCrypto();
const fs = localforage.createInstance({
storeName: "notesnook-fs",
@@ -57,8 +59,10 @@ async function readEncrypted(filename, key, cipherData) {
console.log("Reading encrypted file", filename);
const readAsBuffer = localforage.supports(localforage.INDEXEDDB);
cipherData.cipher = await fs.getItem(filename);
- if (!cipherData.cipher)
- throw new Error(`File not found. Filename: ${filename}`);
+ if (!cipherData.cipher) {
+ console.error(`File not found. Filename: ${filename}`);
+ return PLACEHOLDER;
+ }
return readAsBuffer
? await crypto.decryptBinary(key, cipherData, cipherData.outputType)
@@ -85,6 +89,12 @@ async function uploadFile(filename, requestOptions) {
data: new Blob([cipher.buffer]),
onUploadProgress: (ev) => {
console.log("Uploading file", filename, ev);
+ AppEventManager.publish(AppEvents.UPDATE_ATTACHMENT_PROGRESS, {
+ type: "upload",
+ hash: filename,
+ total: ev.total,
+ loaded: ev.loaded,
+ });
},
});
@@ -102,6 +112,12 @@ async function downloadFile(filename, requestOptions) {
responseType: "blob",
onDownloadProgress: (ev) => {
console.log("Downloading file", filename, ev);
+ AppEventManager.publish(AppEvents.UPDATE_ATTACHMENT_PROGRESS, {
+ type: "download",
+ hash: filename,
+ total: ev.total,
+ loaded: ev.loaded,
+ });
},
});
console.log("File downloaded", filename, url, response);
@@ -124,12 +140,17 @@ async function deleteFile(filename, requestOptions) {
return result;
}
+function exists(filename) {
+ return fs.hasItem(filename);
+}
+
const FS = {
writeEncrypted,
readEncrypted,
uploadFile,
downloadFile,
deleteFile,
+ exists,
};
export default FS;
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 6a5525eb1..fad5849ad 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -16,7 +16,7 @@ class AppStore extends BaseStore {
isFocusMode = false;
isEditorOpen = false;
isVaultCreated = false;
- processingStatus = undefined;
+ processingStatuses = {};
colors = [];
globalMenu = { items: [], data: {} };
reminders = [];
@@ -66,8 +66,11 @@ class AppStore extends BaseStore {
this.set((state) => (state.isVaultCreated = toggleState));
};
- setProcessingStatus = (status) => {
- this.set((state) => (state.processingStatus = status));
+ setProcessingStatus = (key, status, progress) => {
+ this.set((state) => {
+ if (!status) delete state.processingStatuses[key];
+ else state.processingStatuses[key] = { status, progress };
+ });
};
/**
diff --git a/apps/web/src/theme/colorscheme/dark.js b/apps/web/src/theme/colorscheme/dark.js
index ce880604b..3a95f3924 100644
--- a/apps/web/src/theme/colorscheme/dark.js
+++ b/apps/web/src/theme/colorscheme/dark.js
@@ -11,8 +11,8 @@ class DarkColorSchemeFactory {
bgSecondary: "#2b2b2b",
bgSecondaryText: "#A1A1A1",
bgSecondaryPrimary: "#00AA46",
- border: "#2b2b2b",
- hover: "#3b3b3b",
+ border: "#3b3b3b",
+ hover: "#1b1b1b",
fontSecondary: "#000",
fontTertiary: "#A1A1A1",
text: "#d3d3d3",
diff --git a/apps/web/src/theme/colorscheme/light.js b/apps/web/src/theme/colorscheme/light.js
index bda7e7afb..e60b5a334 100644
--- a/apps/web/src/theme/colorscheme/light.js
+++ b/apps/web/src/theme/colorscheme/light.js
@@ -10,10 +10,10 @@ class LightColorSchemeFactory {
bgSecondary: "#f7f7f7",
bgSecondaryText: "#5E5E5E",
bgSecondaryPrimary: "#008234",
- border: "#e7e7e7",
- hover: "#f1f1f1",
+ border: "#d7d7d7",
+ hover: "#e7e7e7",
fontSecondary: "white",
- fontTertiary: "#757575",
+ fontTertiary: "#656565",
text: "#202124",
overlay: "rgba(0, 0, 0, 0.1)",
secondary: "white",