Skip to content

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

fix: show upgrade reminder dialog after app loads

thecodrr65bf07c37418
diff --git a/apps/web/src/app-effects.js b/apps/web/src/app-effects.js
index 55d3b21d0..0c799599b 100644
--- a/apps/web/src/app-effects.js
+++ b/apps/web/src/app-effects.js
@@ -3,14 +3,18 @@ import { useStore, store } from "./stores/app-store";
import { useStore as useUserStore } from "./stores/user-store";
import { useStore as useNotesStore } from "./stores/note-store";
import { resetReminders } from "./common/reminders";
-import { AppEventManager, AppEvents, introduceFeatures } from "./common";
+import {
+ AppEventManager,
+ AppEvents,
+ introduceFeatures,
+ showUpgradeReminderDialogs,
+} from "./common";
import { db } from "./common/db";
import { CHECK_IDS, EV, EVENTS } from "notes-core/common";
import { registerKeyMap } from "./common/key-map";
import { isUserPremium } from "./hooks/use-is-user-premium";
import { loadTrackerScript } from "./utils/analytics";
import Modal from "react-modal";
-import useDatabase from "./hooks/use-database";
Modal.setAppElement("#root");
if (process.env.NODE_ENV === "production") {
@@ -28,23 +32,21 @@ export default function AppEffects({ setShow }) {
const initUser = useUserStore((store) => store.init);
const initNotes = useNotesStore((store) => store.init);
const setIsVaultCreated = useStore((store) => store.setIsVaultCreated);
- const [isAppLoaded] = useDatabase();
useEffect(
function initializeApp() {
- if (!isAppLoaded) return;
refreshColors();
refreshMenuPins();
- initUser();
initNotes();
- updateLastSynced();
(async function () {
+ await initUser();
+ await updateLastSynced();
await resetReminders();
setIsVaultCreated(await db.vault.exists());
+ await showUpgradeReminderDialogs();
})();
},
[
- isAppLoaded,
updateLastSynced,
refreshColors,
refreshMenuPins,
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index 601426721..0afd1d133 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -15,6 +15,7 @@ import { db } from "./db";
import { sanitizeFilename } from "../utils/filename";
import { isTesting } from "../utils/platform";
import EventManager from "notes-core/utils/eventmanager";
+import { store as userstore } from "../stores/user-store";
export const COLORS = [
"Red",
@@ -155,7 +156,10 @@ export function totalSubscriptionConsumed(user) {
return Math.round((consumed / total) * 100);
}
-export async function showUpgradeReminderDialogs(user) {
+export async function showUpgradeReminderDialogs() {
+ const user = userstore.get().user;
+ if (!user) return;
+
const consumed = totalSubscriptionConsumed(user);
const isTrial = user?.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
const isBasic = user?.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index eaf075eb3..b49ca2600 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -9,7 +9,6 @@ import { showAccountLoggedOutNotice } from "../common/dialog-controller";
import Config from "../utils/config";
import { onPageVisibilityChanged } from "../utils/page-visibility";
import { hashNavigate } from "../navigation";
-import { showUpgradeReminderDialogs } from "../common";
class UserStore extends BaseStore {
isLoggedIn = false;
@@ -88,8 +87,6 @@ class UserStore extends BaseStore {
await db.connectSSE();
}
});
-
- await showUpgradeReminderDialogs(user);
await appStore.sync();
return true;
});