Skip to content

Commit a93e904

Browse files
authored
Merge pull request #17 from oslabs-beta/mike/darkmodefixes
continue state migration to redux toolkit and add initial websocket functionality.
2 parents 0ef2842 + 7a0ff7f commit a93e904

File tree

73 files changed

+3626
-1564
lines changed

Some content is hidden

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

73 files changed

+3626
-1564
lines changed

app/src/Dashboard/NavbarDash.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const StyledMenu = withStyles({
5050
})(props => (
5151
<Menu
5252
elevation={0}
53-
getContentAnchorEl={null}
53+
// getContentAnchorEl={null}
5454
anchorOrigin={{
5555
vertical: 'bottom',
5656
horizontal: 'center'

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ const TabPanelItem = (props: TabPanelProps): JSX.Element => {
8484
const useStyles = makeStyles(theme => ({
8585
root: {
8686
flexGrow: 1,
87-
backgroundColor: theme.palette.background.paper,
87+
// backgroundColor: theme.palette.background.paper,
8888
display: 'flex'
8989
},
9090
tabs: {
91-
borderRight: `1px solid ${theme.palette.divider}`
91+
// borderRight: `1px solid ${theme.palette.divider}`
9292
}
9393
}));
9494
// End of prefab code to generate a tab panel

app/src/components/App.tsx

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,39 @@ import reducer from '../reducers/componentReducer';
99
import localforage from 'localforage';
1010
import { saveProject } from '../helperFunctions/projectGetSaveDel';
1111
import Cookies from 'js-cookie';
12+
//redux toolkit addition
13+
import { useSelector, useDispatch } from 'react-redux';
14+
import { setInitialState, toggleLoggedIn, configToggle } from '../redux/reducers/slice/appStateSlice';
15+
1216
// Intermediary component to wrap main App component with higher order provider components
1317
export const App = (): JSX.Element => {
14-
const [state, dispatch] = useReducer(reducer, initialState);
18+
// const [state, dispatch] = useReducer(reducer, initialState);
19+
const state = useSelector(store => store.appState);
20+
const dispatch = useDispatch();
1521
// checks if user is signed in as guest or actual user and changes loggedIn boolean accordingly
16-
if (window.localStorage.getItem('ssid') !== 'guest') {
17-
state.isLoggedIn = true;
18-
} else {
19-
state.isLoggedIn = false;
20-
}
22+
useEffect(()=>{
23+
if (window.localStorage.getItem('ssid') !== 'guest') {
24+
// state.isLoggedIn = true;
25+
dispatch(toggleLoggedIn())
26+
}
27+
},[])
28+
29+
// else {
30+
// state.isLoggedIn = false;
31+
// }
2132
// following useEffect runs on first mount
2233
useEffect(() => {
2334
// if user is a guest, see if a project exists in localforage and retrieve it
24-
if (state.isLoggedIn === false) {
35+
// if (state.isLoggedIn === false) {
36+
if (!state.isLoggedIn) {
2537
localforage.getItem('guestProject').then(project => {
2638
// if project exists, use dispatch to set initial state to that project
2739
if (project) {
28-
dispatch({
29-
type: 'SET INITIAL STATE',
30-
payload: project
31-
});
40+
// dispatch({
41+
// type: 'SET INITIAL STATE',
42+
// payload: project
43+
// });
44+
dispatch(setInitialState(project))
3245
}
3346
});
3447
} else {
@@ -42,10 +55,11 @@ export const App = (): JSX.Element => {
4255
//also load user's last project, which was saved in localforage on logout
4356
localforage.getItem(userId).then(project => {
4457
if (project) {
45-
dispatch({
46-
type: 'SET INITIAL STATE',
47-
payload: project
48-
});
58+
// dispatch({
59+
// type: 'SET INITIAL STATE',
60+
// payload: project
61+
// });
62+
dispatch(setInitialState(project))
4963
} else {
5064
console.log(
5165
'No user project found in localforage, setting initial state blank'
@@ -56,35 +70,38 @@ export const App = (): JSX.Element => {
5670
}, []);
5771
useEffect(() => {
5872
// provide config properties to legacy projects so new edits can be auto saved
59-
if (state.config === undefined) {
60-
state.config = { saveFlag: true, saveTimer: false };
61-
}
73+
// if (state.config === undefined) {
74+
// state.config = { saveFlag: true, saveTimer: false };
75+
// }
6276
// New project save configuration to optimize server load and minimize Ajax requests
6377
if (state.config.saveFlag) {
64-
state.config.saveFlag = false;
65-
state.config.saveTimer = true;
78+
// state.config.saveFlag = false;
79+
// state.config.saveTimer = true;
80+
dispatch(configToggle())
81+
6682
let userId;
6783
if (Cookies.get('ssid')) {
6884
userId = Cookies.get('ssid');
6985
} else {
7086
userId = window.localStorage.getItem('ssid');
7187
}
72-
if (state.isLoggedIn === false) {
88+
// if (state.isLoggedIn === false) {
89+
if (!state.isLoggedIn) {
7390
localforage.setItem('guestProject', state);
7491
} else if (state.name !== '') {
7592
saveProject(state.name, state);
7693
localforage.setItem(userId, state);
7794
}
7895
}
79-
if (state.config.saveTimer) {
80-
state.config.saveTimer = false;
96+
if (!state.config.saveTimer) {
97+
// state.config.saveTimer = false;
8198
setTimeout(() => {
82-
state.config.saveFlag = true;
99+
// state.config.saveFlag = true;
83100
}, 15000);
84101
}
85102
}, [state]);
86103
// uncomment below to log state
87-
// console.log('STATE!!!!: ', state);
104+
88105
return (
89106
<div className="app">
90107
<DndProvider backend={HTML5Backend}>

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,32 @@ import { Button } from '@mui/material';
99
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
1010
// import * as actions from '../../../redux/actions/actions';
1111
import StateContext from '../../../context/context';
12-
import {addComponentToContext} from '../../../redux/reducers/slice/contextReducer'
13-
import {useSelector, useDispatch , useStore,} from 'react-redux';
12+
import { addComponentToContext } from '../../../redux/reducers/slice/contextReducer';
13+
import { useSelector, useDispatch, useStore } from 'react-redux';
14+
import { deleteElement } from '../../../redux/reducers/slice/appStateSlice';
1415

1516
const AssignContainer = () => {
1617
const store = useStore();
1718
const dispatch = useDispatch();
1819

19-
const [state, setState] = useState([]);
20+
// const [state, setState] = useState([]);
2021
const defaultTableData = [{ key: 'Key', value: 'Value' }];
2122
const [tableState, setTableState] = React.useState(defaultTableData);
2223
const [contextInput, setContextInput] = React.useState(null);
2324
const [componentInput, setComponentInput] = React.useState(null);
2425
const [componentTable, setComponentTable] = useState([]);
25-
const [stateContext, dispatchContext] = useContext(StateContext);
26-
const allContext = useSelector(state => state.contextSlice);
26+
// const [stateContext, dispatchContext] = useContext(StateContext);
27+
const { state, contextParam } = useSelector((store) => ({
28+
state: store.appState,
29+
contextParam: store.contextSlice
30+
}));
2731

2832
//fetching data from redux store
29-
useEffect(() => {
30-
setState(allContext);
31-
}, [allContext]);
33+
// useEffect(() => {
34+
// setState(allContext);
35+
// }, [allContext]);
3236

33-
const renderTable = targetContext => {
37+
const renderTable = (targetContext) => {
3438
if (targetContext === null || !targetContext.values) {
3539
setTableState(defaultTableData);
3640
} else {
@@ -39,7 +43,7 @@ const AssignContainer = () => {
3943
};
4044

4145
//construct data for table displaying component table
42-
const renderComponentTable = targetComponent => {
46+
const renderComponentTable = (targetComponent) => {
4347
//target Component is main
4448

4549
const listOfContexts = [];
@@ -48,7 +52,7 @@ const AssignContainer = () => {
4852
targetComponent !== null &&
4953
targetComponent.name
5054
) {
51-
state.allContext.forEach(context => {
55+
contextParam.allContext.forEach((context) => {
5256
if (context.components.includes(targetComponent.name)) {
5357
listOfContexts.push(context.name);
5458
}
@@ -67,16 +71,18 @@ const AssignContainer = () => {
6771
)
6872
return;
6973
dispatch(
70-
addComponentToContext({
74+
addComponentToContext({
7175
context: contextInput,
7276
component: componentInput
7377
})
7478
);
7579
//trigger generateCode(), update code preview tab
76-
dispatchContext({
77-
type: 'DELETE ELEMENT',
78-
payload: 'FAKE_ID'
79-
});
80+
dispatch(deleteElement({ id: 'FAKE_ID', contextParam: contextParam }));
81+
82+
// dispatchContext({
83+
// type: 'DELETE ELEMENT',
84+
// payload: 'FAKE_ID'
85+
// });
8086

8187
// setState(allContext);
8288
renderComponentTable(componentInput);
@@ -96,7 +102,7 @@ const AssignContainer = () => {
96102
>
97103
<Grid item>
98104
<ContextDropDown
99-
contextStore={state}
105+
contextStore={contextParam}
100106
renderTable={renderTable}
101107
contextInput={contextInput}
102108
setContextInput={setContextInput}
@@ -125,7 +131,7 @@ const AssignContainer = () => {
125131
>
126132
<Grid item>
127133
<ComponentDropDown
128-
contextStore={state}
134+
contextStore={contextParam}
129135
renderComponentTable={renderComponentTable}
130136
componentInput={componentInput}
131137
setComponentInput={setComponentInput}

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TextField from '@mui/material/TextField';
33
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
44
import Box from '@mui/material/Box';
55
import StateContext from '../../../../context/context';
6+
import { useSelector } from 'react-redux';
67

78
const filter = createFilterOptions();
89

@@ -13,7 +14,11 @@ const ComponentDropDown = ({
1314
setComponentInput
1415
}) => {
1516
const { allContext } = contextStore;
16-
const [componentList] = useContext(StateContext);
17+
// const [componentList] = useContext(StateContext);
18+
const { state, isDarkMode } = useSelector((store) => ({
19+
state: store.appState,
20+
isDarkMode: store.darkMode.isDarkMode
21+
}));
1722

1823
const onChange = (event, newValue) => {
1924
if (typeof newValue === 'string') {
@@ -38,7 +43,7 @@ const ComponentDropDown = ({
3843
const filtered = filter(options, params);
3944
const { inputValue } = params;
4045
// Suggest the creation of a new contextInput
41-
const isExisting = options.some(option => inputValue === option.name);
46+
const isExisting = options.some((option) => inputValue === option.name);
4247
if (inputValue !== '' && !isExisting) {
4348
filtered.push({
4449
inputValue,
@@ -51,7 +56,7 @@ const ComponentDropDown = ({
5156
return filtered;
5257
};
5358

54-
const getOptionLabel = option => {
59+
const getOptionLabel = (option) => {
5560
// Value selected with enter, right from the input
5661
if (typeof option === 'string') {
5762
return option;
@@ -65,6 +70,7 @@ const ComponentDropDown = ({
6570
};
6671

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

6975
return (
7076
<Fragment>
@@ -77,13 +83,20 @@ const ComponentDropDown = ({
7783
selectOnFocus
7884
clearOnBlur
7985
handleHomeEndKeys
80-
options={componentList.components || []}
86+
options={state.components || []}
8187
getOptionLabel={getOptionLabel}
8288
renderOption={renderOption}
8389
sx={{ width: 425 }}
8490
freeSolo
85-
renderInput={params => (
86-
<TextField {...params} label="Select Component" helperText='Select a component for your selected context to consume' />
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+
/>
87100
)}
88101
/>
89102
</Box>

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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';
78

89
const filter = createFilterOptions();
910

@@ -14,6 +15,7 @@ const ContextDropDown = ({
1415
setContextInput
1516
}) => {
1617
const { allContext } = contextStore;
18+
const isDarkMode = useSelector((store) => store.darkMode.isDarkMode);
1719

1820
const onChange = (event, newValue) => {
1921
if (typeof newValue === 'string') {
@@ -38,7 +40,7 @@ const ContextDropDown = ({
3840
const filtered = filter(options, params);
3941
const { inputValue } = params;
4042
// Suggest the creation of a new contextInput
41-
const isExisting = options.some(option => inputValue === option.name);
43+
const isExisting = options.some((option) => inputValue === option.name);
4244
if (inputValue !== '' && !isExisting) {
4345
filtered.push({
4446
inputValue,
@@ -51,7 +53,7 @@ const ContextDropDown = ({
5153
return filtered;
5254
};
5355

54-
const getOptionLabel = option => {
56+
const getOptionLabel = (option) => {
5557
// Value selected with enter, right from the input
5658
if (typeof option === 'string') {
5759
return option;
@@ -65,6 +67,7 @@ const ContextDropDown = ({
6567
};
6668

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

6972
return (
7073
<Fragment>
@@ -82,8 +85,15 @@ const ContextDropDown = ({
8285
renderOption={renderOption}
8386
sx={{ width: 425 }}
8487
freeSolo
85-
renderInput={params => (
86-
<TextField {...params} label="Select Context" helperText='Select a context you would like to assign'/>
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+
/>
8797
)}
8898
/>
8999
</Box>

0 commit comments

Comments
 (0)