Skip to content

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

refactor: use event names from EVENTS global obj

thecodrrabd26d1a1777
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 1100eaf8b..3f5ed0610 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -14,7 +14,7 @@ import useMobile from "./utils/use-mobile";
import GlobalMenuWrapper from "./components/globalmenuwrapper";
import { resetReminders } from "./common/reminders";
import { db, isUserPremium } from "./common";
-import { EV } from "notes-core/common";
+import { EV, EVENTS } from "notes-core/common";
import useTablet from "./utils/use-tablet";
import { showBuyDialog } from "./components/dialogs/buy-dialog";
import Banner from "./components/banner";
@@ -77,7 +77,7 @@ function App() {
);
useEffect(() => {
- EV.subscribe("user:checkStatus", async (type) => {
+ EV.subscribe(EVENTS.userCheckStatus, async (type) => {
if (process.env.REACT_APP_CI) return { type, result: true };
if (isUserPremium()) {
return { type, result: true };
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index d83f81445..628d1b1cc 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -19,18 +19,18 @@ export const db = new Database(StorageInterface, EventSource);
// SSE_HOST: "https://events.streetwriters.co",
// });
-db.host({
- API_HOST: "http://localhost:5264",
- AUTH_HOST: "http://localhost:8264",
- SSE_HOST: "http://localhost:7264",
-});
-
// db.host({
-// API_HOST: "http://192.168.10.8:5264",
-// AUTH_HOST: "http://192.168.10.8:8264",
-// SSE_HOST: "http://192.168.10.8:7264",
+// API_HOST: "http://localhost:5264",
+// AUTH_HOST: "http://localhost:8264",
+// SSE_HOST: "http://localhost:7264",
// });
+db.host({
+ API_HOST: "http://192.168.10.9:5264",
+ AUTH_HOST: "http://192.168.10.9:8264",
+ SSE_HOST: "http://192.168.10.9:7264",
+});
+
export const COLORS = {
red: "#f44336",
orange: "#FF9800",
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 404a6baea..d08ce6aa1 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -4,7 +4,7 @@ import { store as appStore } from "./app-store";
import { store as tagStore } from "./tag-store";
import { db } from "../common";
import BaseStore from ".";
-import { EV } from "notes-core/common";
+import { EV, EVENTS } from "notes-core/common";
import { hashNavigate } from "../navigation";
const SESSION_STATES = {
@@ -37,7 +37,7 @@ class EditorStore extends BaseStore {
arePropertiesVisible = false;
init = () => {
- EV.subscribe("user:loggedOut", () => this.get().newSession());
+ EV.subscribe(EVENTS.userLoggedOut, () => this.get().newSession());
};
openLockedSession = async (note) => {
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index b179b0cb4..82ea74796 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -4,7 +4,7 @@ import { store as editorStore } from "./editor-store";
import { store as appStore } from "./app-store";
import Vault from "../common/vault";
import BaseStore from ".";
-import { EV } from "notes-core/common";
+import { EV, EVENTS } from "notes-core/common";
import Config from "../utils/config";
import { showToast } from "../utils/toast";
import { qclone } from "qclone";
@@ -15,7 +15,7 @@ class NoteStore extends BaseStore {
selectedNote = 0;
init = () => {
- EV.subscribe("notes:removeEmptyNote", (id) => {
+ EV.subscribe(EVENTS.noteRemoved, (id) => {
const { session, newSession } = editorStore.get();
if (session.id === id) {
newSession();
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index f933dbc12..b6749d7a8 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -4,7 +4,7 @@ import { db } from "../common";
import { store as appStore } from "./app-store";
import BaseStore from "./index";
import config from "../utils/config";
-import { EV } from "notes-core/common";
+import { EV, EVENTS } from "notes-core/common";
import { showLoadingDialog } from "../components/dialogs/loadingdialog";
import { Text } from "rebass";
import { showToast } from "../utils/toast";
@@ -19,14 +19,21 @@ class UserStore extends BaseStore {
lastSynced = 0;
init = () => {
+ db.user.getUser().then((user) => {
+ if (!user) return false;
+ this.set((state) => {
+ state.user = user;
+ state.isLoggedIn = true;
+ });
+ });
return db.user.fetchUser(true).then(async (user) => {
if (!user) return false;
this.set((state) => {
state.user = user;
state.isLoggedIn = true;
});
- EV.subscribe("db:refresh", () => appStore.refresh());
- EV.subscribe("user:upgraded", (subscription) => {
+ EV.subscribe(EVENTS.appRefreshRequested, () => appStore.refresh());
+ EV.subscribe(EVENTS.userSubscriptionUpdated, (subscription) => {
this.set((state) => {
state.user = {
...state.user,
@@ -34,13 +41,13 @@ class UserStore extends BaseStore {
};
});
});
- EV.subscribe("user:emailConfirmed", async () => {
+ EV.subscribe(EVENTS.userEmailConfirmed, async () => {
showToast("success", "Email confirmed successfully!");
window.location.reload();
});
- EV.subscribe("db:sync", () => this.sync(false));
- EV.subscribe("user:loggedOut", async (reason) => {
+ EV.subscribe(EVENTS.databaseSyncRequested, () => this.sync(false));
+ EV.subscribe(EVENTS.userLoggedOut, async (reason) => {
this.set((state) => {
state.user = {};
state.isLoggedIn = false;
diff --git a/apps/web/src/views/splash.js b/apps/web/src/views/splash.js
index 1f369d9f7..6f5a8d211 100644
--- a/apps/web/src/views/splash.js
+++ b/apps/web/src/views/splash.js
@@ -5,7 +5,7 @@ import Animated from "../components/animated";
import { db } from "../common";
import ProgressBar from "../components/progress-bar";
import { getRandom } from "../utils/random";
-import { EV } from "notes-core/common";
+import { EV, EVENTS } from "notes-core/common";
import { showToast } from "../utils/toast";
import { captureException } from "@sentry/react";
@@ -23,7 +23,7 @@ function Splash(props) {
useEffect(() => {
(async function () {
try {
- EV.subscribe("user:loggedOut", (reason) => {
+ EV.subscribe(EVENTS.userLoggedOut, (reason) => {
if (reason) {
showToast("error", reason);
}
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 84d385ec9..cfb57b13b 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -8990,8 +8990,8 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
- version "5.4.1"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#6738252643874d5fad77661657d99cf1b28b6cc4"
+ version "5.5.0"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#24f491823c9ec69fe8c2ac9df85ebdf49abafabd"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"