Skip to content

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

feat: completely remove event emitter

thecodrrc88f5d3b4da4
diff --git a/apps/web/package.json b/apps/web/package.json
index ba4ce5764..9c099abd9 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -5,7 +5,6 @@
"dependencies": {
"@rebass/forms": "^4.0.6",
"emotion-theming": "^10.0.19",
- "events": "^3.0.0",
"framer-motion": "^1.9.1",
"immer": "^5.3.6",
"localforage": "^1.7.3",
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index b99e76daa..c185132fc 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -1,9 +1,7 @@
import StorageInterface from "../interfaces/storage";
import Database from "notes-core/api/";
-import events from "events";
export const db = new Database(StorageInterface);
-export const ev = new events.EventEmitter();
export const COLORS = {
red: "#ed2d37",
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index f345c0372..3bc477926 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -10,6 +10,7 @@ function appStore(set, get) {
isSelectionMode: false,
shouldSelectAll: false,
selectedItems: [],
+ theme: {},
colors: [],
closeSideMenu: function() {
set(state => {
@@ -89,6 +90,11 @@ function appStore(set, get) {
.then(() => true)
.catch(() => false);
});
+ },
+ setTheme: function(theme) {
+ set(state => {
+ state.theme = theme;
+ });
}
};
}
diff --git a/apps/web/src/utils/theme.js b/apps/web/src/utils/theme.js
index 3c7908025..3d853120f 100644
--- a/apps/web/src/utils/theme.js
+++ b/apps/web/src/utils/theme.js
@@ -1,7 +1,6 @@
import React from "react";
import { ThemeProvider as EmotionThemeProvider } from "emotion-theming";
-import { ev } from "../common";
-import { useEffect } from "react";
+import { store, useStore } from "../stores/app-store";
import { addCss } from "./css";
const colorsLight = primary =>
@@ -16,7 +15,7 @@ const colorsLight = primary =>
text: "#000000",
overlay: "rgba(0, 0, 0, 0.1)",
secondary: "white",
- icon:'#909090'
+ icon: "#909090"
});
const colorsDark = primary =>
makeTheme({
@@ -30,7 +29,7 @@ const colorsDark = primary =>
text: "#ffffff",
overlay: "rgba(255, 255, 255, 0.5)",
secondary: "black",
- icon:'#909090'
+ icon: "#909090"
});
const shadowsDark = {
@@ -227,18 +226,11 @@ var currentTheme = window.localStorage.getItem("theme") || "light";
var currentAccent = window.localStorage.getItem("accent") || "#0560ff";
export const ThemeProvider = props => {
- const [, updateState] = React.useState();
- useEffect(() => {
- function updater() {
- updateState({});
- }
- ev.addListener("changeTheme", updater);
- return () => {
- ev.removeListener("changeTheme", updater);
- };
- }, []);
- const theme = getTheme(currentTheme, currentAccent);
+ let theme = useStore(store => store.theme);
+
+ theme = theme.colors ? theme : getTheme(currentTheme, currentAccent);
addCss(cssTheme(theme));
+
return (
<EmotionThemeProvider theme={theme}>
{props.children instanceof Function
@@ -251,13 +243,17 @@ export const ThemeProvider = props => {
export const changeAccent = accent => {
currentAccent = accent;
window.localStorage.setItem("accent", accent);
- ev.emit("changeTheme");
+ const theme = getTheme(currentTheme, currentAccent);
+ addCss(cssTheme(theme));
+ store.getState().setTheme(theme);
};
export const changeTheme = () => {
currentTheme = currentTheme === "dark" ? "light" : "dark";
window.localStorage.setItem("theme", currentTheme);
- ev.emit("changeTheme");
+ const theme = getTheme(currentTheme, currentAccent);
+ addCss(cssTheme(theme));
+ store.getState().setTheme(theme);
};
export const isDarkTheme = () => currentTheme === "dark";