mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-03 12:41:45 +02:00
feat: show premium dialog on using premium features
This commit is contained in:
@@ -4,7 +4,10 @@ import { Flex, Box } from "rebass";
|
||||
import ThemeProvider from "./components/theme-provider";
|
||||
import { useStore } from "./stores/app-store";
|
||||
import { useStore as useEditorStore } from "./stores/editor-store";
|
||||
import { useStore as useUserStore } from "./stores/user-store";
|
||||
import {
|
||||
store as userstore,
|
||||
useStore as useUserStore,
|
||||
} from "./stores/user-store";
|
||||
import { useStore as useNotesStore } from "./stores/note-store";
|
||||
import Animated from "./components/animated";
|
||||
import NavigationMenu from "./components/navigationmenu";
|
||||
@@ -19,6 +22,7 @@ import {
|
||||
} from "./common/reminders";
|
||||
import { EV } from "notes-core/common";
|
||||
import useTablet from "./utils/use-tablet";
|
||||
import { showBuyDialog } from "./components/dialogs/buy-dialog";
|
||||
|
||||
function App() {
|
||||
const [show, setShow] = useState(true);
|
||||
@@ -51,6 +55,18 @@ function App() {
|
||||
[refreshColors, initUser, initNotes, addReminder]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
EV.subscribe("user:checkStatus", async (type) => {
|
||||
const subStatus = userstore.get().user?.subscription?.status;
|
||||
if (subStatus && subStatus >= 1 && subStatus <= 3) {
|
||||
return { type, result: true };
|
||||
} else {
|
||||
await showBuyDialog();
|
||||
return { type, result: false };
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isFocusMode) {
|
||||
setShow(false);
|
||||
|
||||
@@ -53,8 +53,8 @@ export function showExportDialog(noteId) {
|
||||
exportNote={async (format) => {
|
||||
const note = db.notes.note(noteId);
|
||||
const content = await note.export(format);
|
||||
if (!content) return perform(false);
|
||||
download(note.title, content, format);
|
||||
showToast("success", `Note exported as ${format} successfully!`);
|
||||
perform(true);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -44,7 +44,8 @@ function menuItems(note, context) {
|
||||
{
|
||||
title: "Export",
|
||||
onClick: async () => {
|
||||
await showExportDialog(note);
|
||||
if (await showExportDialog(note))
|
||||
showToast("success", `Note exported successfully!`);
|
||||
},
|
||||
onlyPro: true,
|
||||
},
|
||||
@@ -54,11 +55,11 @@ function menuItems(note, context) {
|
||||
onClick: async () => {
|
||||
const { unlock, lock } = store.get();
|
||||
if (!note.locked) {
|
||||
await lock(note.id);
|
||||
showToast("success", "Note locked successfully!");
|
||||
if (await lock(note.id))
|
||||
showToast("success", "Note locked successfully!");
|
||||
} else {
|
||||
await unlock(note.id);
|
||||
showToast("success", "Note unlocked successfully!");
|
||||
if (await unlock(note.id))
|
||||
showToast("success", "Note unlocked successfully!");
|
||||
}
|
||||
},
|
||||
onlyPro: true,
|
||||
|
||||
@@ -193,7 +193,7 @@ function Properties() {
|
||||
data-test-id="properties-tag"
|
||||
placeholder="#tag"
|
||||
mt={4}
|
||||
onKeyUp={(event) => {
|
||||
onKeyUp={async (event) => {
|
||||
if (
|
||||
event.key === "Enter" ||
|
||||
event.key === " " ||
|
||||
@@ -204,8 +204,8 @@ function Properties() {
|
||||
event.target.value = "";
|
||||
return;
|
||||
}
|
||||
setTag(value.trim().replace(",", ""));
|
||||
event.target.value = "";
|
||||
await setTag(value.trim().replace(",", ""));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -230,8 +230,8 @@ function Properties() {
|
||||
cursor: "pointer",
|
||||
}}
|
||||
fontSize={"subBody"}
|
||||
onClick={() => {
|
||||
setTag(tag);
|
||||
onClick={async () => {
|
||||
await setTag(tag);
|
||||
}}
|
||||
>
|
||||
#{tag}
|
||||
|
||||
@@ -176,7 +176,7 @@ class EditorStore extends BaseStore {
|
||||
};
|
||||
|
||||
setTag = (tag) => {
|
||||
this._setTagOrColor("tag", tag);
|
||||
return this._setTag(tag);
|
||||
};
|
||||
|
||||
toggleProperties = (toggleState) => {
|
||||
@@ -204,23 +204,22 @@ class EditorStore extends BaseStore {
|
||||
: db.notes.add.bind(db.notes);
|
||||
};
|
||||
|
||||
_setTagOrColor(key, value) {
|
||||
const array = key === "tag" ? "tags" : "colors";
|
||||
const { [array]: arr, id } = this.get().session;
|
||||
async _setTag(value) {
|
||||
const { tags, id } = this.get().session;
|
||||
|
||||
let note = db.notes.note(id);
|
||||
if (!note) return;
|
||||
|
||||
let index = arr.indexOf(value);
|
||||
let index = tags.indexOf(value);
|
||||
if (index > -1) {
|
||||
note[`un${key}`](value).then(() => {
|
||||
this.setSession((state) => state.session[array].splice(index, 1));
|
||||
});
|
||||
await note.untag(value);
|
||||
} else {
|
||||
note[key](value).then(() => {
|
||||
this.setSession((state) => state.session[array].push(value));
|
||||
});
|
||||
await note.tag(value);
|
||||
}
|
||||
|
||||
this.setSession(
|
||||
(state) => (state.session.tags = db.notes.note(id).data.tags)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,10 +97,11 @@ class NoteStore extends BaseStore {
|
||||
setColor = async (id, color) => {
|
||||
let note = db.notes.note(id);
|
||||
if (!note) return;
|
||||
const shouldUncolor = note.data.colors.indexOf(color) > -1;
|
||||
for (var c of note.data.colors) {
|
||||
await note.uncolor(c);
|
||||
}
|
||||
await db.notes.note(id).color(color);
|
||||
if (!shouldUncolor) await db.notes.note(id).color(color);
|
||||
appStore.refreshColors();
|
||||
if (!this._syncEditor(note.id, "colors", db.notes.note(id).data.colors)) {
|
||||
this.refresh();
|
||||
@@ -112,7 +113,6 @@ class NoteStore extends BaseStore {
|
||||
*/
|
||||
_syncEditor = (noteId, action, value) => {
|
||||
const { session, setSession } = editorStore.get();
|
||||
console.log(session.id, noteId, session.id !== noteId);
|
||||
if (session.id !== noteId) return false;
|
||||
setSession((state) => (state.session[action] = value), true);
|
||||
return true;
|
||||
|
||||
@@ -8859,8 +8859,8 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
|
||||
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
|
||||
|
||||
"notes-core@git+ssh://git@github.com:streetwriters/notesnook-core.git":
|
||||
version "2.1.1"
|
||||
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#9f80e6b94e45c56b30531d294bf415dfc057c347"
|
||||
version "2.1.4"
|
||||
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#f5fb463b23d4483bd8c066d0dab815f30fb260c3"
|
||||
dependencies:
|
||||
fast-sort "^2.0.1"
|
||||
fuzzysearch "^1.0.3"
|
||||
@@ -10754,15 +10754,6 @@ react-scripts@3.4.1:
|
||||
optionalDependencies:
|
||||
fsevents "2.1.2"
|
||||
|
||||
react-textarea-autosize@^8.3.0:
|
||||
version "8.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-8.3.0.tgz#e6e2fd186d9f61bb80ac6e2dcb4c55504f93c2fa"
|
||||
integrity sha512-3GLWFAan2pbwBeoeNDoqGmSbrShORtgWfaWX0RJDivsUrpShh01saRM5RU/i4Zmf+whpBVEY5cA90Eq8Ub1N3w==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.10.2"
|
||||
use-composed-ref "^1.0.0"
|
||||
use-latest "^1.0.0"
|
||||
|
||||
react-virtualized-auto-sizer@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.2.tgz#a61dd4f756458bbf63bd895a92379f9b70f803bd"
|
||||
@@ -12405,11 +12396,6 @@ tryer@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
|
||||
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
|
||||
|
||||
ts-essentials@^2.0.3:
|
||||
version "2.0.12"
|
||||
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-2.0.12.tgz#c9303f3d74f75fa7528c3d49b80e089ab09d8745"
|
||||
integrity sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==
|
||||
|
||||
ts-pnp@1.1.6:
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.6.tgz#389a24396d425a0d3162e96d2b4638900fdc289a"
|
||||
@@ -12643,25 +12629,6 @@ url@^0.11.0:
|
||||
punycode "1.3.2"
|
||||
querystring "0.2.0"
|
||||
|
||||
use-composed-ref@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/use-composed-ref/-/use-composed-ref-1.1.0.tgz#9220e4e94a97b7b02d7d27eaeab0b37034438bbc"
|
||||
integrity sha512-my1lNHGWsSDAhhVAT4MKs6IjBUtG6ZG11uUqexPH9PptiIZDQOzaF4f5tEbJ2+7qvNbtXNBbU3SfmN+fXlWDhg==
|
||||
dependencies:
|
||||
ts-essentials "^2.0.3"
|
||||
|
||||
use-isomorphic-layout-effect@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/use-isomorphic-layout-effect/-/use-isomorphic-layout-effect-1.1.0.tgz#4db2111e0d53ca694187ea5fd5cb2ba610286fe0"
|
||||
integrity sha512-kady5Z1O1qx5RitodCCKbpJSVEtECXYcnBnb5Q48Bz5V6gBmTu85ZcGdVwVFs8+DaOurNb/L5VdGHoQRMknghw==
|
||||
|
||||
use-latest@^1.0.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/use-latest/-/use-latest-1.2.0.tgz#a44f6572b8288e0972ec411bdd0840ada366f232"
|
||||
integrity sha512-d2TEuG6nSLKQLAfW3By8mKr8HurOlTkul0sOpxbClIv4SQ4iOd7BYr7VIzdbktUCnv7dua/60xzd8igMU6jmyw==
|
||||
dependencies:
|
||||
use-isomorphic-layout-effect "^1.0.0"
|
||||
|
||||
use@^3.1.0:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
|
||||
|
||||
Reference in New Issue
Block a user