diff --git a/apps/web/src/common/index.ts b/apps/web/src/common/index.ts
index 47c1a83cb..9c26c0201 100644
--- a/apps/web/src/common/index.ts
+++ b/apps/web/src/common/index.ts
@@ -41,7 +41,7 @@ import { createWritableStream } from "./desktop-bridge";
import { createZipStream } from "../utils/streams/zip-stream";
import { FeatureKeys } from "../dialogs/feature-dialog";
import { ZipEntry, createUnzipIterator } from "../utils/streams/unzip-stream";
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
import { LegacyBackupFile } from "@notesnook/core";
import { useEditorStore } from "../stores/editor-store";
diff --git a/apps/web/src/components/diff-viewer/index.tsx b/apps/web/src/components/diff-viewer/index.tsx
index db3a59431..3e170b5fa 100644
--- a/apps/web/src/components/diff-viewer/index.tsx
+++ b/apps/web/src/components/diff-viewer/index.tsx
@@ -187,7 +187,6 @@ function DiffViewer(props: DiffViewerProps) {
unlock={async (password) => {
const decryptedContent = await db.vault.decryptContent(
content,
- session.note.id,
password
);
setContent({
@@ -271,7 +270,6 @@ function DiffViewer(props: DiffViewerProps) {
unlock={async (password) => {
const decryptedContent = await db.vault.decryptContent(
conflictedContent,
- session.note.id,
password
);
setConflictedContent({
diff --git a/apps/web/src/components/editor/header.tsx b/apps/web/src/components/editor/header.tsx
index f5a809f62..5bae59888 100644
--- a/apps/web/src/components/editor/header.tsx
+++ b/apps/web/src/components/editor/header.tsx
@@ -34,7 +34,9 @@ import { Tag } from "@notesnook/core";
type HeaderProps = { readonly: boolean; id: string };
function Header(props: HeaderProps) {
const { readonly, id } = props;
- const tags = useEditorStore((store) => store.getSession(id)?.tags || []);
+ const tags = useEditorStore(
+ (store) => store.getSession(id, ["default", "readonly"])?.tags || []
+ );
const refreshTags = useEditorStore((store) => store.refreshTags);
useEffect(() => {
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 92aa2bcaa..6642802e2 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -151,7 +151,7 @@ function EditorView({ id }: { id: string }) {
const isTOCVisible = useEditorStore((store) => store.isTOCVisible);
const toggleProperties = useEditorStore((store) => store.toggleProperties);
const isReadonly = useEditorStore(
- (store) => store.getSession(id, ["default"])?.note?.readonly
+ (store) => store.getSession(id, ["default", "readonly"])?.note?.readonly
);
const isFocusMode = useAppStore((store) => store.isFocusMode);
const isPreviewSession = !!previewSession.current;
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx
index c9cf62b2d..a642e0793 100644
--- a/apps/web/src/components/editor/title-box.tsx
+++ b/apps/web/src/components/editor/title-box.tsx
@@ -62,7 +62,7 @@ function TitleBox(props: TitleBoxProps) {
useEffect(() => {
const session = useEditorStore.getState().getSession(id);
- if (!session || !session.note) return;
+ if (!session || !("note" in session) || !session.note) return;
const { title } = session.note;
if (!inputRef.current) return;
diff --git a/apps/web/src/components/status-bar/index.tsx b/apps/web/src/components/status-bar/index.tsx
index 77be318c4..1cb7146df 100644
--- a/apps/web/src/components/status-bar/index.tsx
+++ b/apps/web/src/components/status-bar/index.tsx
@@ -42,7 +42,7 @@ import useStatus, { statusToString } from "../../hooks/use-status";
import { ScopedThemeProvider } from "../theme-provider";
import { checkForUpdate, installUpdate } from "../../utils/updater";
import { getTimeAgo, toTitleCase } from "@notesnook/common";
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
function StatusBar() {
const user = useUserStore((state) => state.user);
diff --git a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
index e7cc3ac70..8ba06d06e 100644
--- a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
+++ b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
@@ -44,7 +44,7 @@ import { isUserSubscribed } from "../../hooks/use-is-user-premium";
import { SUBSCRIPTION_STATUS } from "../../common/constants";
import BaseDialog from "../../components/dialog";
import { ScopedThemeProvider } from "../../components/theme-provider";
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
type BuyDialogProps = {
couponCode?: string;
diff --git a/apps/web/src/dialogs/mfa/multi-factor-dialog.tsx b/apps/web/src/dialogs/mfa/multi-factor-dialog.tsx
index 7d43c97b1..c33ba9773 100644
--- a/apps/web/src/dialogs/mfa/multi-factor-dialog.tsx
+++ b/apps/web/src/dialogs/mfa/multi-factor-dialog.tsx
@@ -30,7 +30,7 @@ import {
} from "./steps";
import { Authenticator, OnNextFunction } from "./types";
import { ErrorText } from "../../components/error-text";
-import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
+import { AuthenticatorType } from "@notesnook/core";
type MultifactorDialogProps = {
onClose: Perform;
diff --git a/apps/web/src/dialogs/mfa/recovery-code-dialog.tsx b/apps/web/src/dialogs/mfa/recovery-code-dialog.tsx
index d4d8eb43b..3dccfd3fa 100644
--- a/apps/web/src/dialogs/mfa/recovery-code-dialog.tsx
+++ b/apps/web/src/dialogs/mfa/recovery-code-dialog.tsx
@@ -22,7 +22,7 @@ import { Perform } from "../../common/dialog-controller";
import Dialog from "../../components/dialog";
import { steps } from "./steps";
import { ErrorText } from "../../components/error-text";
-import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
+import { AuthenticatorType } from "@notesnook/core";
type RecoveryCodesDialogProps = {
onClose: Perform;
diff --git a/apps/web/src/dialogs/mfa/steps.tsx b/apps/web/src/dialogs/mfa/steps.tsx
index 75fa3b90c..a1c403d4a 100644
--- a/apps/web/src/dialogs/mfa/steps.tsx
+++ b/apps/web/src/dialogs/mfa/steps.tsx
@@ -57,7 +57,7 @@ import {
} from "./types";
import { showMultifactorDialog } from "../../common/dialog-controller";
import { ErrorText } from "../../components/error-text";
-import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
+import { AuthenticatorType } from "@notesnook/core";
const QRCode = React.lazy(() => import("../../re-exports/react-qrcode-logo"));
diff --git a/apps/web/src/dialogs/mfa/types.ts b/apps/web/src/dialogs/mfa/types.ts
index be2e81356..46ff648f0 100644
--- a/apps/web/src/dialogs/mfa/types.ts
+++ b/apps/web/src/dialogs/mfa/types.ts
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
+import { AuthenticatorType } from "@notesnook/core";
import { Perform } from "../../common/dialog-controller";
import { Icon } from "../../components/icons";
diff --git a/apps/web/src/dialogs/settings/backup-export-settings.ts b/apps/web/src/dialogs/settings/backup-export-settings.ts
index 48b02f01e..0d48c340c 100644
--- a/apps/web/src/dialogs/settings/backup-export-settings.ts
+++ b/apps/web/src/dialogs/settings/backup-export-settings.ts
@@ -103,8 +103,11 @@ export const BackupExportSettings: SettingsGroup[] = [
description: "Encrypt all backup files using your master key.",
isHidden: () => !useUserStore.getState().isLoggedIn,
onStateChange: (listener) => {
- useUserStore.subscribe((s) => s.isLoggedIn, listener);
- useSettingStore.subscribe((s) => s.encryptBackups, listener);
+ const subscriptions = [
+ useUserStore.subscribe((s) => s.isLoggedIn, listener),
+ useSettingStore.subscribe((s) => s.encryptBackups, listener)
+ ];
+ return () => subscriptions.forEach((s) => s());
},
components: [
{
diff --git a/apps/web/src/dialogs/settings/behaviour-settings.ts b/apps/web/src/dialogs/settings/behaviour-settings.ts
index d58f4eeb2..cbc82822c 100644
--- a/apps/web/src/dialogs/settings/behaviour-settings.ts
+++ b/apps/web/src/dialogs/settings/behaviour-settings.ts
@@ -22,6 +22,8 @@ import { SettingsGroup } from "./types";
import { useStore as useSettingStore } from "../../stores/setting-store";
import dayjs from "dayjs";
import { isUserPremium } from "../../hooks/use-is-user-premium";
+import { TimeFormat } from "@notesnook/core/dist/utils/date";
+import { TrashCleanupInterval } from "@notesnook/core";
export const BehaviourSettings: SettingsGroup[] = [
{
@@ -91,7 +93,7 @@ export const BehaviourSettings: SettingsGroup[] = [
{
type: "dropdown",
onSelectionChanged: (value) =>
- useSettingStore.getState().setTimeFormat(value),
+ useSettingStore.getState().setTimeFormat(value as TimeFormat),
selectedOption: () => useSettingStore.getState().timeFormat,
options: [
{ value: "12-hour", title: "12h" },
@@ -121,7 +123,9 @@ export const BehaviourSettings: SettingsGroup[] = [
onSelectionChanged: (value) =>
useSettingStore
.getState()
- .setTrashCleanupInterval(parseInt(value)),
+ .setTrashCleanupInterval(
+ parseInt(value) as TrashCleanupInterval
+ ),
selectedOption: () =>
useSettingStore.getState().trashCleanupInterval.toString(),
options: [
diff --git a/apps/web/src/dialogs/settings/types.ts b/apps/web/src/dialogs/settings/types.ts
index 37f48f048..5531c9916 100644
--- a/apps/web/src/dialogs/settings/types.ts
+++ b/apps/web/src/dialogs/settings/types.ts
@@ -145,5 +145,5 @@ export type TextInputSettingComponent = BaseSettingComponent<"input"> & {
};
export type CustomSettingComponent = BaseSettingComponent<"custom"> & {
- component: () => JSX.Element;
+ component: () => JSX.Element | null;
};
diff --git a/apps/web/src/hooks/use-is-user-premium.ts b/apps/web/src/hooks/use-is-user-premium.ts
index 5d8994e76..4660ac583 100644
--- a/apps/web/src/hooks/use-is-user-premium.ts
+++ b/apps/web/src/hooks/use-is-user-premium.ts
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
import { SUBSCRIPTION_STATUS } from "../common/constants";
import {
useStore as useUserStore,
@@ -30,7 +30,6 @@ export function useIsUserPremium() {
}
export function isUserPremium(user?: User) {
- return true;
if (IS_TESTING) return true;
if (!user) user = userstore.get().user;
if (!user) return false;
diff --git a/apps/web/src/interfaces/storage.ts b/apps/web/src/interfaces/storage.ts
index f9b03b1ba..c347c0efd 100644
--- a/apps/web/src/interfaces/storage.ts
+++ b/apps/web/src/interfaces/storage.ts
@@ -28,7 +28,7 @@ import { NNCrypto } from "./nncrypto";
import type { Cipher, SerializedKey } from "@notesnook/crypto/dist/src/types";
import { isFeatureSupported } from "../utils/feature-check";
import { IKeyStore } from "./key-store";
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
type EncryptedKey = { iv: Uint8Array; cipher: BufferSource };
export type DatabasePersistence = "memory" | "db";
diff --git a/apps/web/src/stores/app-store.ts b/apps/web/src/stores/app-store.ts
index 48c5ad004..35e9464ce 100644
--- a/apps/web/src/stores/app-store.ts
+++ b/apps/web/src/stores/app-store.ts
@@ -316,8 +316,9 @@ class AppStore extends BaseStore {
logger.error(err);
if (err.cause === "MERGE_CONFLICT") {
- const sessionId = editorstore.get().session.id;
- if (sessionId) await editorstore.openSession(sessionId, true);
+ // TODO: reopen conflicted note
+ // const sessionId = editorstore.get().session.id;
+ // if (sessionId) await editorstore.openSession(sessionId, true);
await this.refresh();
this.updateSyncStatus("conflicts");
} else {
diff --git a/apps/web/src/stores/attachment-store.ts b/apps/web/src/stores/attachment-store.ts
index d30cb950f..d77f81565 100644
--- a/apps/web/src/stores/attachment-store.ts
+++ b/apps/web/src/stores/attachment-store.ts
@@ -122,14 +122,14 @@ class AttachmentStore extends BaseStore {
if (await db.attachments.remove(attachment.hash, false)) {
await this.get().refresh();
- const sessionId = useEditorStore.getState().session.id;
+ const session = useEditorStore.getState().getActiveSession(); //.id;
if (
- sessionId &&
+ session &&
(await db.relations
.to({ id: attachment.id, type: "attachment" }, "note")
- .has(sessionId))
+ .has(session.id))
) {
- await useEditorStore.getState().clearSession();
+ useEditorStore.getState().closeSessions(session.id);
}
}
} catch (e) {
diff --git a/apps/web/src/stores/note-store.ts b/apps/web/src/stores/note-store.ts
index 7ca46a714..8bb8c6afb 100644
--- a/apps/web/src/stores/note-store.ts
+++ b/apps/web/src/stores/note-store.ts
@@ -71,8 +71,10 @@ class NoteStore extends BaseStore {
};
delete = async (...ids: string[]) => {
- const { session, clearSession } = useEditorStore.getState();
- if (session.id && ids.indexOf(session.id) > -1) await clearSession();
+ const { closeSessions, getActiveSession } = useEditorStore.getState();
+ const session = getActiveSession();
+ if (session && session.id && ids.indexOf(session.id) > -1)
+ closeSessions(session.id);
await db.notes.moveToTrash(...ids);
await this.refresh();
};
@@ -91,7 +93,7 @@ class NoteStore extends BaseStore {
unlock = async (id: string) => {
return await Vault.unlockNote(id).then(async (res) => {
- if (useEditorStore.getState().session.id === id)
+ if (useEditorStore.getState().getActiveSession()?.id === id)
await useEditorStore.getState().openSession(id);
await this.refresh();
return res;
@@ -101,7 +103,7 @@ class NoteStore extends BaseStore {
lock = async (id: string) => {
if (!(await Vault.lockNote(id))) return false;
await this.refresh();
- if (useEditorStore.getState().session.id === id)
+ if (useEditorStore.getState().getActiveSession()?.id === id)
await useEditorStore.getState().openSession(id, true);
};
@@ -142,8 +144,9 @@ class NoteStore extends BaseStore {
action: "favorite" | "pinned" | "readonly" | "localOnly" | "color",
value: boolean | string
) => {
- const { session, toggle } = useEditorStore.getState();
- if (!session.id || !noteIds.includes(session.id)) return false;
+ const { getActiveSession, toggle } = useEditorStore.getState();
+ const session = getActiveSession();
+ if (!session || !session.id || !noteIds.includes(session.id)) return false;
toggle(session.id, action, value);
return true;
};
diff --git a/apps/web/src/stores/setting-store.ts b/apps/web/src/stores/setting-store.ts
index 57cea3f9d..e45928516 100644
--- a/apps/web/src/stores/setting-store.ts
+++ b/apps/web/src/stores/setting-store.ts
@@ -181,7 +181,9 @@ class SettingStore extends BaseStore {
this.set({ hideNoteTitle: !hideNoteTitle });
Config.set("hideNoteTitle", !hideNoteTitle);
setDocumentTitle(
- !hideNoteTitle ? undefined : useEditorStore.getState().session.title
+ !hideNoteTitle
+ ? undefined
+ : useEditorStore.getState().getActiveSession()?.title
);
};
diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsx
index c354aaaa3..45dfa254f 100644
--- a/apps/web/src/views/auth.tsx
+++ b/apps/web/src/views/auth.tsx
@@ -43,7 +43,7 @@ import {
showLogoutConfirmation
} from "../common/dialog-controller";
import { ErrorText } from "../components/error-text";
-import { AuthenticatorType, User } from "@notesnook/core/dist/api/user-manager";
+import { AuthenticatorType, User } from "@notesnook/core";
type EmailFormData = {
email: string;
diff --git a/apps/web/src/views/recovery.tsx b/apps/web/src/views/recovery.tsx
index 4755cf035..3543115f7 100644
--- a/apps/web/src/views/recovery.tsx
+++ b/apps/web/src/views/recovery.tsx
@@ -31,7 +31,7 @@ import { showRecoveryKeyDialog } from "../common/dialog-controller";
import Config from "../utils/config";
import { EVENTS } from "@notesnook/core/dist/common";
import { ErrorText } from "../components/error-text";
-import { User } from "@notesnook/core/dist/api/user-manager";
+import { User } from "@notesnook/core";
type RecoveryMethodType = "key" | "backup" | "reset";
type RecoveryMethodsFormData = Record;