Skip to content

Commit d317236

Browse files
authored
Merge pull request #18 from oslabs-beta/garrett/stylecontext
Garrett/stylecontext
2 parents a93e904 + 6b3c427 commit d317236

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+349
-2158
lines changed

app/src/Dashboard/NavbarDash.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import HomeIcon from '@mui/icons-material/Home';
1313
import Toolbar from '@mui/material/Toolbar';
1414
import Typography from '@mui/material/Typography';
1515
import { Link } from 'react-router-dom';
16-
import { styleContext } from '../containers/AppContainer';
16+
// import { styleContext } from '../containers/AppContainer';
1717
import Menu from '@mui/material/Menu';
1818
import MenuItem from '@mui/material/MenuItem';
1919
import SortIcon from '@mui/icons-material/Sort';
2020
import StarBorderIcon from '@mui/icons-material/StarBorder';
2121
import PersonIcon from '@mui/icons-material/Person';
2222
import greenLogo from '../public/icons/png/512x512.png';
23+
import {setStyle} from '../redux/reducers/slice/styleSlice'
24+
import { useSelector,useDispatch } from 'react-redux';
2325

2426
// NavBar text and button styling
2527
const useStyles = makeStyles((theme: Theme) => createStyles({
@@ -75,7 +77,9 @@ const StyledMenuItem = withStyles(theme => ({
7577
export default function NavBar(props) {
7678
// TO DO: import setStyle
7779
const classes = useStyles();
78-
const { style, setStyle } = useContext(styleContext);
80+
// const { style, setStyle } = useContext(styleContext);
81+
const style = useSelector(store => store.styleSlice);
82+
const dispatch = useDispatch();
7983
const toggling = () => setIsOpen(!isOpen);
8084
// toggle to open and close dropdown sorting menu
8185
const [isOpen, setIsOpen] = useState(false);
@@ -143,11 +147,17 @@ export default function NavBar(props) {
143147
style={{minWidth: '113.97px'}}
144148
endIcon={props.isThemeLight ? <Brightness3Icon/> : <Brightness5Icon/>}
145149
onClick={() => {
146-
!props.styles[0].backgroundColor
147-
? props.styles[1]({ backgroundColor: '#21262D' }) //dark mode color
148-
: props.styles[1]({ backgroundColor: null })
150+
!style.backgroundColor
151+
? dispatch(setStyle({ backgroundColor: '#21262D' })) //dark mode color
152+
: dispatch(setStyle( null ))
149153
props.isThemeLight ? props.setTheme(false) : props.setTheme(true);
150154
}}
155+
// onClick={() => {
156+
// !props.styles[0].backgroundColor
157+
// ? props.styles[1]({ backgroundColor: '#21262D' }) //dark mode color
158+
// : props.styles[1]({ backgroundColor: null })
159+
// props.isThemeLight ? props.setTheme(false) : props.setTheme(true);
160+
// }}
151161
>
152162
{props.isThemeLight ? 'Dark Mode' : 'Light Mode'}
153163
</Button>

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import React, { useState, useContext, createContext } from 'react';
1+
import React, { useState} from 'react';
22
import { ThemeProvider, Theme, StyledEngineProvider, useTheme } from '@mui/material/styles';
33
import makeStyles from '@mui/styles/makeStyles';
44
import { useQuery } from '@apollo/client';
55
import Tabs from '@mui/material/Tabs';
66
import Tab from '@mui/material/Tab';
7-
87
import Box from '@mui/material/Box';
98
import { GET_PROJECTS } from './gqlStrings';
109
import Project from './Project';
1110
import NavBarDash from './NavbarDash';
12-
11+
import { useSelector } from 'react-redux';
1312
import { theme1, theme2 } from '../public/styles/theme';
1413

1514

@@ -23,10 +22,10 @@ declare module '@mui/styles/defaultTheme' {
2322
// 1) Impliment Apollo Provider in the top component in ./src/index.js, this allows children components access to the queried data
2423
// 2) useQuery hook will update the data stored in Apollo Client's cache and automatically trigger child components rendering
2524

26-
export const styleContext = createContext({
27-
style: null,
28-
setStyle: null
29-
});
25+
// export const styleContext = createContext({
26+
// style: null,
27+
// setStyle: null
28+
// });
3029

3130
// setting light and dark themes (navbar and background); linked to theme.ts
3231
const lightTheme = theme1;
@@ -104,8 +103,9 @@ const ProjectContainer = (): JSX.Element => {
104103
const userSSID = window.localStorage.getItem('ssid') || 'unavailable';
105104
const username = window.localStorage.getItem('username') || 'unavailable';
106105
const [isThemeLight, setTheme] = useState(true);
107-
const initialStyle = useContext(styleContext);
108-
const [style, setStyle] = useState(initialStyle);
106+
// const initialStyle = useContext(styleContext);
107+
// const [style, setStyle] = useState(initialStyle);
108+
const style = useSelector(store => store.styleSlice)
109109
// hook for sorting menu
110110
const [selectedOption, setSelectedOption] = useState('RATING');
111111
const sortByRating = projects => {
@@ -163,7 +163,7 @@ const ProjectContainer = (): JSX.Element => {
163163
<div className={'dashboardContainer'}>
164164
<NavBarDash
165165
setTheme={setTheme}
166-
styles={[style, setStyle]}
166+
// styles={[style]}
167167
isThemeLight={isThemeLight}
168168
optionClicked={optionClicked}
169169
/>

app/src/components/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import '../public/styles/style.css';
33
import { DndProvider } from 'react-dnd';
44
import { HTML5Backend } from 'react-dnd-html5-backend';
55
import AppContainer from '../containers/AppContainer';
6-
import StateContext from '../context/context';
7-
import initialState from '../context/initialState';
8-
import reducer from '../reducers/componentReducer';
96
import localforage from 'localforage';
107
import { saveProject } from '../helperFunctions/projectGetSaveDel';
118
import Cookies from 'js-cookie';
@@ -110,9 +107,9 @@ export const App = (): JSX.Element => {
110107
>
111108
ReacType
112109
</header>
113-
<StateContext.Provider value = {[state, dispatch]}>
110+
114111
<AppContainer />
115-
</StateContext.Provider>
112+
116113
</DndProvider>
117114
</div>
118115
);

app/src/components/ContextAPIManager/AssignTab/AssignContainer.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useState, Fragment, useEffect } from 'react';
1+
import React, { useState, Fragment } from 'react';
22
import DataTable from '../CreateTab/components/DataTable';
33
import ContextDropDown from './components/ContextDropDown';
44
import ComponentDropDown from './components/ComponentDropDrown';
@@ -7,32 +7,23 @@ import Grid from '@mui/material/Grid';
77
import ComponentTable from './components/ComponentTable';
88
import { Button } from '@mui/material';
99
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
10-
// import * as actions from '../../../redux/actions/actions';
11-
import StateContext from '../../../context/context';
1210
import { addComponentToContext } from '../../../redux/reducers/slice/contextReducer';
1311
import { useSelector, useDispatch, useStore } from 'react-redux';
1412
import { deleteElement } from '../../../redux/reducers/slice/appStateSlice';
1513

1614
const AssignContainer = () => {
17-
const store = useStore();
1815
const dispatch = useDispatch();
19-
20-
// const [state, setState] = useState([]);
2116
const defaultTableData = [{ key: 'Key', value: 'Value' }];
2217
const [tableState, setTableState] = React.useState(defaultTableData);
2318
const [contextInput, setContextInput] = React.useState(null);
2419
const [componentInput, setComponentInput] = React.useState(null);
2520
const [componentTable, setComponentTable] = useState([]);
26-
// const [stateContext, dispatchContext] = useContext(StateContext);
2721
const { state, contextParam } = useSelector((store) => ({
2822
state: store.appState,
2923
contextParam: store.contextSlice
3024
}));
3125

32-
//fetching data from redux store
33-
// useEffect(() => {
34-
// setState(allContext);
35-
// }, [allContext]);
26+
3627

3728
const renderTable = (targetContext) => {
3829
if (targetContext === null || !targetContext.values) {
@@ -78,13 +69,6 @@ const AssignContainer = () => {
7869
);
7970
//trigger generateCode(), update code preview tab
8071
dispatch(deleteElement({ id: 'FAKE_ID', contextParam: contextParam }));
81-
82-
// dispatchContext({
83-
// type: 'DELETE ELEMENT',
84-
// payload: 'FAKE_ID'
85-
// });
86-
87-
// setState(allContext);
8872
renderComponentTable(componentInput);
8973
};
9074

app/src/components/ContextAPIManager/AssignTab/components/ComponentDropDrown.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ const ComponentDropDown = ({
1515
}) => {
1616
const { allContext } = contextStore;
1717
// const [componentList] = useContext(StateContext);
18-
const { state, isDarkMode } = useSelector((store) => ({
19-
state: store.appState,
20-
isDarkMode: store.darkMode.isDarkMode
21-
}));
18+
const state = useSelector(store => store.appState)
2219

2320
const onChange = (event, newValue) => {
2421
if (typeof newValue === 'string') {
@@ -43,7 +40,7 @@ const ComponentDropDown = ({
4340
const filtered = filter(options, params);
4441
const { inputValue } = params;
4542
// Suggest the creation of a new contextInput
46-
const isExisting = options.some((option) => inputValue === option.name);
43+
const isExisting = options.some(option => inputValue === option.name);
4744
if (inputValue !== '' && !isExisting) {
4845
filtered.push({
4946
inputValue,
@@ -56,7 +53,7 @@ const ComponentDropDown = ({
5653
return filtered;
5754
};
5855

59-
const getOptionLabel = (option) => {
56+
const getOptionLabel = option => {
6057
// Value selected with enter, right from the input
6158
if (typeof option === 'string') {
6259
return option;
@@ -70,7 +67,6 @@ const ComponentDropDown = ({
7067
};
7168

7269
const renderOption = (props, option) => <li {...props}>{option.name}</li>;
73-
const color = isDarkMode ? 'lightgray' : 'black';
7470

7571
return (
7672
<Fragment>
@@ -88,20 +84,13 @@ const ComponentDropDown = ({
8884
renderOption={renderOption}
8985
sx={{ width: 425 }}
9086
freeSolo
91-
renderInput={(params) => (
92-
<TextField
93-
{...params}
94-
label="Select Component"
95-
helperText="Select a component for your selected context to consume"
96-
InputLabelProps={{ style: { color } }}
97-
FormHelperTextProps={{ style: { color } }}
98-
InputProps={{ style: { color } }}
99-
/>
87+
renderInput={params => (
88+
<TextField {...params} label="Select Component" helperText='Select a component for your selected context to consume' />
10089
)}
10190
/>
10291
</Box>
10392
</Fragment>
10493
);
10594
};
10695

107-
export default ComponentDropDown;
96+
export default ComponentDropDown;

app/src/components/ContextAPIManager/AssignTab/components/ComponentTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ export default function DataTable({ target }) {
4949
</Table>
5050
</TableContainer>
5151
);
52-
}
52+
}

app/src/components/ContextAPIManager/AssignTab/components/ContextDropDown.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
44
import Button from '@mui/material/Button';
55
import Box from '@mui/material/Box';
66
import { Typography } from '@mui/material';
7-
import { useSelector } from 'react-redux';
87

98
const filter = createFilterOptions();
109

@@ -15,7 +14,6 @@ const ContextDropDown = ({
1514
setContextInput
1615
}) => {
1716
const { allContext } = contextStore;
18-
const isDarkMode = useSelector((store) => store.darkMode.isDarkMode);
1917

2018
const onChange = (event, newValue) => {
2119
if (typeof newValue === 'string') {
@@ -40,7 +38,7 @@ const ContextDropDown = ({
4038
const filtered = filter(options, params);
4139
const { inputValue } = params;
4240
// Suggest the creation of a new contextInput
43-
const isExisting = options.some((option) => inputValue === option.name);
41+
const isExisting = options.some(option => inputValue === option.name);
4442
if (inputValue !== '' && !isExisting) {
4543
filtered.push({
4644
inputValue,
@@ -53,7 +51,7 @@ const ContextDropDown = ({
5351
return filtered;
5452
};
5553

56-
const getOptionLabel = (option) => {
54+
const getOptionLabel = option => {
5755
// Value selected with enter, right from the input
5856
if (typeof option === 'string') {
5957
return option;
@@ -67,7 +65,6 @@ const ContextDropDown = ({
6765
};
6866

6967
const renderOption = (props, option) => <li {...props}>{option.name}</li>;
70-
const color = isDarkMode ? 'lightgray' : 'black';
7168

7269
return (
7370
<Fragment>
@@ -85,20 +82,13 @@ const ContextDropDown = ({
8582
renderOption={renderOption}
8683
sx={{ width: 425 }}
8784
freeSolo
88-
renderInput={(params) => (
89-
<TextField
90-
{...params}
91-
label="Select Context"
92-
helperText="Select a context you would like to assign"
93-
InputLabelProps={{ style: { color } }}
94-
FormHelperTextProps={{ style: { color } }}
95-
InputProps={{ style: { color } }}
96-
/>
85+
renderInput={params => (
86+
<TextField {...params} label="Select Context" helperText='Select a context you would like to assign'/>
9787
)}
9888
/>
9989
</Box>
10090
</Fragment>
10191
);
10292
};
10393

104-
export default ContextDropDown;
94+
export default ContextDropDown;

app/src/components/ContextAPIManager/AssignTab/components/ContextTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ export default function ContextTable() {
6969
</Table>
7070
</TableContainer>
7171
);
72-
}
72+
}

app/src/components/ContextAPIManager/ContextManager.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
import React, { useContext } from 'react';
24
import { makeStyles } from '@mui/styles';
35
import Box from '@mui/material/Box';
@@ -9,7 +11,8 @@ import TabPanel from '@mui/lab/TabPanel';
911
import CreateContainer from './CreateTab/CreateContainer';
1012
import AssignContainer from './AssignTab/AssignContainer';
1113
import DisplayContainer from './DisplayTab/DisplayContainer';
12-
import { useSelector } from 'react-redux';
14+
import { useSelector } from 'react-redux'
15+
1316

1417
const useStyles = makeStyles({
1518
contextContainer: {
@@ -19,27 +22,29 @@ const useStyles = makeStyles({
1922
});
2023

2124
const ContextManager = (props): JSX.Element => {
22-
const isDarkMode = useSelector((state) => state.darkMode.isDarkMode);
25+
const { isDarkMode, style } = useSelector((store) => ({
26+
isDarkMode: store.darkMode.isDarkMode,
27+
style: store.styleSlice
28+
}));
2329
const classes = useStyles();
2430
const [value, setValue] = React.useState<string>('1');
25-
31+
2632
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
2733
setValue(newValue);
2834
};
2935

30-
const backgroundColor = isDarkMode ? '#21262b' : 'white';
31-
const color = isDarkMode ? 'lightgray' : 'black';
36+
const background_Color = isDarkMode ? '#21262b' : 'white'
3237

3338
return (
3439
<React.Fragment>
35-
<div className={classes.contextContainer} style={{ backgroundColor }}>
40+
<div className={classes.contextContainer} style={style.style}>
3641
<Box sx={{ width: '100%', typography: 'body1' }}>
3742
<TabContext value={value}>
3843
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
3944
<TabList onChange={handleChange} centered={true}>
40-
<Tab label="Create/Edit" value="1" style={{ color }} />
41-
<Tab label="Assign" value="2" style={{ color }} />
42-
<Tab label="Display" value="3" style={{ color }} />
45+
<Tab label="Create/Edit" value="1" />
46+
<Tab label="Assign" value="2" />
47+
<Tab label="Display" value="3" />
4348
</TabList>
4449
</Box>
4550
<TabPanel value="1">
@@ -58,4 +63,4 @@ const ContextManager = (props): JSX.Element => {
5863
);
5964
};
6065

61-
export default ContextManager;
66+
export default ContextManager;

0 commit comments

Comments
 (0)