client: dark mode

This commit is contained in:
Max Leiter 2022-03-09 02:06:03 -08:00
parent d8447f759d
commit 252d16866f
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A3512F2F2F17EBDA
4 changed files with 48 additions and 23 deletions

View file

@ -1,5 +1,5 @@
import { Page, ButtonGroup, Button, useBodyScroll, useMediaQuery, useTheme, Tabs, Loading, Spacer } from "@geist-ui/core"; import { Page, ButtonGroup, Button, useBodyScroll, useMediaQuery, useTheme, Tabs, Loading, Spacer } from "@geist-ui/core";
import { Github as GitHubIcon, UserPlus as SignUpIcon, User as SignInIcon, Home as HomeIcon, Menu as MenuIcon, Tool as SettingsIcon, UserX as SignoutIcon, PlusCircle as NewIcon, List as YourIcon } from "@geist-ui/icons"; import { Github as GitHubIcon, UserPlus as SignUpIcon, User as SignInIcon, Home as HomeIcon, Menu as MenuIcon, Tool as SettingsIcon, UserX as SignoutIcon, PlusCircle as NewIcon, List as YourIcon, Moon, Sun } from "@geist-ui/icons";
import { DriftProps } from "../../pages/_app"; import { DriftProps } from "../../pages/_app";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import styles from './header.module.css'; import styles from './header.module.css';
@ -28,19 +28,22 @@ const Header = ({ changeTheme, theme }: DriftProps) => {
name: "Home", name: "Home",
href: "/", href: "/",
icon: <HomeIcon />, icon: <HomeIcon />,
condition: true condition: true,
value: "home"
}, },
{ {
name: "New", name: "New",
href: "/new", href: "/new",
icon: <NewIcon />, icon: <NewIcon />,
condition: isSignedIn condition: isSignedIn,
value: "new"
}, },
{ {
name: "Yours", name: "Yours",
href: "/mine", href: "/mine",
icon: <YourIcon />, icon: <YourIcon />,
condition: isSignedIn condition: isSignedIn,
value: "mine"
}, },
// { // {
// name: "Settings", // name: "Settings",
@ -57,27 +60,42 @@ const Header = ({ changeTheme, theme }: DriftProps) => {
} }
}, },
icon: <SignoutIcon />, icon: <SignoutIcon />,
condition: isSignedIn condition: isSignedIn,
value: "signout"
}, },
{ {
name: "Sign in", name: "Sign in",
href: "/signin", href: "/signin",
icon: <SignInIcon />, icon: <SignInIcon />,
condition: !isSignedIn condition: !isSignedIn,
value: "signin"
}, },
{ {
name: "Sign up", name: "Sign up",
href: "/signup", href: "/signup",
icon: <SignUpIcon />, icon: <SignUpIcon />,
condition: !isSignedIn condition: !isSignedIn,
value: "signup"
}, },
{ {
name: isMobile ? "GitHub" : "", name: isMobile ? "GitHub" : "",
href: "https://github.com/maxleiter/drift", href: "https://github.com/maxleiter/drift",
icon: <GitHubIcon />, icon: <GitHubIcon />,
condition: true condition: true,
value: "github"
},
{
name: isMobile ? "Change theme" : "",
action: function () {
if (typeof window !== 'undefined') {
changeTheme();
}
},
icon: theme === 'light' ? <Moon /> : <Sun />,
condition: true,
value: "theme",
} }
], [isMobile, isSignedIn, router]) ], [changeTheme, isMobile, isSignedIn, router, theme])
useEffect(() => { useEffect(() => {
setSelectedTab(pages.find((page) => { setSelectedTab(pages.find((page) => {
@ -98,20 +116,20 @@ const Header = ({ changeTheme, theme }: DriftProps) => {
hideDivider hideDivider
hideBorder hideBorder
onChange={(tab) => { onChange={(tab) => {
const nameMatch = pages.find(page => page.name === tab) const match = pages.find(page => page.value === tab)
if (nameMatch?.action) { if (match?.action) {
nameMatch.action() match.action()
} else { } else if (match?.href) {
router.push(`${tab}`) router.push(`${match.href}`)
} }
}}> }}>
{!isLoading && pages.map((tab, index) => { {!isLoading && pages.map((tab) => {
if (tab.condition) if (tab.condition)
return <Tabs.Item return <Tabs.Item
font="14px" font="14px"
label={<>{tab.icon} {tab.name}</>} label={<>{tab.icon} {tab.name}</>}
value={tab.href || tab.name} value={tab.value}
key={`${tab.name}-${index}`} key={`${tab.value}`}
/> />
else return null else return null
})} })}
@ -124,7 +142,7 @@ const Header = ({ changeTheme, theme }: DriftProps) => {
onClick={() => setExpanded(!expanded)} onClick={() => setExpanded(!expanded)}
> >
<Spacer height={5 / 6} width={0} /> <Spacer height={5 / 6} width={0} />
<MenuIcon size="1.5rem" /> <MenuIcon />
</Button> </Button>
</div> </div>
{isMobile && expanded && (<div className={styles.mobile}> {isMobile && expanded && (<div className={styles.mobile}>

View file

@ -8,6 +8,9 @@ const titlePlaceholders = [
"Status update for ...", "Status update for ...",
"My new project", "My new project",
"My new idea", "My new idea",
"Let's talk about...",
"What's up with ...",
"I'm thinking about ...",
] ]
type props = { type props = {
@ -25,7 +28,7 @@ const Title = ({ setTitle, title }: props) => {
onChange={(event) => setTitle(event.target.value)} onChange={(event) => setTitle(event.target.value)}
height={"55px"} height={"55px"}
font={1.5} font={1.5}
label="Your title" label="Post title"
marginLeft={'var(--gap)'} marginLeft={'var(--gap)'}
style={{ width: "100%" }} style={{ width: "100%" }}
/> />

View file

@ -1,8 +1,6 @@
const dotenv = require("dotenv"); const dotenv = require("dotenv");
dotenv.config(); dotenv.config();
console.log(`${process.env.API_URL}/:path*`);
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
reactStrictMode: true, reactStrictMode: true,

View file

@ -1,6 +1,6 @@
import '../styles/globals.css' import '../styles/globals.css'
import { GeistProvider, CssBaseline } from '@geist-ui/core' import { GeistProvider, CssBaseline } from '@geist-ui/core'
import { useState } from 'react' import { useEffect, useState } from 'react'
import type { AppProps as NextAppProps } from "next/app"; import type { AppProps as NextAppProps } from "next/app";
export type ThemeProps = { export type ThemeProps = {
@ -15,7 +15,13 @@ type AppProps<P = any> = {
export type DriftProps = ThemeProps export type DriftProps = ThemeProps
function MyApp({ Component, pageProps }: AppProps<ThemeProps>) { function MyApp({ Component, pageProps }: AppProps<ThemeProps>) {
const [themeType, setThemeType] = useState<string>(typeof window !== 'undefined' ? localStorage.getItem('drift-theme') || 'light' : 'light') const [themeType, setThemeType] = useState<string>('light')
useEffect(() => {
if (typeof window === 'undefined' || !window.localStorage) return
const storedTheme = window.localStorage.getItem('drift-theme')
if (storedTheme) setThemeType(storedTheme)
}, [])
const changeTheme = () => { const changeTheme = () => {
const newTheme = themeType === 'dark' ? 'light' : 'dark' const newTheme = themeType === 'dark' ? 'light' : 'dark'