Skip to content

Commit

Permalink
Add dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshusingla authored May 7, 2020
1 parent 5c9edf4 commit 2a32c7b
Show file tree
Hide file tree
Showing 19 changed files with 578 additions and 482 deletions.
30 changes: 22 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import React, { useState } from "react";
import React, { useState, useMemo } from "react";
import { BrowserRouter, Switch, Route, Redirect } from "react-router-dom";
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";

import Mainframe from "./Mainframe";
import Login from "./screens/login";

function App() {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [isAuthenticated, setIsAuthenticated] = useState(true);
const [useDarkMode, setUseDarkMode] = useState(true);

const theme = useMemo(
() =>
createMuiTheme({
palette: {
type: useDarkMode ? "dark" : "light",
},
}),
[useDarkMode]
);

function PrivateRoute(props) {
return (
Expand All @@ -19,12 +31,14 @@ function App() {
}

return (
<BrowserRouter>
<Switch>
<Route exact path="/login" component={Login} />
<PrivateRoute path="/" component={Mainframe} />
</Switch>
</BrowserRouter>
<ThemeProvider theme={theme}>
<BrowserRouter>
<Switch>
<Route exact path="/login" component={Login} />
<PrivateRoute path="/" component={Mainframe} />
</Switch>
</BrowserRouter>
</ThemeProvider>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mainframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Mainframe(props) {
<Route path="/profile" component={screens.Profile} />
<Route path="/streams" component={screens.Streams} />
<Route exact path="/stream/:id" component={screens.Stream} />
<Route path="/stream/:id/newpost" component={screens.NewPost} />
<Route path="/stream/:id/new" component={screens.CreatePost} />
<Route render={() => <h1>404: page not found</h1>} />
</Switch>
);
Expand Down
Empty file.
Empty file.
65 changes: 35 additions & 30 deletions src/components/MaximisedPost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,54 @@ import CardMedia from "@material-ui/core/CardMedia";
import CardContent from "@material-ui/core/CardContent";
import Avatar from "@material-ui/core/Avatar";
import Typography from "@material-ui/core/Typography";
import { red, blue } from "@material-ui/core/colors";
import { red, indigo, grey, blueGrey } from "@material-ui/core/colors";

const useStyles = makeStyles((theme) => ({
card: {
width: "100%",
backgroundColor: "white",
textAlign: "left",
justifyContent: "left",
alignContent: "left",
},
avatar: {
backgroundColor: red[500],
},
title: {
color: "white",
},
subheader: {
color: "white",
},
img: {
height: 500,
},
}));
const useStyles = makeStyles((theme) => {
const dark = theme.palette.type === "dark";
return {
card: {
width: "100%",
textAlign: "left",
justifyContent: "left",
alignContent: "left",
},
avatar: {
backgroundColor: red[500],
},
title: { color: dark ? indigo["100"] : grey["50"] },
subheader: { color: dark ? indigo["300"] : grey["500"] },
img: {
height: 500,
},
header: {
textAlign: "left",
backgroundColor: dark ? indigo["900"] : indigo["700"],
},
};
});

export default function MaximisedPost(props) {
const classes = useStyles();

return (
<Card className={classes.card}>
<CardHeader
classes={{ title: classes.title, subheader: classes.subheader }}
avatar={
<Avatar aria-label={props.postAuthor} className={classes.avatar}>
P
</Avatar>
}
title={props.postTitle}
subheader={props.postAuthor}
style={{
textAlign: "left",
backgroundColor: "#1565c0",
color: "white",
}}
title={
<Typography className={classes.title} variant="h5">
{props.postTitle}
</Typography>
}
subheader={
<Typography className={classes.subheader}>
{props.postAuthor}
</Typography>
}
className={classes.header}
/>
<CardMedia
className={classes.img}
Expand Down
1 change: 0 additions & 1 deletion src/components/MinimizedPost/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import "./style.css";

/* Using Material UI */
import { Card } from "@material-ui/core";
Expand Down
Empty file.
40 changes: 28 additions & 12 deletions src/components/Topbar/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import "./style.css";

/*using Material UI*/

Expand All @@ -8,16 +7,31 @@ import { AppBar } from "@material-ui/core";
import { Toolbar } from "@material-ui/core";
import { IconButton } from "@material-ui/core";
import MenuIcon from "@material-ui/icons/Menu";
import Search from "@material-ui/icons/Search";
import SearchIcon from "@material-ui/icons/Search";
import { Typography } from "@material-ui/core";
import { grey, indigo } from "@material-ui/core/colors";

const useStyles = makeStyles((theme) => ({
topbar: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
},
}));
const useStyles = makeStyles((theme) => {
const dark = theme.palette.type === "dark";

return {
topbar: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
backgroundColor: dark ? indigo["900"] : indigo["700"],
},
title: {
color: dark ? indigo["100"] : grey["100"],
},
menuIcon: {
color: dark ? indigo["300"] : grey["100"],
},
searchIcon: {
color: dark ? indigo["300"] : grey["100"],
},
};
});

function Topbar(props) {
const classes = useStyles();
Expand All @@ -26,13 +40,15 @@ function Topbar(props) {
<AppBar className={classes.topbar} position="sticky">
<Toolbar>
<IconButton edge="start" color="inherit" aria-label="menu">
<MenuIcon />
<MenuIcon className={classes.menuIcon} />
</IconButton>
<Typography variant="h6">{props.title}</Typography>
<Typography variant="h5" className={classes.title}>
{props.title}
</Typography>
</Toolbar>
<Toolbar>
<IconButton edge="start" color="inherit" aria-label="menu">
<Search />
<SearchIcon className={classes.searchIcon} />
</IconButton>
</Toolbar>
</AppBar>
Expand Down
Empty file removed src/components/Topbar/style.css
Empty file.
66 changes: 39 additions & 27 deletions src/components/comment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import Avatar from "@material-ui/core/Avatar";
import IconButton from "@material-ui/core/IconButton";
import Button from "@material-ui/core/Button";
import Typography from "@material-ui/core/Typography";
import { red, orange, purple, pink, green } from "@material-ui/core/colors";
import {
red,
orange,
purple,
pink,
green,
grey,
} from "@material-ui/core/colors";
import ReplyIcon from "@material-ui/icons/Reply";
import ThumbUpIcon from "@material-ui/icons/ThumbUp";
import ThumbDownIcon from "@material-ui/icons/ThumbDown";
Expand All @@ -46,21 +53,27 @@ import { Toolbar } from "@material-ui/core";

const spacing = 60; //It controls spacing between nested comments

const useStyles = makeStyles((theme) => ({
main: {
margin: 10,
maxWidth: "80em", //max width of comment box
},
contentShown: { overflowWrap: "break-word" },
contentHidden: { marginLeft: "1em", flexShrink: "true" },
authorHidden: {
marginLeft: "0.5em",
fontWeight: "bold",
minWidth: "4em",
maxWidth: "6em",
},
indent: { marginLeft: spacing },
}));
const useStyles = makeStyles((theme) => {
const dark = theme.palette.type === "dark";
return {
main: {
margin: 10,
maxWidth: "80em", //max width of comment box
},
contentShown: { overflowWrap: "break-word" },
contentHidden: { marginLeft: "1em", flexShrink: "true" },
authorHidden: {
marginLeft: "0.5em",
fontWeight: "bold",
minWidth: "4em",
maxWidth: "6em",
},
indent: { marginLeft: spacing },
header: {
backgroundColor: dark ? grey["700"] : grey["300"],
},
};
});

// Generate random color for avatar
const colorArray = [red, orange, purple, pink, green];
Expand Down Expand Up @@ -210,17 +223,16 @@ function MaximisedComment(props) {
return (
<Card className={classes.main}>
{/* Comment Header */}
<div className="header">
<CardHeader
avatar={<AvatarProp {...props} />}
title={
<Typography noWrap>
<b>{props.author}</b>
</Typography>
}
subheader={<i>{props.date}</i>}
/>
</div>
<CardHeader
avatar={<AvatarProp {...props} />}
title={
<Typography noWrap>
<b>{props.author}</b>
</Typography>
}
subheader={<i>{props.date}</i>}
className={classes.header}
/>
{/* Comment Body */}
<CardContent>
<Typography
Expand Down
4 changes: 0 additions & 4 deletions src/components/comment/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.header {
background-color: rgb(236, 240, 241);
}

.actions {
margin-left: auto;
}
Expand Down
42 changes: 37 additions & 5 deletions src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,49 @@ import ListItemIcon from "@material-ui/core/ListItemIcon";
import ListItemText from "@material-ui/core/ListItemText";
import AccountCircleIcon from "@material-ui/icons/AccountCircle";
import ChevronRightIcon from "@material-ui/icons/ChevronRight";
import { withStyles } from "@material-ui/core/styles";
import { makeStyles } from "@material-ui/core/styles";
import "./style.css";
import { Typography } from "@material-ui/core";
import { indigo, grey, blueGrey } from "@material-ui/core/colors";

const useStyles = makeStyles((theme) => {
const dark = theme.palette.type === "dark";
return {
profileName: {
color: dark ? grey["400"] : indigo["900"],
},
accountCircleIcon: {
color: dark ? indigo["400"] : indigo["900"],
},
appName: {
textAlign: "center",
fontSize: "28px",
padding: "10px",
backgroundColor: dark ? grey["700"] : indigo["700"],
color: dark ? indigo["50"] : indigo["50"],
},
};
});

const styles = {
root: {
minWidth: 40,
color: "black",
},
};
function Profile(props) {
const classes = useStyles();
// AccountCircleIcon can be replaced by Avatar when we add Profile Picture functionality
return (
<Button color="primary" startIcon={<AccountCircleIcon />} fullWidth>
{props.name}
<Button
color="primary"
startIcon={
<Typography className={classes.accountCircleIcon}>
<AccountCircleIcon />
</Typography>
}
fullWidth
>
<Typography className={classes.profileName}>{props.name}</Typography>
</Button>
);
}
Expand Down Expand Up @@ -52,10 +81,13 @@ function StreamsList(props) {
}

function Sidebar(props) {
const classes = useStyles();
return (
<nav>
<Drawer variant="permanent" anchor="left" width="100%">
<div class="app-name">Campus Discuss</div>
<Typography variant="h4" className={classes.appName}>
Campus Discuss
</Typography>
<div className="streams-list-wrapper">
<StreamsList streams={props.streams} />
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/sidebar/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.app-name {
text-align: center;
font-size: 28px;
background-color: rgba(45, 51, 115, 0.1);
padding: 10px;
}
.streams-list {
Expand Down
Loading

0 comments on commit 2a32c7b

Please sign in to comment.