Skip to content

Commit 70eee1f

Browse files
author
Rachel Kucharski
committed
Co-authored-by: Sophia Bui <[email protected]>
2 parents e340658 + 22e6391 commit 70eee1f

File tree

11 files changed

+78
-31
lines changed

11 files changed

+78
-31
lines changed

app/src/components/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import Cookies from 'js-cookie';
1010
import { useSelector, useDispatch } from 'react-redux';
1111
import { setInitialState, toggleLoggedIn, configToggle } from '../redux/reducers/slice/appStateSlice';
1212

13+
import { RootState } from '../redux/store';
14+
1315
// Intermediary component to wrap main App component with higher order provider components
1416
export const App = (): JSX.Element => {
15-
const state = useSelector(store => store.appState);
17+
const state = useSelector((store: RootState) => store.appState);
1618
const dispatch = useDispatch();
1719
// checks if user is signed in as guest or actual user and changes loggedIn boolean accordingly
1820
useEffect(()=>{

app/src/components/top/NavBarButtons.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import store from '../../redux/store.js';
2+
import store from '../../redux/store.ts';
33
import { Link } from 'react-router-dom';
44
import { useSelector, useDispatch } from 'react-redux';
55
import List from '@mui/material/List';
@@ -8,7 +8,7 @@ import ListItemText from '@mui/material/ListItemText';
88
import { resetAllState } from '../../redux/reducers/slice/appStateSlice.ts';
99
import createModal from '../right/createModal.tsx';
1010
import ExportButton from '../right/ExportButton.tsx';
11-
import { setStyle } from '../../redux/reducers/slice/styleSlice';
11+
import { setStyle } from '../../redux/reducers/slice/styleSlice.ts';
1212
import LoginButton from '../right/LoginButton.tsx';
1313
import withStyles from '@mui/styles/withStyles';
1414
import MenuItem from '@mui/material/MenuItem';
@@ -18,15 +18,15 @@ import SaveProjectButton from '../right/SaveProjectButton.tsx';
1818
import ProjectsFolder from '../right/OpenProjects.tsx';
1919
import DeleteProjects from '../right/DeleteProjects.tsx';
2020
import Menu from '@mui/material/Menu';
21-
import { changeRoom } from '../../redux/reducers/slice/roomCodeSlice';
21+
import { changeRoom } from '../../redux/reducers/slice/roomCodeSlice.ts';
2222
// for websockets
2323
import debounce from 'lodash/debounce';
2424
// websocket front end starts here
2525
import { io } from 'socket.io-client';
26-
import { toggleDarkMode } from '../../redux/reducers/slice/darkModeSlice';
26+
import { toggleDarkMode } from '../../redux/reducers/slice/darkModeSlice.ts';
2727
import { allCooperativeState } from '../../redux/reducers/slice/appStateSlice.ts';
28-
import { codePreviewCooperative } from '../../redux/reducers/slice/codePreviewSlice';
29-
import { cooperativeStyle } from '../../redux/reducers/slice/styleSlice';
28+
import { codePreviewCooperative } from '../../redux/reducers/slice/codePreviewSlice.ts';
29+
import { cooperativeStyle } from '../../redux/reducers/slice/styleSlice.ts';
3030
import config from '../../../../config.js';
3131
const { API_BASE_URL } = config;
3232

app/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'react-router-dom';
88
import 'babel-polyfill';
99
import React from 'react';
10-
import store from './redux/store';
10+
import store from './redux/store.ts';
1111
import { Provider } from 'react-redux';
1212
import ReactDOM from 'react-dom';
1313
import Cookies from 'js-cookie';

app/src/redux/reducers/rootReducer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { combineReducers } from 'redux';
22

33
// Need to import each slice which will be combined in the rootReducer
4-
import darkModeReducer from './slice/darkModeSlice';
5-
import codePreviewReducer from './slice/codePreviewSlice';
6-
import contextReducer from './slice/contextReducer';
4+
import darkModeReducer from './slice/darkModeSlice.ts';
5+
import codePreviewReducer from './slice/codePreviewSlice.ts';
6+
import contextReducer from './slice/contextReducer.ts';
77
import appStateReducer from './slice/appStateSlice.ts';
8-
import styleReducer from './slice/styleSlice';
9-
import roomCodeReducer from './slice/roomCodeSlice';
8+
import styleReducer from './slice/styleSlice.ts';
9+
import roomCodeReducer from './slice/roomCodeSlice.ts';
1010

1111
const rootReducer = combineReducers({
1212
// Add desired slices here

app/src/redux/reducers/slice/contextReducer.js renamed to app/src/redux/reducers/slice/contextReducer.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
1-
import { createSlice } from '@reduxjs/toolkit';
1+
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2+
// import type { RootState } from '../redux/store';
23

3-
const initialState = {
4-
allContext: []
4+
// -------------------------//
5+
// interfaces for all methods // calling actions payloads type referencss assigning type // typesccript
6+
//Defined Slice State and Action Types on this page
7+
interface Context {
8+
name: string;
9+
values: Array<{ key: string; value: string }>;
10+
components: Array<string>;
11+
}
12+
13+
interface AddContextPayload {
14+
name: string;
15+
}
16+
17+
interface AddContextValuesPayload {
18+
name: string;
19+
inputKey: string;
20+
inputValue: string;
21+
}
22+
23+
interface DeleteContextPayload {
24+
name: string;
25+
}
26+
27+
interface AddComponentToContextPayload {
28+
context: { name: string };
29+
component: { name: string };
30+
}
31+
// did not do getall context and allcontext cooperative
32+
// most imprtant because it allows reference from the intial state to all the interfaces
33+
interface ContextState {
34+
allContext: Context[];
35+
}
36+
// -------------------------//
37+
38+
const initialState: ContextState = {
39+
allContext: [],
540
};
641

742
const contextReducerSlice = createSlice({
843
name: 'context',
944
initialState,
1045
reducers: {
11-
addContext: (state, action) => {
46+
addContext: (state, action:PayloadAction<AddContextPayload>) => {
1247
let newName = action.payload.name.trim();
1348
newName = newName.charAt(0).toUpperCase() + newName.slice(1);
1449
const newContext = {
@@ -18,7 +53,7 @@ const contextReducerSlice = createSlice({
1853
};
1954
state.allContext = [...state.allContext, newContext];
2055
},
21-
addContextValues: (state, action) => {
56+
addContextValues: (state, action: PayloadAction<AddContextValuesPayload>) => {
2257
const newAllContext = [...state.allContext];
2358

2459
for (let i = 0; i < newAllContext.length; i += 1) {
@@ -31,12 +66,12 @@ const contextReducerSlice = createSlice({
3166
}
3267
state.allContext = newAllContext;
3368
},
34-
deleteContext: (state, action) => {
69+
deleteContext: (state, action: PayloadAction<DeleteContextPayload>) => {
3570
const tempState = [...state.allContext];
3671
const remains = tempState.filter((el) => el.name !== action.payload.name);
3772
state.allContext = remains;
3873
},
39-
addComponentToContext: (state, action) => {
74+
addComponentToContext: (state, action: PayloadAction<AddComponentToContextPayload>) => {
4075
const newTempState = [...state.allContext];
4176
for (let i = 0; i < newTempState.length; i += 1) {
4277
if (newTempState[i].name === action.payload.context.name) {
@@ -45,7 +80,7 @@ const contextReducerSlice = createSlice({
4580
}
4681
state.allContext = newTempState;
4782
},
48-
getAllContext: (state, action) => {
83+
getAllContext: (state,action) => {
4984
state = state;
5085
},
5186
allContextCooperative: (state, action) => {

app/src/redux/store.js renamed to app/src/redux/store.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ import { configureStore } from '@reduxjs/toolkit';
33
// Import of combined reducers in rootReducer
44
import rootReducer from './reducers/rootReducer';
55

6+
/*
7+
// Define the root state type based on the rootReducer
8+
export type RootState = ReturnType<typeof rootReducer>;
9+
10+
// Define the type of the Redux store
11+
export type AppStore = Store<RootState>;
12+
*/
13+
614
const store = configureStore({
715
reducer: rootReducer,
8-
middleware: getDefaultMiddleware => {
9-
const ignoredPaths = [];
16+
middleware: (getDefaultMiddleware) => {
17+
let ignoredPaths: string[] = [];
1018

1119
for (let i = 0; i < 21; i++) {
1220
ignoredPaths.push(`appState.HTMLTypes.${i}.icon`);
@@ -20,16 +28,18 @@ const store = configureStore({
2028
// Ignore these field paths in all actions
2129
// ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
2230
// Ignore these paths in the state
23-
ignoredPaths: ignoredPaths,
24-
},
31+
// ignoredPaths: ignoredPaths,
32+
ignoredPaths
33+
}
2534
});
26-
},
35+
}
2736
});
2837

38+
// Define the root state type based on the rootReducer
39+
//export type RootState = ReturnType<typeof rootReducer>;
40+
export type RootState = ReturnType<typeof store.getState>;
2941

30-
31-
32-
33-
42+
// Define the type of the Redux store
43+
export type AppStore = typeof store;
3444

3545
export default store;

app/src/utils/createApplication.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import createFiles from './createFiles.util';
33
import { Component } from '../interfaces/Interfaces';
44
import createTestSuiteClassic from './createTestSuiteClassic.util';
5-
import store from '../redux/store.js';
5+
import store from '../redux/store.ts';
66

77
const camelToKebab = (camel: string) => {
88
return camel.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();

0 commit comments

Comments
 (0)