mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: implement the new subscription api
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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://git@github.com:streetwriters/notesnook-core.git":
|
||||
version "1.5.0"
|
||||
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#ccddf7870901639d82a1998701b1aa3a50742091"
|
||||
resolved "git+ssh://git@github.com: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"
|
||||
|
||||
Reference in New Issue
Block a user