From 2a32c7b70e5eeb5bdde65ebb8be69ff4635c9355 Mon Sep 17 00:00:00 2001 From: devanshu singla <56247443+devanshusingla@users.noreply.github.com> Date: Fri, 8 May 2020 00:32:32 +0530 Subject: [PATCH] Add dark mode --- src/App.js | 30 +- src/Mainframe.js | 2 +- src/components/CommentReplies/style.css | 0 src/components/CommentsContainer/style.css | 0 src/components/MaximisedPost/index.js | 65 +-- src/components/MinimizedPost/index.js | 1 - src/components/MinimizedPost/style.css | 0 src/components/Topbar/index.js | 40 +- src/components/Topbar/style.css | 0 src/components/comment/index.js | 66 +-- src/components/comment/style.css | 4 - src/components/sidebar/index.js | 42 +- src/components/sidebar/style.css | 1 - src/screens/createPost/index.js | 211 +++++---- src/screens/index.js | 12 +- src/screens/login/index.js | 72 +-- src/screens/profile/index.js | 481 ++++++++++----------- src/screens/profile/style.css | 3 - yarn.lock | 30 ++ 19 files changed, 578 insertions(+), 482 deletions(-) delete mode 100644 src/components/CommentReplies/style.css delete mode 100644 src/components/CommentsContainer/style.css delete mode 100644 src/components/MinimizedPost/style.css delete mode 100644 src/components/Topbar/style.css delete mode 100644 src/screens/profile/style.css diff --git a/src/App.js b/src/App.js index e8309d2..2178682 100644 --- a/src/App.js +++ b/src/App.js @@ -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 ( @@ -19,12 +31,14 @@ function App() { } return ( - - - - - - + + + + + + + + ); } diff --git a/src/Mainframe.js b/src/Mainframe.js index 6c72133..17f077e 100644 --- a/src/Mainframe.js +++ b/src/Mainframe.js @@ -9,7 +9,7 @@ function Mainframe(props) { - + 404: page not found} /> ); diff --git a/src/components/CommentReplies/style.css b/src/components/CommentReplies/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/CommentsContainer/style.css b/src/components/CommentsContainer/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/MaximisedPost/index.js b/src/components/MaximisedPost/index.js index e720526..e0c6580 100644 --- a/src/components/MaximisedPost/index.js +++ b/src/components/MaximisedPost/index.js @@ -6,29 +6,31 @@ 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(); @@ -36,19 +38,22 @@ export default function MaximisedPost(props) { return ( P } - title={props.postTitle} - subheader={props.postAuthor} - style={{ - textAlign: "left", - backgroundColor: "#1565c0", - color: "white", - }} + title={ + + {props.postTitle} + + } + subheader={ + + {props.postAuthor} + + } + className={classes.header} /> ({ - 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(); @@ -26,13 +40,15 @@ function Topbar(props) { - + - {props.title} + + {props.title} + - + diff --git a/src/components/Topbar/style.css b/src/components/Topbar/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/comment/index.js b/src/components/comment/index.js index cb2a3f5..e46585c 100644 --- a/src/components/comment/index.js +++ b/src/components/comment/index.js @@ -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"; @@ -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]; @@ -210,17 +223,16 @@ function MaximisedComment(props) { return ( {/* Comment Header */} - - } - title={ - - {props.author} - - } - subheader={{props.date}} - /> - + } + title={ + + {props.author} + + } + subheader={{props.date}} + className={classes.header} + /> {/* Comment Body */} { + 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 ( - } fullWidth> - {props.name} + + + + } + fullWidth + > + {props.name} ); } @@ -52,10 +81,13 @@ function StreamsList(props) { } function Sidebar(props) { + const classes = useStyles(); return ( - Campus Discuss + + Campus Discuss + diff --git a/src/components/sidebar/style.css b/src/components/sidebar/style.css index c2eec76..a5ca56c 100644 --- a/src/components/sidebar/style.css +++ b/src/components/sidebar/style.css @@ -8,7 +8,6 @@ .app-name { text-align: center; font-size: 28px; - background-color: rgba(45, 51, 115, 0.1); padding: 10px; } .streams-list { diff --git a/src/screens/createPost/index.js b/src/screens/createPost/index.js index 6974850..fb45270 100644 --- a/src/screens/createPost/index.js +++ b/src/screens/createPost/index.js @@ -10,53 +10,69 @@ import Button from "@material-ui/core/Button"; import CloudUploadIcon from "@material-ui/icons/CloudUpload"; import SendIcon from "@material-ui/icons/Send"; import { DropzoneDialog } from "material-ui-dropzone"; +import { Typography } from "@material-ui/core"; +import { blueGrey, indigo, grey } from "@material-ui/core/colors"; -const useStyles = makeStyles((theme) => ({ - button: { - margin: theme.spacing(1), - width: "100%", - }, - card: { - width: "100%", - backgroundColor: "white", - textAlign: "left", - justifyContent: "left", - alignContent: "left", - }, - avatar: { - backgroundColor: "white", - }, - root: { - "& .MuiTextField-root": { +const useStyles = makeStyles((theme) => { + const dark = theme.palette.type === "dark"; + return { + outer: { + height: "100vh", + width: "100vw", + backgroundColor: dark ? grey["900"] : blueGrey["50"], + borderRadius: 0, + }, + header: { + textAlign: "left", + backgroundColor: dark ? indigo["900"] : indigo["700"], + }, + submitButton: { margin: theme.spacing(1), width: "100%", + backgroundColor: dark ? indigo["900"] : indigo["600"], + color: dark ? blueGrey["100"] : blueGrey["50"], }, - "& > *": { - margin: theme.spacing(1), + uploadButton: { + backgroundColor: dark ? indigo["900"] : indigo["600"], + color: dark ? blueGrey["100"] : blueGrey["50"], + }, + card: { + width: "100%", + textAlign: "left", + justifyContent: "left", + alignContent: "left", + }, + avatar: { + backgroundColor: dark ? blueGrey["100"] : blueGrey["50"], + }, + root: { + "& .MuiTextField-root": { + margin: theme.spacing(1), + width: "100%", + }, + "& > *": { + margin: theme.spacing(1), + }, }, - }, - input: { - display: "none", - }, - title: { - fontSize: "large", - color: "white", - }, - subheader: { - fontSize: "large", - color: "white", - }, + input: { + display: "none", + }, + title: { color: dark ? indigo["100"] : grey["50"] }, + subheader: { color: dark ? indigo["300"] : indigo["100"] }, - img: { - height: 500, - }, -})); + img: { + height: 500, + }, + }; +}); function DropzoneDialogExample(props) { const [open, setOpen] = useState(false); const [files, setFiles] = useState([]); const [arr, setArr] = useState([]); + const classes = useStyles(); + const handleClose = () => { setOpen(false); }; @@ -89,6 +105,7 @@ function DropzoneDialogExample(props) { } onClick={handleOpen} @@ -107,7 +124,7 @@ function DropzoneDialogExample(props) { ); } -export default function Maxmised(props) { +export default function CreatePost(props) { const inputEl1 = useRef(null); const inputEl2 = useRef(null); const classes = useStyles(); @@ -139,65 +156,71 @@ export default function Maxmised(props) { }; return ( - - - - - } - title="CREATE POST" - subheader={props.stream} - style={{ - textAlign: "left", - backgroundColor: "#3f51b5", - }} - /> + + + + + + } + title={ + + CREATE POST + + } + subheader={ + + {props.stream} + + } + className={classes.header} + /> - - - - - - - - - - - - - } - onClick={validateandSubmit} - > - Submit - - - - + + + + + + + + + + + + + } + onClick={validateandSubmit} + > + Submit + + + + + ); } diff --git a/src/screens/index.js b/src/screens/index.js index a6cf136..09c4c3f 100644 --- a/src/screens/index.js +++ b/src/screens/index.js @@ -2,6 +2,8 @@ import React from "react"; //exporting screens from this folder. import Login from "./login"; +import Profile from "./profile"; +import CreatePost from "./createPost"; //screens examples till they are not created. @@ -9,10 +11,6 @@ function Home(props) { return Home; } -function Profile(props) { - return Profile; -} - function Streams(props) { return All Streams; } @@ -21,8 +19,4 @@ function Stream(props) { return Stream; } -function NewPost(props) { - return Waiting for new post; -} - -export default { Home, Login, Profile, Streams, Stream, NewPost }; +export default { Home, Login, Profile, Streams, Stream, CreatePost }; diff --git a/src/screens/login/index.js b/src/screens/login/index.js index 73fced9..67a0bbe 100644 --- a/src/screens/login/index.js +++ b/src/screens/login/index.js @@ -12,40 +12,46 @@ import Grid from "@material-ui/core/Grid"; import LockOutlinedIcon from "@material-ui/icons/LockOutlined"; import Typography from "@material-ui/core/Typography"; import { makeStyles } from "@material-ui/core/styles"; +import { blueGrey, indigo } from "@material-ui/core/colors"; -const useStyles = makeStyles((theme) => ({ - root: { - height: "100vh", - }, - image: { - backgroundImage: - "url(https://cdn4.vectorstock.com/i/1000x1000/33/28/discussion-and-communication-in-the-office-vector-22823328.jpg)", - backgroundRepeat: "no-repeat", - backgroundColor: - theme.palette.type === "light" - ? theme.palette.grey[50] - : theme.palette.grey[900], - backgroundSize: "cover", - backgroundPosition: "center", - }, - paper: { - margin: theme.spacing(8, 4), - display: "flex", - flexDirection: "column", - alignItems: "center", - }, - avatar: { - margin: theme.spacing(1), - backgroundColor: theme.palette.secondary.main, - }, - form: { - width: "100%", // Fix IE 11 issue. - marginTop: theme.spacing(1), - }, - submit: { - margin: theme.spacing(3, 0, 2), - }, -})); +const useStyles = makeStyles((theme) => { + const dark = theme.palette.type === "dark"; + return { + root: { + height: "100vh", + }, + image: { + backgroundImage: + "url(https://cdn4.vectorstock.com/i/1000x1000/33/28/discussion-and-communication-in-the-office-vector-22823328.jpg)", + backgroundRepeat: "no-repeat", + backgroundColor: + theme.palette.type === "light" + ? theme.palette.grey[50] + : theme.palette.grey[900], + backgroundSize: "cover", + backgroundPosition: "center", + }, + paper: { + margin: theme.spacing(8, 4), + display: "flex", + flexDirection: "column", + alignItems: "center", + }, + avatar: { + margin: theme.spacing(1), + backgroundColor: theme.palette.secondary.main, + }, + form: { + width: "100%", // Fix IE 11 issue. + marginTop: theme.spacing(1), + }, + submit: { + margin: theme.spacing(3, 0, 2), + backgroundColor: dark ? indigo["900"] : indigo["600"], + color: dark ? blueGrey["100"] : blueGrey["50"], + }, + }; +}); function Copyright() { return ( diff --git a/src/screens/profile/index.js b/src/screens/profile/index.js index 8314fe1..7e632cd 100644 --- a/src/screens/profile/index.js +++ b/src/screens/profile/index.js @@ -14,36 +14,52 @@ import { Typography, LinearProgress, } from "@material-ui/core"; -import Topbar from "../../components/Topbar/index"; +import Topbar from "../../components/Topbar"; import Link from "@material-ui/core/Link"; -import "./style.css"; +import { indigo, blueGrey, grey } from "@material-ui/core/colors"; -const useStyles = makeStyles(() => ({ - root: { - padding: 10, - margin: 10, - }, - details: { - display: "flex", - }, - avatar: { - marginLeft: "auto", - height: 110, - width: 100, - flexShrink: 0, - flexGrow: 0, - }, - progress: { - marginTop: "2px", - }, - uploadButton: { - marginRight: "2px", - }, - profile2: { - height: 1100, - width: 800, - }, -})); +const useStyles = makeStyles((theme) => { + const dark = theme.palette.type === "dark"; + return { + outer: { + height: "100vh", + width: "100vw", + backgroundColor: dark ? grey["900"] : blueGrey["50"], + borderRadius: 0, + }, + root: { + padding: 10, + margin: 10, + }, + details: { + display: "flex", + }, + avatar: { + marginLeft: "auto", + height: 110, + width: 100, + flexShrink: 0, + flexGrow: 0, + }, + progress: { + marginTop: "2px", + }, + uploadButton: { + marginRight: "2px", + }, + uploadText: { + color: dark ? indigo["400"] : indigo["600"], + }, + submitButton: { + backgroundColor: dark ? indigo["900"] : indigo["600"], + color: dark ? blueGrey["100"] : blueGrey["50"], + }, + profile2: { + height: 1100, + width: 800, + }, + }; +}); const Profile = (props) => { const { ...rest } = props; @@ -60,7 +76,7 @@ const Profile = (props) => { following: props.following, hall: props.hall, }); - + //Handle change in text fields and update profile completeness const [completenessIndex, setCompletenessIndex] = useState(0); @@ -103,247 +119,204 @@ const Profile = (props) => { alert("Details saved!"); }; - const halls = [ - { - value: "1", - label: "Hall 1", - }, - { - value: "2", - label: "Hall 2", - }, - { - value: "3", - label: "Hall 3", - }, - { - value: "4", - label: "Hall 4", - }, - { - value: "5", - label: "Hall 5", - }, - { - value: "6", - label: "Hall 6", - }, - { - value: "7", - label: "Hall 7", - }, - { - value: "8", - label: "Hall 8", - }, - { - value: "9", - label: "Hall 9", - }, - { - value: "10", - label: "Hall 10", - }, - { - value: "11", - label: "Hall 11", - }, - { - value: "12", - label: "Hall 12", - }, - { - value: "13", - label: "Hall 13", - }, - ]; + const halls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13].map((val) => { + return { + value: val, + label: "Hall " + val, + }; + }); return ( - - - - - - - - - - {values.firstName} {values.lastName} - {{values.nickname}} - - - Following: {values.following} - - - Followers: {values.followers} + + + + + + + + + + + {values.firstName} {values.lastName} + {{values.nickname}} + + + Following: {values.following} + + + Followers: {values.followers} + + + + + + + Profile Completeness: {completenessIndex}% + - - - - - Profile Completeness: {completenessIndex}% - - - - - - - - - - Upload Picture - - - - - - Remove picture - - - - - - - - - - - - - - - - - - - - - - - - - - - - {halls.map((option) => ( - - {option.label} - - ))} - - - - - Save details + + + + + Upload Picture + + + + + + + Remove picture - - + + + + + + + + + + + + + + + + + + + + + + + + + + {halls.map((option) => ( + + {option.label} + + ))} + + + + + + + + Save details + + + + + - - - + + + ); }; Profile.propTypes = { - name: PropTypes.string, - userName: PropTypes.string, - email: PropTypes.string, - fblink: PropTypes.string, - followers: PropTypes.number, - following: PropTypes.number, - hall: PropTypes.number, + name: PropTypes.string, + userName: PropTypes.string, + email: PropTypes.string, + fblink: PropTypes.string, + followers: PropTypes.number, + following: PropTypes.number, + hall: PropTypes.number, }; export default Profile; diff --git a/src/screens/profile/style.css b/src/screens/profile/style.css deleted file mode 100644 index dab0a47..0000000 --- a/src/screens/profile/style.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background-color: #f5f5ef; -} diff --git a/yarn.lock b/yarn.lock index 3610074..6ad33df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2124,6 +2124,11 @@ atob@^2.1.2: resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +attr-accept@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.1.0.tgz#a231a854385d36ff7a99647bb77b33c8a5175aee" + integrity sha512-sLzVM3zCCmmDtDNhI0i96k6PUztkotSOXqE4kDGQt/6iDi5M+H0srjeF+QC6jN581l4X/Zq3Zu/tgcErEssavg== + autoprefixer@^9.6.1: version "9.7.4" resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.7.4.tgz#f8bf3e06707d047f0641d87aee8cfb174b2a5378" @@ -4413,6 +4418,13 @@ file-loader@4.3.0: loader-utils "^1.2.3" schema-utils "^2.5.0" +file-selector@^0.1.12: + version "0.1.12" + resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.1.12.tgz#fe726547be219a787a9dcc640575a04a032b1fd0" + integrity sha512-Kx7RTzxyQipHuiqyZGf+Nz4vY9R1XGxuQl/hLoJwq+J4avk/9wxxgZyHKtbyIPJmbD4A66DWGYfyykWNpcYutQ== + dependencies: + tslib "^1.9.0" + file-uri-to-path@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" @@ -6651,6 +6663,15 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +material-ui-dropzone@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/material-ui-dropzone/-/material-ui-dropzone-3.0.0.tgz#ef69b8f51a5021b0d09a1b72d1807f830068b415" + integrity sha512-0+QbdZsTLNhaEW/mZUWvZirnOATJfj3zovLuSNdG7gdlQPludj8i1nSEXTFUPn3DS0Rz5939pmeJfzTSatFnVg== + dependencies: + "@babel/runtime" "^7.4.4" + clsx "^1.0.2" + react-dropzone "^10.2.1" + md5.js@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" @@ -8678,6 +8699,15 @@ react-dom@^16.13.1: prop-types "^15.6.2" scheduler "^0.19.1" +react-dropzone@^10.2.1: + version "10.2.2" + resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-10.2.2.tgz#67b4db7459589a42c3b891a82eaf9ade7650b815" + integrity sha512-U5EKckXVt6IrEyhMMsgmHQiWTGLudhajPPG77KFSvgsMqNEHSyGpqWvOMc5+DhEah/vH4E1n+J5weBNLd5VtyA== + dependencies: + attr-accept "^2.0.0" + file-selector "^0.1.12" + prop-types "^15.7.2" + react-error-overlay@^6.0.7: version "6.0.7" resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.7.tgz#1dcfb459ab671d53f660a991513cb2f0a0553108"