Skip to content

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

fix: simplify user data access

thecodrrc0e61df4e3d7
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index de05a5524..2bb33e3cc 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -5,6 +5,7 @@ import EventSource from "eventsource";
import { navigate } from "hookrouter";
export const db = new Database(StorageInterface, EventSource);
+db.host("http://localhost:8000");
export const COLORS = {
red: "#f44336",
@@ -16,6 +17,14 @@ export const COLORS = {
gray: "#9E9E9E",
};
+export const SUBSCRIPTION_STATUS = {
+ EXPIRED: 0,
+ TRIAL: 1,
+ ACTIVE: 2,
+ ACTIVE_RENEWING: 3,
+ CANCELLED: 4,
+};
+
export const SELECTION_OPTIONS_MAP = {
notes: SelectionOptions.NotesOptions,
notebooks: SelectionOptions.NotebooksOptions,
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 758bcb180..694054b39 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -18,6 +18,7 @@ import SplitEditor from "../spliteditor";
import Unlock from "../unlock";
import RouteContainer from "../route-container";
import useMobile from "../../utils/use-mobile";
+import { SUBSCRIPTION_STATUS } from "../../common";
function Editor() {
const sessionState = useStore((store) => store.session.state);
@@ -29,7 +30,7 @@ function Editor() {
const isFocusMode = useAppStore((store) => store.isFocusMode);
const isMobile = useMobile();
const isTrial = useUserStore(
- (store) => store.user?.notesnook?.subscription?.isTrial
+ (store) => store.user?.subscription?.status === SUBSCRIPTION_STATUS.TRIAL
);
const isLoggedin = useUserStore((store) => store.isLoggedIn);
@@ -99,7 +100,7 @@ function Editor() {
id="quill"
ref={quillRef}
refresh={sessionState === SESSION_STATES.new}
- isSimple={isLoggedin || !isTrial}
+ isSimple={isLoggedin && !isTrial}
onFocus={() => {
toggleProperties(false);
}}
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 8f7dec714..0a1364e16 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -1,10 +1,11 @@
import React from "react";
import { Flex, Box, Text } from "rebass";
+import { SUBSCRIPTION_STATUS } from "../../common";
import { useStore as useUserStore } from "../../stores/user-store";
function Menu(props) {
const isTrial = useUserStore(
- (store) => store.user?.notesnook?.subscription?.isTrial
+ (store) => store.user?.subscription?.status === SUBSCRIPTION_STATUS.TRIAL
);
return (
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 8352f912e..05044cf07 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -20,11 +20,10 @@ class UserStore extends BaseStore {
});
db.ev.subscribe("db:refresh", () => appStore.refresh());
db.ev.subscribe("user:upgraded", (subscription) => {
- console.log("user:upgraded", subscription);
this.set((state) => {
state.user = {
...state.user,
- notesnook: { ...state.user.notesnook, subscription },
+ subscription,
};
});
});
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index d27fe8b22..4638f4ce8 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -9,7 +9,7 @@ import { showLogInDialog } from "../components/dialogs/logindialog";
import { upgrade } from "../common/upgrade";
import useSystemTheme from "../utils/use-system-theme";
import download from "../utils/download";
-import { db } from "../common";
+import { db, SUBSCRIPTION_STATUS } from "../common";
import { usePersistentState } from "../utils/hooks";
function importBackup() {
@@ -54,7 +54,7 @@ function Settings(props) {
const user = useUserStore((store) => store.user);
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
const isTrial = useUserStore(
- (store) => store?.user?.notesnook?.subscription?.isTrial
+ (store) => store?.user?.subscription?.status === SUBSCRIPTION_STATUS.TRIAL
);
const logout = useUserStore((store) => store.logout);
const [backupReminderOffset, setBackupReminderOffset] = usePersistentState(
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 2df6c5559..74c692dea 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -8861,7 +8861,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
version "1.5.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#565bd9d16b03702ed8c0443ad68583461f937b18"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#e65d336a8155a24a3e700594bf4fdeb9198e7cfb"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"