Skip to content

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

feat: implement the new subscription api

thecodrr882802282080
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index c6b7c98bc..fb84d440b 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -16,7 +16,9 @@ function Editor() {
const setSession = useStore((store) => store.setSession);
const saveSession = useStore((store) => store.saveSession);
const isFocusMode = useAppStore((store) => store.isFocusMode);
- const isPremium = useUserStore((store) => store.user.isPremium);
+ const isTrial = useUserStore(
+ (store) => store.user.notesnook?.subscription?.isTrial
+ );
const quillRef = useRef();
useEffect(() => {
@@ -56,7 +58,7 @@ function Editor() {
id="quill"
ref={quillRef}
refresh={sessionState === SESSION_STATES.new}
- isSimple={!isPremium}
+ isSimple={isTrial}
initialContent={delta}
placeholder="Type anything here"
container=".editor"
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 282c3469a..4c6aa61ad 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -4,7 +4,9 @@ import { useStore as useUserStore } from "../../stores/user-store";
function Menu(props) {
const isPremium = useUserStore((store) => store.user.isPremium);
- const isTrialExpired = useUserStore((store) => store.isTrialExpired);
+ const isTrial = useUserStore(
+ (store) => store.user?.notesnook?.subscription?.isTrial
+ );
return (
<Flex
@@ -42,7 +44,8 @@ function Menu(props) {
if (props.closeMenu) {
props.closeMenu();
}
- const onlyPro = item.onlyPro && !isPremium && isTrialExpired;
+
+ const onlyPro = item.onlyPro && isTrial === undefined;
if (onlyPro) {
// TODO
} else if (item.onClick) {
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 6b5e4d9ea..8a752907a 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -10,7 +10,6 @@ class UserStore extends BaseStore {
isLoggingIn = false;
isSigningIn = false;
isSyncing = false;
- isTrialExpired = false;
user = {};
init = () => {
@@ -18,11 +17,17 @@ class UserStore extends BaseStore {
if (!user) return false;
this.set((state) => {
state.user = user;
- state.isTrialExpired = user.trialExpiryDate > Date.now() * 1000;
state.isLoggedIn = true;
});
- db.ev.subscribe("sync", () => {
- this.sync();
+ 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 },
+ };
+ });
});
this.sync();
return true;
diff --git a/apps/web/src/views/Settings.js b/apps/web/src/views/Settings.js
index 58f110afe..a642ef0b2 100644
--- a/apps/web/src/views/Settings.js
+++ b/apps/web/src/views/Settings.js
@@ -13,8 +13,9 @@ function Settings(props) {
const toggleNightMode = useThemeStore((store) => store.toggleNightMode);
const user = useUserStore((store) => store.user);
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
- const isPremium = useUserStore((store) => store.user.isPremium);
- const isTrialExpired = useUserStore((store) => store.isTrialExpired);
+ const isTrial = useUserStore(
+ (store) => store?.user?.notesnook?.subscription?.isTrial
+ );
const logout = useUserStore((store) => store.logout);
return (
@@ -79,7 +80,7 @@ function Settings(props) {
px={1}
py={1 / 2}
>
- {isPremium || isTrialExpired ? "Pro" : "Trial"}
+ {!isTrial ? "Pro" : "Trial"}
</Text>
)}
</Flex>
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 88f319223..00bc9d763 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -4357,6 +4357,11 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
+event-source-polyfill@^1.0.16:
+ version "1.0.16"
+ resolved "https://registry.yarnpkg.com/event-source-polyfill/-/event-source-polyfill-1.0.16.tgz#24a035cf95efcc6d44e7288887da2e8de6859ca9"
+ integrity sha512-8Uw+cbuKGC8NwA2EW5zV95qmyvrxQcFlVjaZcK1NpJD/M+4aSIGhLobsY8L5QXRQ7+oVX4jA0FcyTgdlv8C0TA==
+
eventemitter3@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-2.0.3.tgz#b5e1079b59fb5e1ba2771c0a993be060a58c99ba"
@@ -7302,8 +7307,9 @@ 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#ccddf7870901639d82a1998701b1aa3a50742091"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#c9ea70d8f9c264431b49f67d77567e32c4f5b1c9"
dependencies:
+ event-source-polyfill "^1.0.16"
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
no-internet "^1.5.2"