A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: implement theme toggling
thecodrr6ece18aef45c
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 3d1e327fe..1226f5cfd 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -1,10 +1,9 @@import React, { useState, useEffect } from "react";import "./app.css";import Editor from "./components/editor";-import { ThemeProvider } from "emotion-theming";import { Flex, Box, Button, Text } from "rebass";import { Input } from "@rebass/forms";-import theme from "./theme";+import { ThemeProvider } from "./utils/theme";import { routes, navigate } from "./navigation";import CheckBox from "./components/checkbox";import * as Icon from "react-feather";@@ -45,7 +44,7 @@ function getNavigationViewWidth() {function App() {const [selectedIndex, setSelectedIndex] = useState(1);return (- <ThemeProvider theme={theme}>+ <ThemeProvider><Flexbg="background"sx={{ color: "text" }}diff --git a/apps/web/src/components/button/index.js b/apps/web/src/components/button/index.jsindex c60ff00d2..fa4dce4a1 100644--- a/apps/web/src/components/button/index.js+++ b/apps/web/src/components/button/index.js@@ -1,7 +1,6 @@import React from "react";import { Flex, Text } from "rebass";-import { ButtonPressedStyle } from "../../theme";-+import { ButtonPressedStyle } from "../../utils/theme";const Button = props => (<Flexdiff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.jsindex c0e555395..04c856600 100644--- a/apps/web/src/components/dialogs/index.js+++ b/apps/web/src/components/dialogs/index.js@@ -3,9 +3,8 @@ import ReactDOM from "react-dom";import { Flex, Box, Text, Button as RebassButton } from "rebass";import { Input, Checkbox, Label } from "@rebass/forms";import * as Icon from "react-feather";-import theme from "../../theme";+import { ThemeProvider } from "../../utils/theme";import Modal from "react-modal";-import { ThemeProvider } from "emotion-theming";const Dialog = props => {const [open, setOpen] = useState(false);@@ -14,78 +13,82 @@ const Dialog = props => {setOpen(props.open);}, [props.open]);return (- <Modal- isOpen={open}- 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: "20%",- paddingRight: 40,- paddingLeft: 40,- overflowY: "hidden"- },- overlay: {- background: theme.colors.overlay- }- }}- >- <Flex flexDirection="column">- <Flex- flexDirection="row"- alignItems="center"- alignSelf="center"- justifyContent="center"- color="primary"- py={2}- >- <Box height={42}>- <props.icon size={42} />- </Box>- <Text- mx={2}- as="span"- variant="title"- fontSize={28}- textAlign="center"- >- {props.title}- </Text>- </Flex>- {props.content}- <Flex- flexDirection="row"- my={1}- justifyContent="center"- alignItems="center"+ <ThemeProvider>+ {theme => (+ <Modal+ isOpen={open}+ 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: "20%",+ paddingRight: 40,+ paddingLeft: 40,+ overflowY: "hidden"+ },+ overlay: {+ background: theme.colors.overlay+ }+ }}>- <RebassButton- variant="primary"- mx={1}- width={"25%"}- onClick={props.positiveButton.click}- >- {props.positiveButton.text || "OK"}- </RebassButton>- <RebassButton- variant="secondary"- width={"25%"}- onClick={props.negativeButton.click}- >- {props.negativeButton.text || "Cancel"}- </RebassButton>- </Flex>- </Flex>- </Modal>+ <Flex flexDirection="column">+ <Flex+ flexDirection="row"+ alignItems="center"+ alignSelf="center"+ justifyContent="center"+ color="primary"+ py={2}+ >+ <Box height={42}>+ <props.icon size={42} />+ </Box>+ <Text+ mx={2}+ as="span"+ variant="title"+ fontSize={28}+ textAlign="center"+ >+ {props.title}+ </Text>+ </Flex>+ {props.content}+ <Flex+ flexDirection="row"+ my={1}+ justifyContent="center"+ alignItems="center"+ >+ <RebassButton+ variant="primary"+ mx={1}+ width={"25%"}+ onClick={props.positiveButton.click}+ >+ {props.positiveButton.text || "OK"}+ </RebassButton>+ <RebassButton+ variant="secondary"+ width={"25%"}+ onClick={props.negativeButton.click}+ >+ {props.negativeButton.text || "Cancel"}+ </RebassButton>+ </Flex>+ </Flex>+ </Modal>+ )}+ </ThemeProvider>);};@@ -193,23 +196,21 @@ export const CreateNotebookDialog = props => {};const ConfirmationDialog = props => (- <ThemeProvider theme={theme}>- <Dialog- open={true}- title={props.title}- icon={props.icon}- content={- <Box my={1}>- <Text>{props.message}</Text>- </Box>- }- positiveButton={{- text: "Yes",- click: props.onYes- }}- negativeButton={{ text: "No", click: props.onNo }}- />- </ThemeProvider>+ <Dialog+ open={true}+ title={props.title}+ icon={props.icon}+ content={+ <Box my={1}>+ <Text>{props.message}</Text>+ </Box>+ }+ positiveButton={{+ text: "Yes",+ click: props.onYes+ }}+ negativeButton={{ text: "No", click: props.onNo }}+ />);export const ask = (icon, title, message) => {diff --git a/apps/web/src/components/listview/index.js b/apps/web/src/components/listview/index.jsindex 41a756ee4..8d279cb4f 100644--- a/apps/web/src/components/listview/index.js+++ b/apps/web/src/components/listview/index.js@@ -79,7 +79,7 @@ function ListView({ type, getItems, menu, button }) {color="#9b9b9b"flexDirection="column">- {type == "Favorites" ? (+ {type === "Favorites" ? (<Icon.Star size={72} strokeWidth={1.5} />) : (<Icon.Trash size={72} strokeWidth={1.5} />diff --git a/apps/web/src/components/search/index.js b/apps/web/src/components/search/index.jsindex bc53ff5e7..90960bdc8 100644--- a/apps/web/src/components/search/index.js+++ b/apps/web/src/components/search/index.js@@ -2,7 +2,6 @@ import React from "react";import { Flex, Box } from "rebass";import { Input } from "@rebass/forms";import * as Icon from "react-feather";-import theme from "../../theme";import "./search.css";const Search = props => (<Flex@@ -27,7 +26,7 @@ const Search = props => (position: "absolute",right: 0,marginRight: 20,- color: theme.colors["hover"],+ color: "hover",height: 24}}>diff --git a/apps/web/src/components/snackbar/index.js b/apps/web/src/components/snackbar/index.jsindex 83cf9b23f..f8b90d84b 100644--- a/apps/web/src/components/snackbar/index.js+++ b/apps/web/src/components/snackbar/index.js@@ -1,8 +1,7 @@import React from "react";import ReactDOM from "react-dom";import { Flex, Text } from "rebass";-import { ThemeProvider } from "emotion-theming";-import theme from "../../theme";+import { ThemeProvider } from "../../utils/theme";export function showSnack(message, icon = undefined) {const root = document.getElementById("snackbarContainer");@@ -24,7 +23,7 @@ export function showSnack(message, icon = undefined) {}const Snackbar = props => (- <ThemeProvider theme={theme}>+ <ThemeProvider><Flexid="snackbar"sx={{diff --git a/apps/web/src/index.css b/apps/web/src/index.cssindex de4a9c079..bfe97247a 100644--- a/apps/web/src/index.css+++ b/apps/web/src/index.css@@ -8,6 +8,14 @@ body,overflow: hidden;}+* {+ -webkit-transition: background-color 300ms linear, border-color 300ms linear;+ -moz-transition: background-color 300ms linear, border-color 300ms linear;+ -o-transition: background-color 300ms linear, border-color 300ms linear;+ -ms-transition: background-color 300ms linear, border-color 300ms linear;+ transition: background-color 300ms linear, border-color 300ms linear;+}+body {font-family: "Noto Sans", sans-serif;font-weight: normal;diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.jsindex 1a7d4fe9c..bd6f1805f 100644--- a/apps/web/src/navigation/index.js+++ b/apps/web/src/navigation/index.js@@ -4,10 +4,9 @@ import Home from "../views/Home";import Notebooks from "../views/Notebooks";import Settings from "../views/Settings";import Trash from "../views/Trash";-import { ThemeProvider } from "emotion-theming";import { Box, Flex, Heading } from "rebass";import * as Icon from "react-feather";-import theme from "../theme";+import { ThemeProvider } from "../utils/theme";import Favorites from "../views/Favorites";export const routes = {@@ -104,7 +103,7 @@ function ThemedComponent(props) {setTitle(props.route.title);}, [props.route.title]);return (- <ThemeProvider theme={theme}>+ <ThemeProvider><Flex alignItems="center" px={3}><BoxonClick={backAction}diff --git a/apps/web/src/theme.js b/apps/web/src/utils/theme.jssimilarity index 67%rename from apps/web/src/theme.jsrename to apps/web/src/utils/theme.jsindex 3ab16cd6e..cb0bb6d61 100644--- a/apps/web/src/theme.js+++ b/apps/web/src/utils/theme.js@@ -1,8 +1,8 @@-export const ButtonPressedStyle = {- ":active": {- opacity: "0.8"- }-};+import React from "react";+import { ThemeProvider as EmotionThemeProvider } from "emotion-theming";+import { ev } from "../common";+import { useEffect } from "react";+const colorsLight = makeTheme({background: "white",accent: "white",@@ -36,9 +36,9 @@ const shadowsLight = {4: "0 0 5px 0px #00000017"};-export default {+const theme = (colors, shadows) => ({breakpoints: ["480px", "834px", "1200px"],- colors: colorsLight,+ colors: colors,space: [0, 5, 10, 12, 15],fontSizes: {heading: 36,@@ -144,23 +144,23 @@ export default {outline: "none"}},- setting:{- bg:'transparent',- borderLeft:'0px Solid',- borderRight:'0px Solid',- borderTop:'0px Solid',- borderBottom:'1px Solid',- borderColor:'border',- color:'text',- textAlign:'left',- fontSize:'title',- fontFamily:'body',- py:'15px',- mx:'5px'+ setting: {+ bg: "transparent",+ borderLeft: "0px Solid",+ borderRight: "0px Solid",+ borderTop: "0px Solid",+ borderBottom: "1px Solid",+ borderColor: "border",+ color: "text",+ textAlign: "left",+ fontSize: "title",+ fontFamily: "body",+ py: "15px",+ mx: "5px"}},- shadows: shadowsLight-};+ shadows: shadows+});function makeTheme({background,@@ -189,3 +189,45 @@ function makeTheme({overlay};}++const getTheme = type =>+ type === "dark"+ ? theme(colorsDark, shadowsDark)+ : theme(colorsLight, shadowsLight);++var currentTheme = window.localStorage.getItem("theme") || "light";++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);+ return (+ <EmotionThemeProvider theme={theme}>+ {props.children instanceof Function+ ? props.children(theme)+ : props.children}+ </EmotionThemeProvider>+ );+};++export const changeTheme = () => {+ currentTheme = currentTheme === "dark" ? "light" : "dark";+ window.localStorage.setItem("theme", currentTheme);+ ev.emit("changeTheme");+};++export const isDarkTheme = () => currentTheme === "dark";++export const ButtonPressedStyle = {+ ":active": {+ opacity: "0.8"+ }+};diff --git a/apps/web/src/views/Settings.js b/apps/web/src/views/Settings.jsindex 34633daa2..e9342f7f1 100644--- a/apps/web/src/views/Settings.js+++ b/apps/web/src/views/Settings.js@@ -3,10 +3,10 @@ import { Box, Button, Flex, Text } from "rebass";import * as Icon from "react-feather";import { Switch } from "@rebass/forms";import "../app.css";+import { changeTheme, isDarkTheme } from "../utils/theme";function Settings() {- const [check, setCheck] = useState(false);-+ const [check, setCheck] = useState(isDarkTheme());return (<Flex flexDirection="column" flex="1 1 auto"><Flex flexDirection="column" flex="1 1 auto">@@ -62,6 +62,7 @@ function Settings() {className="unselectable"onClick={() => {setCheck(!check);+ changeTheme();}}checked={check}/>diff --git a/apps/web/src/views/Trash.js b/apps/web/src/views/Trash.jsindex 5f976139d..09246efbc 100644--- a/apps/web/src/views/Trash.js+++ b/apps/web/src/views/Trash.js@@ -3,6 +3,7 @@ import { db, ev } from "../common";import * as Icon from "react-feather";import ListView from "../components/listview";import { ask } from "../components/dialogs";+import { showSnack } from "../components/snackbar";const dropdownRefs = [];const menuItems = item => [