diff --git a/gatsby-browser.js b/gatsby-browser.js index 2567ffd..68d5438 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1,15 +1,21 @@ import React from "react" -import { ThemeProvider } from "emotion-theming" -import Firebase, { FirebaseContext } from "./src/components/firebase" -import theme from "./src/styles/theme" - -const selectedTheme = - new Date().getHours() >= 7 && new Date().getHours() <= 21 ? "LIGHT" : "DARK" +import { ThemeProvider as EmotionThemeProvider } from "emotion-theming" +import Firebase, { FirebaseContext } from "components/firebase" +import theme from "styles/theme" +import ThemeTogglerContext, { ThemeToggler } from "components/context/theme" export const wrapRootElement = ({ element }) => { return ( - {element} + + + {({ themeName }) => ( + + {element} + + )} + + ) } diff --git a/src/App.js b/src/App.js index f75874a..4847408 100644 --- a/src/App.js +++ b/src/App.js @@ -2,11 +2,11 @@ import React, { Component } from "react" import { Router } from "@reach/router" import { compose } from "recompose" import styled from "@emotion/styled" -import { ThemeProvider } from "emotion-theming" +import { withTheme } from "emotion-theming" import { SIZES } from "./styles/constants" -import theme from "./styles/theme" +// import theme from "./styles/theme" import Navbar from "./components/Navbar" import Day from "routes/Day" import Month from "routes/Month" @@ -19,6 +19,7 @@ import PrivateRoute from "./components/PrivateRoute" import { OnlineContext } from "./components/context/online" import { withAuthentication } from "./components/session" import { withFirebase } from "./components/firebase" +import ThemeTogglerContext from "components/context/theme" const FullscreenLayout = styled.div` background-color: ${props => props.theme.colors.bodyBackground}; @@ -36,10 +37,7 @@ const RouteLayout = styled.div` class App extends Component { state = { - selectedTheme: - new Date().getHours() >= 7 && new Date().getHours() <= 21 - ? "LIGHT" - : "DARK", + selectedTheme: this.props.theme.name, } componentDidMount() { @@ -57,71 +55,62 @@ class App extends Component { }) } - onChangeTheme = () => { - const { selectedTheme } = this.state - const body = document.body - const newTheme = selectedTheme === "LIGHT" ? "DARK" : "LIGHT" - body.style.setProperty( - "background-color", - theme[newTheme].colors.bodyBackground - ) - this.setState({ selectedTheme: newTheme }) - } - render() { - const { selectedTheme, authUser, online } = this.state - const { authUser: propAuthUser } = this.props + const { authUser, online } = this.state + const { authUser: propAuthUser, theme } = this.props const authed = !!propAuthUser || !!authUser - const currentTheme = theme[selectedTheme] return ( - - - - - - - - - - - - - - - - - + + {({ toggle }) => ( + + + + + + + + + + + + + + + + )} + ) } } export default compose( withAuthentication, - withFirebase + withFirebase, + withTheme )(App) diff --git a/src/components/Navbar.js b/src/components/Navbar.js index c4692e5..cd80d2f 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -13,6 +13,7 @@ import { todayUrl, yearUrl } from "utils/date" import Logo from "components/Logo" import Icon from "components/Icon" import { withAuthentication } from "components/session" +import ThemeTogglerContext from "components/context/theme" const Header = styled.div` background-color: ${props => props.theme.colors.headerBackground}; @@ -93,16 +94,24 @@ const Navbar = ({ authUser, theme, toggleTheme }) => ( /> ) : ( - - - + <> + + + + toggleTheme()} + onKeyPress={() => toggleTheme()} + name={theme.name === "Dark" ? "Sun" : "Moon"} + /> + )} ) -const SimpleNav = ({ theme, toggleTheme }) => ( +const SimpleNav = ({ authUser, theme }) => (
) -const SimpleNavbar = withTheme(SimpleNav) +const SimpleNavbar = compose( + withAuthentication, + withTheme +)(SimpleNav) export { SimpleNavbar } diff --git a/src/components/context/theme.js b/src/components/context/theme.js new file mode 100644 index 0000000..31be356 --- /dev/null +++ b/src/components/context/theme.js @@ -0,0 +1,46 @@ +import React from "react" +import theme from "styles/theme" + +const ThemeTogglerContext = React.createContext({ + themeName: "LIGHT", + toggle: () => {}, +}) + +class ThemeToggler extends React.Component { + state = { + themeName: + new Date().getHours() >= 7 && new Date().getHours() <= 21 + ? "LIGHT" + : "DARK", + } + + toggle = () => { + const { themeName } = this.state + const body = document.body + const newTheme = themeName === "LIGHT" ? "DARK" : "LIGHT" + body.style.setProperty( + "background-color", + theme[newTheme].colors.bodyBackground + ) + this.setState({ themeName: newTheme }) + } + + render() { + const { children } = this.props + const { themeName } = this.state + return ( + + {children} + + ) + } +} + +export default ThemeTogglerContext + +export { ThemeToggler } diff --git a/src/components/elements.js b/src/components/elements.js index 2408edb..541560d 100644 --- a/src/components/elements.js +++ b/src/components/elements.js @@ -11,6 +11,18 @@ export const H1 = styled.h1` color: ${props => props.color}; ` +export const SimpleH1 = styled.h1` + color: ${props => props.color}; +` + +export const SimpleH2 = styled.h1` + color: ${props => props.color}; +` + +export const Em = styled.em` + color: ${props => props.color}; +` + export const Input = styled.input` color: ${props => props.colors.primary}; background-color: ${props => props.colors.headerBackground}; diff --git a/src/pages/login.js b/src/pages/login.js index ee37f64..155e82c 100644 --- a/src/pages/login.js +++ b/src/pages/login.js @@ -30,7 +30,10 @@ const LoginPage = ({ theme }) => ( {firebase => }

- Don't have an account? Sign Up + Don't have an account?{" "} + + Sign Up +

@@ -91,7 +94,7 @@ class LoginFormBase extends Component { Login - {error &&

{error.message}

} + {error &&

{error.message}

} ) } diff --git a/src/pages/privacy.js b/src/pages/privacy.js index 53deba0..76bf83f 100644 --- a/src/pages/privacy.js +++ b/src/pages/privacy.js @@ -1,19 +1,22 @@ import React from "react" -import { P } from "components/elements" +import { SimpleH1, SimpleH2, P, Em } from "components/elements" import Layout from "components/Layout" import Container from "components/container" +import { SimpleNavbar } from "components/Navbar" +import { withTheme } from "emotion-theming" -const Terms = () => ( +const Terms = ({ theme }) => ( + -

Privacy Policy

- Last update: April 30, 2019 + Privacy Policy + Last update: April 30, 2019{" "}

Sol Journal supports the following browsers: Chrome (latest), Safari (latest), Firefox (50+)

-

Rights

+ Rights

You don't have to provide your real name when you register to an account, but you need to use a valid/verifiable email address. @@ -43,7 +46,7 @@ const Terms = () => (
Any new features that affect privacy will be strictly opt-in.

-

Responsibilites

+ Responsibilites

You will not use the site to store illegal information or data under United States law (or any law). @@ -68,7 +71,7 @@ const Terms = () => ( (millions of entries or overloading services with requests) or use it in an unreasonable manner.

-

Other

+ Other

Other important legal stuff Though I want to provide a great service, there are certain things about the service I cannot promise. For @@ -88,4 +91,4 @@ const Terms = () => ( ) -export default Terms +export default withTheme(Terms) diff --git a/src/pages/register.js b/src/pages/register.js index 6ef3e79..3a3133a 100644 --- a/src/pages/register.js +++ b/src/pages/register.js @@ -29,7 +29,10 @@ const RegisterPage = ({ theme }) => ( {firebase => }

- Already have an account? Login + Already have an account?{" "} + + Login +

@@ -133,7 +136,7 @@ class RegisterFormBase extends Component { - {error &&

{error.message}

} + {error &&

{error.message}

} ) } diff --git a/src/pages/terms.js b/src/pages/terms.js index 3e3917e..d9470dc 100644 --- a/src/pages/terms.js +++ b/src/pages/terms.js @@ -1,20 +1,23 @@ import React from "react" -import { P } from "components/elements" +import { SimpleH1, SimpleH2, P, Em } from "components/elements" import Layout from "components/Layout" import Container from "components/container" +import { SimpleNavbar } from "components/Navbar" +import { withTheme } from "emotion-theming" -const Terms = () => ( +const Terms = ({ theme }) => ( + -

Terms of Service

- Last update: April 30, 2019 -

Scope of Service

+ Terms of Service + Last update: April 30, 2019 + Scope of Service

Sol Journal supports the following browsers: Chrome (latest), Safari (latest), Firefox (50+)

-

Rights

+ Rights

You don't have to provide your real name when you register to an account, but you need to use a valid/verifiable email address. @@ -37,7 +40,7 @@ const Terms = () => (
Any new features that affect privacy will be strictly opt-in.

-

Responsibilites

+ Responsibilites

You will not use the site to store illegal information or data under United States law (or any law). @@ -62,7 +65,7 @@ const Terms = () => ( (millions of entries or overloading services with requests) or use it in an unreasonable manner.

-

Other

+ Other

Other important legal stuff Though I want to provide a great service, there are certain things about the service I cannot promise. For @@ -82,4 +85,4 @@ const Terms = () => ( ) -export default Terms +export default withTheme(Terms) diff --git a/src/routes/Start.js b/src/routes/Start.js index 2eed77e..1ec2001 100644 --- a/src/routes/Start.js +++ b/src/routes/Start.js @@ -120,7 +120,7 @@ class Start extends Component { } `} render={data => { - return theme.name === "Light" ? ( + return theme.name === "LIGHT" ? ( ) : ( - + ) }} /> diff --git a/src/styles/theme.js b/src/styles/theme.js index fc1db2d..5ca154f 100644 --- a/src/styles/theme.js +++ b/src/styles/theme.js @@ -1,6 +1,6 @@ const theme = { LIGHT: { - name: "Light", + name: "LIGHT", colors: { logo: "#344157", primary: "#2E3136", @@ -11,10 +11,11 @@ const theme = { bodyBackground: "#FFF", inputBackground: "#FAFBFC", hover: "hsla(233, 5%, 31%, 0.12)", + button: "#f2f3f5", }, }, DARK: { - name: "Dark", + name: "DARK", colors: { logo: "#EAEAEA", primary: "#F3F6F8", @@ -25,6 +26,7 @@ const theme = { bodyBackground: "#262B34", inputBackground: "#272f3d", hover: "hsla(233, 100%, 96%, 0.12)", + button: "#464d5d", }, }, }