diff --git a/client/package-lock.json b/client/package-lock.json index 4eaa596f50f01a515a2c44db6152ebc0883bd0ba..283deca695ee7ef78fd7f34dbd3991f385caab82 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -15980,6 +15980,12 @@ "is-typedarray": "^1.0.0" } }, + "typesafe-actions": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/typesafe-actions/-/typesafe-actions-5.1.0.tgz", + "integrity": "sha512-bna6Yi1pRznoo6Bz1cE6btB/Yy8Xywytyfrzu/wc+NFW3ZF0I+2iCGImhBsoYYCOWuICtRO4yHcnDlzgo1AdNg==", + "dev": true + }, "typescript": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", diff --git a/client/package.json b/client/package.json index ccfa1134525936e1555231281e828ad02a1b127d..62063ad624b7d1947b3834b11f70dbbc6f452fcf 100644 --- a/client/package.json +++ b/client/package.json @@ -46,7 +46,8 @@ "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-prettier": "^3.3.1", "eslint-plugin-react": "^7.22.0", - "prettier": "^2.2.1" + "prettier": "^2.2.1", + "typesafe-actions": "^5.1.0" }, "scripts": { "start": "react-scripts start", diff --git a/client/src/actions/communication.js b/client/src/actions/communication.js deleted file mode 100644 index 587f431ea260e09400d948fe1bab73d08b60a784..0000000000000000000000000000000000000000 --- a/client/src/actions/communication.js +++ /dev/null @@ -1,62 +0,0 @@ -import Types from "./types.js"; - -export function axiosPost(path, data, config = undefined, - startCB = undefined, successCB = undefined, errorCB = undefined){ - return { - type: Types.AXIOS_POST, - path, - data, - config, - startCB, - successCB, - errorCB - } -} - -export function axiosPostSuccess(path, data, previousAction){ - return { - type: Types.AXIOS_POST_SUCCESS, - path, - data, - previousAction - } -} - -export function axiosPostError(path, data, previousAction){ - return { - type: Types.AXIOS_POST_ERROR, - path, - data, - previousAction - } -} - -export function axiosGet(path, data, config = undefined, startCB = undefined, successCB = undefined, errorCB = undefined) { - return { - type: Types.AXIOS_GET, - path, - data, - config, - startCB, - successCB, - errorCB - } -} - -export function axiosGetSuccess(path, data, previousAction){ - return { - type: Types.AXIOS_GET_SUCCESS, - path, - data, - previousAction - } -} - -export function axiosGetError(path, data, previousAction){ - return { - type: Types.AXIOS_GET_ERROR, - path, - data, - previousAction - } -} diff --git a/client/src/actions/communication.ts b/client/src/actions/communication.ts new file mode 100644 index 0000000000000000000000000000000000000000..d0719cd320f73b11d8a8243130a67896a48bf6e0 --- /dev/null +++ b/client/src/actions/communication.ts @@ -0,0 +1,75 @@ +import Types from './types.js' + +export function axiosPost( + path: any, + data: any, + config = undefined, + startCB = undefined, + successCB = undefined, + errorCB = undefined +) { + return { + type: Types.AXIOS_POST, + path, + data, + config, + startCB, + successCB, + errorCB, + } +} + +export function axiosPostSuccess(path: any, data: any, previousAction: any) { + return { + type: Types.AXIOS_POST_SUCCESS, + path, + data, + previousAction, + } +} + +export function axiosPostError(path: any, data: any, previousAction: any) { + return { + type: Types.AXIOS_POST_ERROR, + path, + data, + previousAction, + } +} + +export function axiosGet( + path: any, + data: any, + config = undefined, + startCB = undefined, + successCB = undefined, + errorCB = undefined +) { + return { + type: Types.AXIOS_GET, + path, + data, + config, + startCB, + successCB, + errorCB, + } +} + +export function axiosGetSuccess(path: any, data: any, previousAction: any) { + return { + type: Types.AXIOS_GET_SUCCESS, + path, + data, + previousAction, + } +} + +export function axiosGetError(path: any, data: any, previousAction: any) { + return { + type: Types.AXIOS_GET_ERROR, + path, + data, + previousAction, + } +} diff --git a/client/src/actions/login.js b/client/src/actions/login.ts similarity index 100% rename from client/src/actions/login.js rename to client/src/actions/login.ts diff --git a/client/src/actions/types.js b/client/src/actions/types.ts similarity index 100% rename from client/src/actions/types.js rename to client/src/actions/types.ts diff --git a/client/src/reducers/allReducers.js b/client/src/reducers/allReducers.js deleted file mode 100644 index 2bfcd5ead021f503794ff14e7b7f3a9da0473129..0000000000000000000000000000000000000000 --- a/client/src/reducers/allReducers.js +++ /dev/null @@ -1,11 +0,0 @@ -// Combines all the reducers so that we only have to pass "one" reducer to the store in src/index.tsx - - -import { combineReducers } from 'redux'; -import loggedInReducer from './isLoggedIn'; - -const allReducers = combineReducers({ - // name: state - isLoggedIn: loggedInReducer // You can write "loggedInReducer" because its the same as "loggedInReducer: loggedInReducer" -}); -export default allReducers; \ No newline at end of file diff --git a/client/src/reducers/allReducers.ts b/client/src/reducers/allReducers.ts new file mode 100644 index 0000000000000000000000000000000000000000..4903f9d73f25dcfb29a2fd99ee45bca18aa24895 --- /dev/null +++ b/client/src/reducers/allReducers.ts @@ -0,0 +1,10 @@ +// Combines all the reducers so that we only have to pass "one" reducer to the store in src/index.tsx + +import { combineReducers } from 'redux' +import loggedInReducer from './isLoggedIn' + +const allReducers = combineReducers({ + // name: state + isLoggedIn: loggedInReducer, // You can write "loggedInReducer" because its the same as "loggedInReducer: loggedInReducer" +}) +export default allReducers diff --git a/client/src/reducers/isLoggedIn.js b/client/src/reducers/isLoggedIn.js deleted file mode 100644 index b665894a5d8136391d34e8512c631867d2a851f2..0000000000000000000000000000000000000000 --- a/client/src/reducers/isLoggedIn.js +++ /dev/null @@ -1,9 +0,0 @@ -const loggedInReducer = (state = false, action) => { // isLoggedIn has an initial state of false - switch (action.type) { - case 'SIGN_IN': - return !state; - default: - return state; - } -} -export default loggedInReducer diff --git a/client/src/reducers/isLoggedIn.ts b/client/src/reducers/isLoggedIn.ts new file mode 100644 index 0000000000000000000000000000000000000000..cf5d7b43177c6b13113d18ab88d018cc8c9cf724 --- /dev/null +++ b/client/src/reducers/isLoggedIn.ts @@ -0,0 +1,10 @@ +const loggedInReducer = (state = false, action: { type: any }) => { + // isLoggedIn has an initial state of false + switch (action.type) { + case 'SIGN_IN': + return !state + default: + return state + } +} +export default loggedInReducer