Skip to content

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

fix: make app compile after theming logic changes

thecodrr4267237f7e43
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index b588e916c..0c7ac0a10 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -3,7 +3,7 @@ import "./app.css";
import Editor from "./components/editor";
import { motion } from "framer-motion";
import { Flex, Box, Button, Text } from "rebass";
-import { ThemeProvider } from "./utils/theme";
+import ThemeProvider from "./components/theme-provider";
import RootNavigator, {
bottomRoutes,
routes
diff --git a/apps/web/src/components/button/index.js b/apps/web/src/components/button/index.js
index a594c6ed8..37416fa8f 100644
--- a/apps/web/src/components/button/index.js
+++ b/apps/web/src/components/button/index.js
@@ -1,8 +1,8 @@
import React from "react";
import { Flex, Text } from "rebass";
-import { ButtonPressedStyle } from "../../utils/theme";
import { useTheme } from "emotion-theming";
+//TODO use normal button
function Button(props) {
const theme = useTheme();
return (
@@ -24,7 +24,6 @@ function Button(props) {
cursor: "pointer",
bg: theme.colors.primary + "dd"
},
- ...ButtonPressedStyle,
...props.style
}}
onClick={props.onClick}
diff --git a/apps/web/src/components/dialogs/add-notebook-dialog.js b/apps/web/src/components/dialogs/add-notebook-dialog.js
index cf2829dd4..216af18ee 100644
--- a/apps/web/src/components/dialogs/add-notebook-dialog.js
+++ b/apps/web/src/components/dialogs/add-notebook-dialog.js
@@ -3,7 +3,6 @@ import { Flex, Box, Text, Button as RebassButton } from "rebass";
import { Input } from "@rebass/forms";
import * as Icon from "../icons";
import Dialog, { showDialog } from "./dialog";
-import { showSnack } from "../snackbar";
import { store } from "../../stores/notebook-store";
class AddNotebookDialog extends React.Component {
@@ -167,8 +166,6 @@ class AddNotebookDialog extends React.Component {
positiveButton={{
text: props.edit ? "Edit" : "Add",
onClick: () => {
- if (!this.title.trim().length)
- return showSnack("Please enter the notebook title.");
props.onDone({
title: this.title,
description: this.description,
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index ef027b1c2..70f19103a 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -1,108 +1,105 @@
import React from "react";
import ReactDOM from "react-dom";
import { Flex, Text, Button as RebassButton } from "rebass";
-import { ThemeProvider } from "../../utils/theme";
+import ThemeProvider from "../theme-provider";
import * as Icon from "../icons";
import Modal from "react-modal";
+import { useTheme } from "emotion-theming";
-export default class Dialog extends React.Component {
- render() {
- const props = this.props;
- return (
- <ThemeProvider>
- {theme => (
- <Modal
- isOpen={props.isOpen || false}
- shouldCloseOnOverlayClick={true}
- onRequestClose={props.negativeButton.onClick}
- style={{
- content: {
- top: "50%",
- left: "50%",
- right: "auto",
- bottom: "auto",
- marginRight: "-50%",
- transform: "translate(-50%, -50%)",
- borderWidth: 0,
- borderRadius: theme.radii["default"],
- backgroundColor: theme.colors.background,
- color: theme.colors.text,
- boxShadow: theme.shadows["3"],
- width: "25%",
- paddingRight: 20,
- paddingLeft: 20,
- overflowY: "hidden"
- },
- overlay: {
- zIndex: 999,
- background: theme.colors.overlay
- }
- }}
+function Dialog(props) {
+ const theme = useTheme();
+ return (
+ <ThemeProvider>
+ <Modal
+ isOpen={props.isOpen || false}
+ shouldCloseOnOverlayClick={true}
+ onRequestClose={props.negativeButton.onClick}
+ style={{
+ content: {
+ top: "50%",
+ left: "50%",
+ right: "auto",
+ bottom: "auto",
+ marginRight: "-50%",
+ transform: "translate(-50%, -50%)",
+ borderWidth: 0,
+ borderRadius: theme.radii["default"],
+ backgroundColor: theme.colors.background,
+ color: theme.colors.text,
+ boxShadow: theme.shadows["3"],
+ width: "25%",
+ paddingRight: 20,
+ paddingLeft: 20,
+ overflowY: "hidden"
+ },
+ overlay: {
+ zIndex: 999,
+ background: theme.colors.overlay
+ }
+ }}
+ >
+ <Flex flexDirection="column">
+ <Flex
+ flexDirection="row"
+ alignItems="center"
+ alignSelf="center"
+ justifyContent="center"
+ color="primary"
+ sx={{ paddingBottom: 2 }}
>
- <Flex flexDirection="column">
- <Flex
- flexDirection="row"
- alignItems="center"
- alignSelf="center"
- justifyContent="center"
- color="primary"
- sx={{ paddingBottom: 2 }}
- >
- <props.icon size={props.iconSize || 38} color="primary" />
- <Text
- mx={1}
- as="span"
- variant="title"
- fontSize={"heading"}
- textAlign="center"
- >
- {props.title}
- </Text>
- </Flex>
- {props.content}
- <Flex
- flexDirection="row"
- sx={{ marginTop: 3 }}
- justifyContent="center"
- alignItems="center"
+ <props.icon size={props.iconSize || 38} color="primary" />
+ <Text
+ mx={1}
+ as="span"
+ variant="title"
+ fontSize={"heading"}
+ textAlign="center"
+ >
+ {props.title}
+ </Text>
+ </Flex>
+ {props.content}
+ <Flex
+ flexDirection="row"
+ sx={{ marginTop: 3 }}
+ justifyContent="center"
+ alignItems="center"
+ >
+ {props.positiveButton && (
+ <RebassButton
+ variant="primary"
+ sx={{ opacity: props.positiveButton.disabled ? 0.7 : 1 }}
+ mx={1}
+ width={"50%"}
+ disabled={props.positiveButton.disabled || false}
+ onClick={
+ !props.positiveButton.disabled && props.positiveButton.onClick
+ }
>
- {props.positiveButton && (
- <RebassButton
- variant="primary"
- sx={{ opacity: props.positiveButton.disabled ? 0.7 : 1 }}
- mx={1}
- width={"50%"}
- disabled={props.positiveButton.disabled || false}
- onClick={
- !props.positiveButton.disabled &&
- props.positiveButton.onClick
- }
- >
- {props.positiveButton.loading ? (
- <Icon.Loading rotate={true} color="static" />
- ) : (
- props.positiveButton.text || "OK"
- )}
- </RebassButton>
+ {props.positiveButton.loading ? (
+ <Icon.Loading rotate={true} color="static" />
+ ) : (
+ props.positiveButton.text || "OK"
)}
+ </RebassButton>
+ )}
- {props.negativeButton && (
- <RebassButton
- variant="secondary"
- width={"50%"}
- onClick={props.negativeButton.onClick}
- >
- {props.negativeButton.text || "Cancel"}
- </RebassButton>
- )}
- </Flex>
- </Flex>
- </Modal>
- )}
- </ThemeProvider>
- );
- }
+ {props.negativeButton && (
+ <RebassButton
+ variant="secondary"
+ width={"50%"}
+ onClick={props.negativeButton.onClick}
+ >
+ {props.negativeButton.text || "Cancel"}
+ </RebassButton>
+ )}
+ </Flex>
+ </Flex>
+ </Modal>
+ </ThemeProvider>
+ );
}
+export default Dialog;
export function showDialog(dialog) {
const root = document.getElementById("dialogContainer");
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index a2564e4f7..f600c9497 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -2,7 +2,6 @@ import React from "react";
import { Flex, Box } from "rebass";
import * as Icon from "../icons";
import TimeAgo from "timeago-react";
-import { showSnack } from "../snackbar";
import ListItem from "../list-item";
import { confirm } from "../dialogs/confirm";
import { showMoveNoteDialog } from "../dialogs/movenotedialog";
@@ -19,7 +18,7 @@ function menuItems(note, context) {
title: note.notebook ? "Move" : "Add to",
onClick: async () => {
if (await showMoveNoteDialog([note.id])) {
- showSnack("Note moved successfully!");
+ console.log("Note moved successfully!");
}
}
},
diff --git a/apps/web/src/components/snackbar/index.js b/apps/web/src/components/snackbar/index.js
deleted file mode 100644
index 909596019..000000000
--- a/apps/web/src/components/snackbar/index.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import React from "react";
-import ReactDOM from "react-dom";
-import { Flex, Text } from "rebass";
-import { ThemeProvider } from "../../utils/theme";
-
-export function showSnack(message, icon = undefined) {
- const root = document.getElementById("snackbarContainer");
- if (root) {
- ReactDOM.render(<Snackbar message={message} Icon={icon} />, root);
- setTimeout(() => {
- const snackbar = document.getElementById("snackbar");
- if (!snackbar) return;
- setTimeout(() => ReactDOM.unmountComponentAtNode(root), 700);
- snackbar.animate(
- {
- opacity: [1, 0],
- transform: ["translateY(0px)", "translateY(500px)"]
- },
- 1000
- );
- }, 3000);
- }
-}
-
-function Snackbar(props) {
- return (
- <ThemeProvider>
- <Flex
- id="snackbar"
- sx={{
- position: "absolute",
- bottom: 10,
- left: "50%",
- textAlign: "center",
- color: "static",
- fontFamily: "body",
- fontWeight: "body",
- borderRadius: "default",
- animation: "1s ease-out fadeUp"
- }}
- alignItems="center"
- flexDirection="row"
- bg="primary"
- py={2}
- px={2}
- >
- {props.Icon && <props.Icon size={18} />}
- <Text mx={1}>{props.message}</Text>
- </Flex>
- </ThemeProvider>
- );
-}
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 05f33cd51..0ec285ea8 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -4,7 +4,7 @@ import { Box, Flex, Heading, Text } from "rebass";
import Animated from "../components/animated";
import { AnimatePresence } from "framer-motion";
import * as Icon from "../components/icons";
-import { ThemeProvider } from "../utils/theme";
+import ThemeProvider from "../components/theme-provider";
import { useStore, store } from "../stores/app-store";
class Navigator {
diff --git a/apps/web/src/navigation/navigators/rootnavigator.js b/apps/web/src/navigation/navigators/rootnavigator.js
index 471f684f7..15ce57eae 100644
--- a/apps/web/src/navigation/navigators/rootnavigator.js
+++ b/apps/web/src/navigation/navigators/rootnavigator.js
@@ -10,16 +10,16 @@ import {
import * as Icon from "../../components/icons";
import { createRoute, createNormalRoute, createDeadRoute } from "../routes";
import Navigator from "../index";
-import { changeTheme } from "../../utils/theme";
import SelectionModeOptions from "../../common/selectionoptions";
import Search from "../../views/Search";
import { store as noteStore } from "../../stores/note-store";
import { store as userStore } from "../../stores/user-store";
+import { store as themeStore } from "../../stores/theme-store";
import { showLogInDialog } from "../../components/dialogs/logindialog";
export const bottomRoutes = {
...createDeadRoute("nightmode", Icon.Theme, {
- onClick: () => changeTheme()
+ onClick: () => themeStore.getState().toggleNightMode()
}),
...createDeadRoute("sync", Icon.Sync, {
onClick: async () => userStore.getState().sync(),
diff --git a/apps/web/src/stores/theme-store.js b/apps/web/src/stores/theme-store.js
index 0a7a0b6b9..8d71ae80a 100644
--- a/apps/web/src/stores/theme-store.js
+++ b/apps/web/src/stores/theme-store.js
@@ -1,6 +1,6 @@
import createStore from "../common/store";
-function themeStore(set) {
+function themeStore(set, get) {
return {
theme: "light",
accent: "#0560ff",
@@ -9,6 +9,10 @@ function themeStore(set) {
state.theme = theme;
});
},
+ toggleNightMode: function() {
+ const theme = get().theme;
+ get().setTheme(theme === "dark" ? "light" : "dark");
+ },
setAccent: function(accent) {
set(state => {
state.accent = accent;
diff --git a/apps/web/src/views/Settings.js b/apps/web/src/views/Settings.js
index 0dc3e2710..e44420454 100644
--- a/apps/web/src/views/Settings.js
+++ b/apps/web/src/views/Settings.js
@@ -1,16 +1,18 @@
-import React, { useState, useEffect } from "react";
+import React, { useEffect } from "react";
import { Box, Button, Flex, Text } from "rebass";
import * as Icon from "../components/icons";
import "../app.css";
-import { changeTheme, isDarkTheme, changeAccent } from "../utils/theme";
-import { useTheme } from "emotion-theming";
import { useStore as useUserStore } from "../stores/user-store";
+import { useStore as useThemeStore } from "../stores/theme-store";
function Settings(props) {
- const [check, setCheck] = useState(isDarkTheme());
- const theme = useTheme();
+ const theme = useThemeStore(store => store.theme);
+ const accent = useThemeStore(store => store.accent);
+ const toggleNightMode = useThemeStore(store => store.theme);
+ const setAccent = useThemeStore(store => store.theme);
const user = useUserStore(store => store.user);
const isLoggedIn = useUserStore(store => store.isLoggedIn);
+
return (
<Flex flexDirection="column" flex="1 1 auto">
<Flex
@@ -99,10 +101,10 @@ function Settings(props) {
justifyContent="center"
alignItems="center"
onClick={() => {
- changeAccent(color.code);
+ setAccent(color.code);
}}
>
- {color.code === theme.colors.primary && (
+ {color.code === accent && (
<Icon.Checkmark
sx={{
position: "absolute",
@@ -125,13 +127,10 @@ function Settings(props) {
px={2}
justifyContent="space-between"
alignItems="center"
- onClick={() => {
- setCheck(!check);
- changeTheme();
- }}
+ onClick={() => toggleNightMode()}
>
<Text fontSize="body">Dark Mode</Text>
- {check ? <Icon.Check /> : <Icon.CircleEmpty />}
+ {theme === "dark" ? <Icon.Check /> : <Icon.CircleEmpty />}
</Flex>
</Box>
<Box