Skip to content

Commit 7dc986b

Browse files
authored
Merge pull request #8 from eddypjr/comments
KeyBindings, Refactored Sort Documents, added instructions to Tutorial
2 parents d8bda37 + 48cee38 commit 7dc986b

28 files changed

+421
-114
lines changed

app/src/Dashboard/FormsContainer.jsx renamed to app/src/Dashboard/FormsContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const FormsContainer = () => {
1919
if (error) return <p>Error :{error}</p>;
2020
// based on resolver(readAllTests) for this query, the data is stored in the data object with the key 'readAllTests'
2121
const myTests = data.readAllTests;
22+
console.log('myTests', myTests);
2223
// generate an array of Form components based on data
2324
const forms = myTests.map((test, index) => <Form key={index} id={test.id} description={test.description} likes={test.likes}/>);
2425

app/src/Dashboard/NavbarDash.tsx

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useContext } from 'react';
22
import {
3+
withStyles, //added
34
createStyles,
45
makeStyles,
56
Theme,
@@ -11,7 +12,12 @@ import Toolbar from '@material-ui/core/Toolbar';
1112
import Typography from '@material-ui/core/Typography';
1213
import { Link } from 'react-router-dom';
1314
import { styleContext } from '../containers/AppContainer';
14-
import logo from '../../../resources/icon.png';
15+
16+
import Menu from '@material-ui/core/Menu';
17+
import MenuItem from '@material-ui/core/MenuItem';
18+
19+
// import logo from '../../../resources/icon.png';
20+
import greenLogo from '../public/icons/png/512x512.png';
1521

1622

1723
// NavBar text and button styling
@@ -35,7 +41,38 @@ const useStyles = makeStyles((theme: Theme) => createStyles({
3541
}));
3642

3743
// sorting options
38-
const sortMethods = ['rating', 'date', 'user'];
44+
const sortMethods = ['Rating', 'Date', 'User'];
45+
46+
// Drop down menu button for SORT PROJECTS
47+
const StyledMenu = withStyles({
48+
paper: {
49+
border: '1px solid #d3d4d5'
50+
}
51+
})(props => (
52+
<Menu
53+
elevation={0}
54+
getContentAnchorEl={null}
55+
anchorOrigin={{
56+
vertical: 'bottom',
57+
horizontal: 'center'
58+
}}
59+
transformOrigin={{
60+
vertical: 'top',
61+
horizontal: 'center'
62+
}}
63+
{...props}
64+
/>
65+
));
66+
67+
const StyledMenuItem = withStyles(theme => ({
68+
root: {
69+
'&:focus': {
70+
'& .MuiListItemIcon-root, & .MuiListItemText-primary': {
71+
color: theme.palette.common.white
72+
}
73+
}
74+
}
75+
}))(MenuItem);
3976

4077
// TO DO: set types of props validation
4178

@@ -44,55 +81,83 @@ export default function NavBar(props) {
4481
const classes = useStyles();
4582
const { style, setStyle } = useContext(styleContext);
4683

47-
84+
const toggling = () => setIsOpen(!isOpen);
85+
4886
// toggle to open and close dropdown sorting menu
4987
const [isOpen, setIsOpen] = useState(false);
5088

51-
const toggling = () => setIsOpen(!isOpen);
89+
// State for sort projects button
90+
const [anchorEl, setAnchorEl] = React.useState(null);
91+
92+
93+
const handleClick = event => {
94+
setAnchorEl(event.currentTarget);
95+
};
96+
97+
const handleClose = () => {
98+
setAnchorEl(null);
99+
};
52100

53101
return (
54102
<div className={classes.root} style={style}>
55103
<AppBar position="static">
56104
<Toolbar>
57-
<Avatar src={logo}></Avatar>
105+
<Avatar src={greenLogo}></Avatar>
58106
<Typography variant="h6" style={{ marginLeft: '1rem' }} className={classes.title}>
59107
ReacType
60108
</Typography>
61109

62110
{/* ==========================================Sort by Button================================================== */}
63111

64112
<div style ={ { textDecoration: 'none' } }>
65-
<Button onClick={toggling}
66-
variant="contained"
67-
color="primary"
68-
style={{ minWidth: '137.69px' }}
69-
className="navbarButton"
70-
id="navbarButtonDash"
71-
>
72-
Sort documents
73-
</Button>
74-
75-
{
76-
isOpen && (
77-
<div className="sortDoc">
78-
{sortMethods.map((option, index) => (
79-
<Button onClick={() => {
113+
<Button
114+
variant="contained"
115+
color="primary"
116+
onClick={handleClick}
117+
className="navbarButton"
118+
id="navbarButton"
119+
>
120+
SORT PROJECT
121+
</Button>
122+
<StyledMenu // Dropdown menu connected to Manage Project Button
123+
id="customized-menus"
124+
anchorEl={anchorEl}
125+
keepMounted
126+
open={Boolean(anchorEl)}
127+
onClose={handleClose}
128+
>
129+
{sortMethods.map((option, index) => (
130+
<StyledMenuItem onClick={() => {
80131
props.optionClicked(option);
81132
toggling();
133+
handleClose();
82134
}}
83135
variant="contained"
84136
color="primary"
85137
style={{ minWidth: '137.69px' }}
86138
className="navbarButton"
87139
key={index}
88-
> {option}
89-
</Button>
90-
))};
91-
</div>
92-
)
93-
}
94-
</div>
95-
140+
>
141+
{option}
142+
</StyledMenuItem>
143+
))}
144+
</StyledMenu>
145+
</div>
146+
<Button
147+
className="navbarButton"
148+
id="navbarDashButton"
149+
color="primary"
150+
variant="contained"
151+
style={{minWidth: '113.97px'}}
152+
onClick={() => {
153+
!props.styles[0].backgroundColor
154+
? props.styles[1]({ backgroundColor: '#21262D' }) //dark mode color
155+
: props.styles[1]({ backgroundColor: null })
156+
props.isThemeLight ? props.setTheme(false) : props.setTheme(true);
157+
}}
158+
>
159+
{props.isThemeLight ? 'Dark Mode' : 'Light Mode'}
160+
</Button>
96161
{/* ====================================Home Button============================================== */}
97162

98163
<div style ={ { textDecoration: 'none' } }>

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useContext, useEffect, createContext } from 'react';
2+
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
23
import { useQuery } from '@apollo/client';
34
import { GET_PROJECTS } from './gqlStrings';
4-
import Project from './Project.tsx';
5-
import NavBar from './NavbarDash';
6-
5+
import Project from './Project';
6+
import NavBarDash from './NavbarDash';
7+
import AppContainer from '../containers/AppContainer';
8+
import { theme1, theme2 } from '../public/styles/theme';
79
// Implement Apollo Client useQuery hook to retrieve data from the server through graphQL. This includes 2 steps:
810
// 1) Impliment Apollo Provider in the top component in ./src/index.js, this allows children components access to the queried data
911
// 2) useQuery hook will update the data stored in Apollo Client's cache and automatically trigger child components rendering
1012

13+
export const styleContext = createContext({
14+
style: null,
15+
setStyle: null
16+
});
17+
18+
// setting light and dark themes (navbar and background); linked to theme.ts
19+
const lightTheme = theme1;
20+
const darkTheme = theme2; // dark mode color in theme.ts not reached
21+
1122
const ProjectContainer = () => {
1223
const myVar = {};
1324
// Need this for the individual user dasboard, for now, dashboard shows all projects from all users
@@ -17,6 +28,11 @@ const ProjectContainer = () => {
1728
// myVar = { userId: userSSID };
1829
// }
1930

31+
const [isThemeLight, setTheme] = useState(true);
32+
33+
const initialStyle = useContext(styleContext);
34+
const [style, setStyle] = useState(initialStyle);
35+
2036
// --------------------------Sorting Buttons------------------------------------//
2137

2238
// hook for sorting menu
@@ -73,15 +89,14 @@ const ProjectContainer = () => {
7389
}
7490
});
7591

76-
7792
// function for selecting drop down sorting menu
7893
const optionClicked = (value) => {
7994
setSelectedOption(value);
8095
};
8196
// checking which sorting method was selected from drop down menu and invoking correct sorting function
82-
if (selectedOption === 'date') sortedProjects = sortByDate(sortedProjects);
83-
else if (selectedOption === 'user') sortedProjects = sortByUser(sortedProjects);
84-
else if (selectedOption === 'rating') sortedProjects = sortByRating(sortedProjects);
97+
if (selectedOption === 'Date') sortedProjects = sortByDate(sortedProjects);
98+
else if (selectedOption === 'User') sortedProjects = sortByUser(sortedProjects);
99+
else if (selectedOption === 'Rating') sortedProjects = sortByRating(sortedProjects);
85100

86101
// create an array of components Project that will be conditionally rendered
87102
const sortedDisplay = [];
@@ -99,8 +114,9 @@ const ProjectContainer = () => {
99114
});
100115

101116
return (
102-
<div>
103-
<NavBar optionClicked = {optionClicked}/>
117+
<MuiThemeProvider theme={isThemeLight ? lightTheme : darkTheme}>
118+
<div className = "dashboardContainer">
119+
<NavBarDash setTheme={setTheme} styles={[style, setStyle]} isThemeLight={isThemeLight} optionClicked={optionClicked}/>
104120
<h1> Public Dashboard </h1>
105121
<div className = "projectContainer">
106122
{sortedDisplay}
@@ -111,6 +127,8 @@ const ProjectContainer = () => {
111127
{userDisplay}
112128
</div>
113129
</div>
130+
</MuiThemeProvider>
114131
);
115132
};
133+
116134
export default ProjectContainer;

app/src/Dashboard/styles.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ $button-blue: #24BCFF; */
2323
width: 250px;
2424
}
2525

26+
/* .dashboardContainer {
27+
display: grid;
28+
grid-template: auto / repeat(2, 1fr);
29+
} */
30+
2631
.formContainer , .projectContainer{
2732
display: flex;
2833
flex-flow: row wrap;
2934
}
3035

36+
37+
/* .formContainer {
38+
display: flex;
39+
flex-direction: row;
40+
width: 100%;
41+
height: 100%;
42+
}
43+
44+
.projectContainer {
45+
display: flex;
46+
flex-direction: row;
47+
align-items: center;
48+
justify-content: center;
49+
width: 100%;
50+
} */

app/src/components/left/HTMLPanel.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState, useCallback, useContext, useEffect } from 'react';
22
import Grid from '@material-ui/core/Grid';
33
import StateContext from '../../context/context';
44
import HTMLItem from './HTMLItem';
@@ -140,6 +140,22 @@ const HTMLPanel = (props): JSX.Element => {
140140
payload: id
141141
});
142142
};
143+
144+
const handleCreateElement = useCallback((e) => {
145+
if(e.key === 'Enter') {
146+
e.preventDefault();
147+
document.getElementById('submitButton').click();
148+
}
149+
}, []);
150+
151+
useEffect(() => {
152+
document.addEventListener('keydown', handleCreateElement);
153+
return () => {
154+
document.removeEventListener('keydown', handleCreateElement)
155+
}
156+
}, []);
157+
158+
143159
// filter out separator so that it will not appear on the html panel
144160
const htmlTypesToRender = state.HTMLTypes.filter(type => type.name !== 'separator')
145161
return (

app/src/components/login/SignIn.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useCallback, useEffect } from 'react';
22
import { LoginInt } from '../../interfaces/Interfaces';
33
import {
44
Link as RouteLink,
@@ -90,6 +90,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
9090

9191
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
9292
let inputVal = e.target.value;
93+
9394
switch (e.target.name) {
9495
case 'username':
9596
setUsername(inputVal);
@@ -132,6 +133,20 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
132133
});
133134
};
134135

136+
const keyBindSignIn = useCallback((e) => {
137+
if(e.key === 'Enter') {
138+
e.preventDefault();
139+
document.getElementById('SignIn').click();
140+
}
141+
}, []);
142+
143+
useEffect(() => {
144+
document.addEventListener('keydown', keyBindSignIn);
145+
return () => {
146+
document.removeEventListener('keydown', keyBindSignIn)
147+
}
148+
}, []);
149+
135150
// for users not wanting to make an account and use as guest
136151
const handleLoginGuest = (
137152
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
@@ -210,6 +225,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
210225

211226
<Button
212227
fullWidth
228+
id="SignIn"
213229
variant="contained"
214230
color="default"
215231
className={classes.submit}

0 commit comments

Comments
 (0)