Skip to content

Commit

Permalink
Merge pull request #410 from brianlovin/fix-dark-mode
Browse files Browse the repository at this point in the history
Fix dark mode
  • Loading branch information
brianlovin committed Jan 3, 2020
2 parents af054f3 + 316e2d2 commit 8d82b9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
15 changes: 15 additions & 0 deletions src/components/Providers/DarkMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'
import useDarkMode from 'use-dark-mode'
import { ThemeProvider } from 'styled-components';
import { light, dark } from '~/components/Theme';

export default function DarkMode({ children }) {
const darkMode = useDarkMode(false);
const [theme, setTheme] = React.useState(light);

React.useEffect(() => {
setTheme(darkMode.value ? dark : light);
}, [darkMode, darkMode.value]);

return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
};
29 changes: 5 additions & 24 deletions src/components/Providers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
import * as React from 'react'
import { ThemeProvider } from 'styled-components';
import useDarkMode from 'use-dark-mode'
import GlobalStyles from '~/components/GlobalStyles';
import { light, dark } from '~/components/Theme';
import FathomProvider from './Fathom'
import SEO from './SEO'
import DarkMode from './DarkMode';

interface Props {
children?: any;
}

export default ({ children }: Props) => {
const { value } = useDarkMode(false, { storageKey: null, onChange: null })
const theme = value ? dark : light

const [mounted, setMounted] = React.useState(false)

React.useEffect(() => {
setMounted(true)
}, [])

const body =
return (
<FathomProvider>
<SEO />

<ThemeProvider theme={theme}>
<DarkMode>
<GlobalStyles.ResetStyles />
{children}
</ThemeProvider>
</DarkMode>
</FathomProvider>

// prevents ssr flash for mismatched dark mode
if (!mounted) {
return (
<div style={{ visibility: 'hidden' }}>{body}</div>
)
}

return body
)
}
2 changes: 1 addition & 1 deletion src/firebase/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getMetadata = async (url) => {
null

return {
url,
url: url.toLowerCase(),
host,
title: $('title').first().text(),
description: getMetavalue('description'),
Expand Down

0 comments on commit 8d82b9a

Please sign in to comment.