Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/NavBar/DarkMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { makeStyles } from "@material-ui/core";
import { Theme } from "../../theme";

const useDarkGlobalStyles = makeStyles((theme: Theme) => {
return {
"@global": {
body: {
backgroundColor: theme.darkMode.backgroundColor,
},
},
};
});
const DarkMode = () => {
useDarkGlobalStyles();
return <></>;
};

export default DarkMode;
16 changes: 13 additions & 3 deletions src/components/NavBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { useContext, useCallback, useState } from "react";
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
import { createStyles, makeStyles } from "@material-ui/core/styles";
import AppBar from "@material-ui/core/AppBar";
import Toolbar from "@material-ui/core/Toolbar";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import { Link, withRouter } from "react-router-dom";
import { AppContext } from "../../state";
import { AppContext, AppActions } from "../../state";
import { IconButton, Menu, MenuItem, Avatar } from "@material-ui/core";
import AccountCircle from "@material-ui/icons/AccountCircle";
import InvertColors from "@material-ui/icons/InvertColors";
import { RouteChildrenProps } from "react-router";
import { FirebaseContext } from "../Firebase";
import { Theme } from "../../theme";
import DarkMode from "./DarkMode";

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand All @@ -36,7 +39,7 @@ const NavBar = ({ history }: RouteChildrenProps) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [open, setOpen] = useState(false);

const { user } = useContext(AppContext);
const { user, isDarkModeEnabled, dispatch } = useContext(AppContext);

const handleProfileMenuOpen = useCallback(
(event: React.MouseEvent<HTMLElement>) => {
Expand All @@ -60,6 +63,7 @@ const NavBar = ({ history }: RouteChildrenProps) => {

return (
<div className={classes.root}>
{isDarkModeEnabled && <DarkMode />}
<AppBar position="static">
<Toolbar>
<Typography variant="h6" className={classes.title}>
Expand Down Expand Up @@ -88,6 +92,12 @@ const NavBar = ({ history }: RouteChildrenProps) => {
>
Teams
</Button>
<Button
onClick={() => dispatch({ type: AppActions.TOGGLE_DARK_MODE })}
className={classes.linkButtons}
>
<InvertColors />
</Button>
<IconButton
edge="end"
aria-label="account of current user"
Expand Down
3 changes: 2 additions & 1 deletion src/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ export enum AppActions {
AUTH_STATE_CHANGED,
TEAMS_GENERATED,
TOURNAMENT_CREATED,
TOGGLE_DARK_MODE
}

export interface Action {
type: AppActions;
payload: any;
payload?: any;
}
7 changes: 7 additions & 0 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ interface AppState {
user: User | null;
generatedTeams: Team[];
dispatch: React.Dispatch<Action>;
isDarkModeEnabled: boolean;
}

export const initialState = {
user: null,
generatedTeams: [],
dispatch: () => {},
isDarkModeEnabled: false
};

export const AppContext = React.createContext<AppState>(initialState);
Expand All @@ -35,6 +37,11 @@ export const reducerApp = (state: AppState, action: Action) => {
...state,
generatedTeams: [],
};
case AppActions.TOGGLE_DARK_MODE:
return {
...state,
isDarkModeEnabled: !state.isDarkModeEnabled
};
default:
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const expandedTheme = {
...customTheme,
status: {
danger: "orange"
},
darkMode: {
backgroundColor: "#3e3340",
auxColor: "#856c89",
linkColor: "#161417"
}
};

Expand Down