diff --git a/client/src/actions/cities.ts b/client/src/actions/cities.ts index efdb8c1dec986b31ce5aa41e006e181c26eb08c0..59f8be983260eec6f4e46e39d8218e2b5c8243eb 100644 --- a/client/src/actions/cities.ts +++ b/client/src/actions/cities.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the cities redux state */ @@ -6,7 +6,7 @@ import axios from 'axios' import { AppDispatch } from './../store' import Types from './types' -// Action creator to get all cities from api and send appropriate actions to reducer +/** Action creator to get all cities from api and send appropriate actions to reducer */ export const getCities = () => async (dispatch: AppDispatch) => { await axios .get('/api/misc/cities') diff --git a/client/src/actions/competitionLogin.ts b/client/src/actions/competitionLogin.ts index 97dc76e4499551bbfba87222aedae6e7a30bad72..d9f2833356bc66cc65e800bdc0481090ff3c0f16 100644 --- a/client/src/actions/competitionLogin.ts +++ b/client/src/actions/competitionLogin.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the competitionLogin redux state */ @@ -8,7 +8,7 @@ import { AppDispatch, RootState } from '../store' import { getPresentationCompetition } from './presentation' import Types from './types' -// Action creator to attempt to login with competition code +/** Action creator to attempt to login with competition code */ export const loginCompetition = (code: string, history: History, redirect: boolean) => async ( dispatch: AppDispatch, getState: () => RootState diff --git a/client/src/actions/competitions.ts b/client/src/actions/competitions.ts index 87b2b26ba844c0be6eafe5ee4f02920f9067d9e4..bae4813822e83db6feac319c9f5179e1c2164255 100644 --- a/client/src/actions/competitions.ts +++ b/client/src/actions/competitions.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the competitions redux state */ @@ -7,7 +7,7 @@ import { CompetitionFilterParams } from '../interfaces/FilterParams' import { AppDispatch, RootState } from './../store' import Types from './types' -// Get all competitions using filterParams from current state +/** Get all competitions using filterParams from current state */ export const getCompetitions = () => async (dispatch: AppDispatch, getState: () => RootState) => { const currentParams: CompetitionFilterParams = getState().competitions.filterParams // Send params in snake-case for api @@ -40,7 +40,7 @@ export const getCompetitions = () => async (dispatch: AppDispatch, getState: () }) } -// Dispatch action to set filter params +/** Dispatch action to set filter params */ export const setFilterParams = (params: CompetitionFilterParams) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_COMPETITIONS_FILTER_PARAMS, payload: params }) } diff --git a/client/src/actions/editor.ts b/client/src/actions/editor.ts index 526ad9ff6ae1698644e32ea02806c7a6e8e2cd78..aaee21a8a0439663583ca62ef526008d17b5b304 100644 --- a/client/src/actions/editor.ts +++ b/client/src/actions/editor.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the editor redux state */ @@ -6,7 +6,7 @@ import axios from 'axios' import { AppDispatch, RootState } from './../store' import Types from './types' -// Save competition in editor state from input id +/** Save competition in editor state from input id */ export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch, getState: () => RootState) => { await axios .get(`/api/competitions/${id}`) @@ -28,7 +28,7 @@ export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch }) } -// Set activeSlideId in editor state +/** Set activeSlideId in editor state */ export const setEditorSlideId = (id: number) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_EDITOR_SLIDE_ID, @@ -36,7 +36,7 @@ export const setEditorSlideId = (id: number) => (dispatch: AppDispatch) => { }) } -// Set activeViewTypeId in editor state +/** Set activeViewTypeId in editor state */ export const setEditorViewId = (id: number) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_EDITOR_VIEW_ID, diff --git a/client/src/actions/presentation.ts b/client/src/actions/presentation.ts index 32e4d0a4334c4639624588f005b704dbca160ae9..07536b213c7a8c95d5fc9b6c6515d4069a730b52 100644 --- a/client/src/actions/presentation.ts +++ b/client/src/actions/presentation.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the presentation redux state */ @@ -8,7 +8,7 @@ import { Timer } from '../interfaces/Timer' import store, { AppDispatch, RootState } from './../store' import Types from './types' -// Save competition in presentation state from input id +/** Save competition in presentation state from input id */ export const getPresentationCompetition = (id: string) => async (dispatch: AppDispatch, getState: () => RootState) => { await axios .get(`/api/competitions/${id}`) @@ -26,30 +26,36 @@ export const getPresentationCompetition = (id: string) => async (dispatch: AppDi }) } +/** Set presentation slide using input slide id */ export const setCurrentSlide = (slide: Slide) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_SLIDE, payload: slide }) } +/** Set presentation slide to previous slide in list */ export const setCurrentSlidePrevious = () => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_SLIDE_PREVIOUS }) } +/** Set presentation slide to next slide in list */ export const setCurrentSlideNext = () => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_SLIDE_NEXT }) } +/** Set presentation slide using input order */ export const setCurrentSlideByOrder = (order: number) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_SLIDE_BY_ORDER, payload: order }) } +/** Set code of presentation */ export const setPresentationCode = (code: string) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_CODE, payload: code }) } - +/** Set timer to input value */ export const setPresentationTimer = (timer: Timer) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_TIMER, payload: timer }) } +/** Decrement timer */ export const setPresentationTimerDecrement = () => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_PRESENTATION_TIMER, diff --git a/client/src/actions/roles.ts b/client/src/actions/roles.ts index 3f27d3a8ddc3f4c5f6963470a6eb5d4fe18cb014..68b86b30e415daa1c5b00470fb5e86b1cb10bd74 100644 --- a/client/src/actions/roles.ts +++ b/client/src/actions/roles.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the roles redux state */ @@ -6,7 +6,7 @@ import axios from 'axios' import { AppDispatch } from './../store' import Types from './types' -// Get all roles and dispatch action to save them to roles state +/** Get all roles and dispatch action to save them to roles state */ export const getRoles = () => async (dispatch: AppDispatch) => { await axios .get('/api/misc/roles') diff --git a/client/src/actions/searchUser.ts b/client/src/actions/searchUser.ts index c47ee9f3d0018763d7b2c134f7edbbf1094c2492..d47d4dd0903f57e1e298418bb72f43122b90407f 100644 --- a/client/src/actions/searchUser.ts +++ b/client/src/actions/searchUser.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the searchUser redux state */ @@ -7,7 +7,7 @@ import { UserFilterParams } from '../interfaces/FilterParams' import { AppDispatch, RootState } from './../store' import Types from './types' -// Get all users using current filterParams in searchUser state +/** Get all users using current filterParams in searchUser state */ export const getSearchUsers = () => async (dispatch: AppDispatch, getState: () => RootState) => { const currentParams: UserFilterParams = getState().searchUsers.filterParams // Send params in snake-case for api @@ -40,6 +40,7 @@ export const getSearchUsers = () => async (dispatch: AppDispatch, getState: () = }) } +/** Set filterParams in searchUser state */ export const setFilterParams = (params: UserFilterParams) => (dispatch: AppDispatch) => { dispatch({ type: Types.SET_SEARCH_USERS_FILTER_PARAMS, payload: params }) } diff --git a/client/src/actions/statistics.ts b/client/src/actions/statistics.ts index acde4316ef929b05ed38543aa9c5095ede63fa36..304099b2034ce727acff29bb3288fe3cea8e5087 100644 --- a/client/src/actions/statistics.ts +++ b/client/src/actions/statistics.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the statistics redux state */ @@ -6,7 +6,7 @@ import axios from 'axios' import { AppDispatch } from './../store' import Types from './types' -// Get all statistics and dispatch actions to save them to statistics state +/** Get all statistics and dispatch actions to save them to statistics state */ export const getStatistics = () => async (dispatch: AppDispatch) => { await axios .get('/api/misc/statistics') diff --git a/client/src/actions/types.ts b/client/src/actions/types.ts index 0ca8a02ffa1d115e165091276b740131be9d9758..c73179c114c3512d0c8dca9230054ea44d81c195 100644 --- a/client/src/actions/types.ts +++ b/client/src/actions/types.ts @@ -1,32 +1,44 @@ -/* -This file includes all redux action types +/** +This file includes all redux action action types */ +/** Includes all actions types */ export default { + // User login action types LOADING_UI: 'LOADING_UI', LOADING_USER: 'LOADING_USER', - LOADING_COMPETITION_LOGIN: 'LOADING_COMPETITION_LOGIN', + SET_ERRORS: 'SET_ERRORS', + CLEAR_ERRORS: 'CLEAR_ERRORS', SET_ROLES: 'SET_ROLES', SET_USER: 'SET_USER', + SET_UNAUTHENTICATED: 'SET_UNAUTHENTICATED', + SET_AUTHENTICATED: 'SET_AUTHENTICATED', + + // Search user action types SET_SEARCH_USERS: 'SET_SEARCH_USERS', SET_SEARCH_USERS_FILTER_PARAMS: 'SET_SEARCH_USERS_FILTER_PARAMS', SET_SEARCH_USERS_COUNT: 'SET_SEARCH_USERS_COUNT', SET_SEARCH_USERS_TOTAL_COUNT: 'SET_SEARCH_USERS_TOTAL_COUNT', - SET_ERRORS: 'SET_ERRORS', - CLEAR_ERRORS: 'CLEAR_ERRORS', + + // Competition login action types + LOADING_COMPETITION_LOGIN: 'LOADING_COMPETITION_LOGIN', SET_COMPETITION_LOGIN_DATA: 'SET_COMPETITION_LOGIN_DATA', SET_COMPETITION_LOGIN_UNAUTHENTICATED: 'SET_COMPETITION_LOGIN_UNAUTHENTICATED', SET_COMPETITION_LOGIN_ERRORS: 'SET_COMPETITION_LOGIN_ERRORS', CLEAR_COMPETITION_LOGIN_ERRORS: 'CLEAR_COMPETITION_LOGIN_ERRORS', - SET_UNAUTHENTICATED: 'SET_UNAUTHENTICATED', - SET_AUTHENTICATED: 'SET_AUTHENTICATED', + + // Competitions action types SET_COMPETITIONS: 'SET_COMPETITIONS', SET_COMPETITIONS_FILTER_PARAMS: 'SET_COMPETITIONS_FILTER_PARAMS', SET_COMPETITIONS_TOTAL: 'SET_COMPETITIONS_TOTAL', SET_COMPETITIONS_COUNT: 'SET_COMPETITIONS_COUNT', + + // Editor action types SET_EDITOR_COMPETITION: 'SET_EDITOR_COMPETITION', SET_EDITOR_SLIDE_ID: 'SET_EDITOR_SLIDE_ID', SET_EDITOR_VIEW_ID: 'SET_EDITOR_VIEW_ID', + + // Presentation action types SET_PRESENTATION_COMPETITION: 'SET_PRESENTATION_COMPETITION', SET_PRESENTATION_SLIDE: 'SET_PRESENTATION_SLIDE', SET_PRESENTATION_SLIDE_PREVIOUS: 'SET_PRESENTATION_SLIDE_PREVIOUS', @@ -34,13 +46,21 @@ export default { SET_PRESENTATION_SLIDE_BY_ORDER: 'SET_PRESENTATION_SLIDE_BY_ORDER', SET_PRESENTATION_CODE: 'SET_PRESENTATION_CODE', SET_PRESENTATION_TIMER: 'SET_PRESENTATION_TIMER', + + // Cities action types SET_CITIES: 'SET_CITIES', SET_CITIES_TOTAL: 'SET_CITIES_TOTAL', SET_CITIES_COUNT: 'SET_CITIES_COUNT', + + // Types action types SET_TYPES: 'SET_TYPES', + + // Media action types SET_MEDIA_ID: 'SET_MEDIA_ID', SET_MEDIA_FILENAME: 'SET_MEDIA_ID', SET_MEDIA_TYPE_ID: 'SET_MEDIA_TYPE_ID', SET_MEDIA_USER_ID: 'SET_MEDIA_USER_ID', + + // Statistics action types SET_STATISTICS: 'SET_STATISTICS', } diff --git a/client/src/actions/typesAction.ts b/client/src/actions/typesAction.ts index b6e9c98ad4f5b0a2593f1fe4d4cde9590f4d6370..06519257e96c86f256bb14ec74e85d595366faf9 100644 --- a/client/src/actions/typesAction.ts +++ b/client/src/actions/typesAction.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the types redux state */ @@ -6,7 +6,7 @@ import axios from 'axios' import { AppDispatch } from './../store' import Types from './types' -// Get all types and save them to types state +/** Get all types and save them to types state */ export const getTypes = () => async (dispatch: AppDispatch) => { await axios .get('/api/misc/types') diff --git a/client/src/actions/user.ts b/client/src/actions/user.ts index 3448fa995dd6f10ed8ec61049ad041bcf164e1b7..a94730fa61c89ee09b483138e90f87a8669afb8a 100644 --- a/client/src/actions/user.ts +++ b/client/src/actions/user.ts @@ -1,4 +1,4 @@ -/* +/** This file handles actions for the user redux state */ @@ -8,7 +8,7 @@ import { AppDispatch } from '../store' import { AccountLoginModel } from './../interfaces/FormModels' import Types from './types' -// Attempt to log in user, dispatch correct actions and save jwt token to localStorage and axios auth header +/** Attempt to log in user, dispatch correct actions and save jwt token to localStorage and axios auth header */ export const loginUser = (userData: AccountLoginModel, history: History) => async (dispatch: AppDispatch) => { dispatch({ type: Types.LOADING_UI }) await axios @@ -30,7 +30,7 @@ export const loginUser = (userData: AccountLoginModel, history: History) => asyn }) } -// Get data for user and save to user state +/** Get data for user and save to user state */ export const getUserData = () => async (dispatch: AppDispatch) => { dispatch({ type: Types.LOADING_USER }) await axios @@ -46,7 +46,7 @@ export const getUserData = () => async (dispatch: AppDispatch) => { }) } -// Log out user and remove jwt token from local storage and axios +/** Log out user and remove jwt token from local storage and axios */ export const logoutUser = () => async (dispatch: AppDispatch) => { localStorage.removeItem('token') await axios.post('/api/auth/logout').then(() => { diff --git a/client/src/hooks.ts b/client/src/hooks.ts index 597f2813de15896121aea601caa50cc42edd0579..914e9aa81f043e785867df7a35a801a3ce60b845 100644 --- a/client/src/hooks.ts +++ b/client/src/hooks.ts @@ -1,5 +1,9 @@ +/** This file includes typed versions of redux hooks */ + import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' import type { AppDispatch, RootState } from './store' +/** Typed version of useDispatch, this should be used every single time instead of useDispatch */ export const useAppDispatch = () => useDispatch<AppDispatch>() +/** Typed version of useSelector, this should be used every single time instead of useSelector */ export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector diff --git a/client/src/reducers/allReducers.ts b/client/src/reducers/allReducers.ts index 038b172e3e308af71d5762ade8a644b67d7992d2..29b8d2c4bcf9cd71eaa0cdbff988530c35976c47 100644 --- a/client/src/reducers/allReducers.ts +++ b/client/src/reducers/allReducers.ts @@ -1,4 +1,4 @@ -// Combines all the reducers so that we only have to pass "one" reducer to the store in src/index.tsx +/** 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 citiesReducer from './citiesReducer' @@ -13,8 +13,8 @@ import typesReducer from './typesReducer' import uiReducer from './uiReducer' import userReducer from './userReducer' +/** All reducers combined */ const allReducers = combineReducers({ - // name: state user: userReducer, UI: uiReducer, competitions: competitionsReducer, diff --git a/client/src/reducers/citiesReducer.ts b/client/src/reducers/citiesReducer.ts index 4fbc5a1cc559fe11994b41fed5073dde304472aa..22cf54f8749c98e3970f36d8642a5fb20c8eb653 100644 --- a/client/src/reducers/citiesReducer.ts +++ b/client/src/reducers/citiesReducer.ts @@ -2,20 +2,21 @@ import { AnyAction } from 'redux' import Types from '../actions/types' import { City } from '../interfaces/ApiModels' -// Define a type for the city state +/** Define a type for the city state */ interface CityState { cities: City[] total: number count: number } -// Define initial values for the city state +/** Define initial values for the city state */ const initialState: CityState = { cities: [], total: 0, count: 0, } +/** Intercept actions for cities state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_CITIES: diff --git a/client/src/reducers/competitionLoginReducer.ts b/client/src/reducers/competitionLoginReducer.ts index d06f8e3029f11298dfe905bfd71041d0a06bf8b9..f3ca764c0a6a243301dd980830c08e3d35818aab 100644 --- a/client/src/reducers/competitionLoginReducer.ts +++ b/client/src/reducers/competitionLoginReducer.ts @@ -1,18 +1,18 @@ import { AnyAction } from 'redux' import Types from '../actions/types' -// Define a type for the competition login data +/** Define a type for the competition login data */ interface CompetitionLoginData { competition_id: number team_id: number | null view: string } -// Define a type for UI error +/** Define a type for UI error */ interface UIError { message: string } -// Define a type for the competition login state +/** Define a type for the competition login state */ interface CompetitionLoginState { loading: boolean errors: null | UIError @@ -21,7 +21,7 @@ interface CompetitionLoginState { initialized: boolean } -// Define the initial values for the competition login state +/** Define the initial values for the competition login state */ const initialState: CompetitionLoginState = { loading: false, errors: null, @@ -30,6 +30,7 @@ const initialState: CompetitionLoginState = { initialized: false, } +/** Intercept actions for competitionLogin state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_COMPETITION_LOGIN_DATA: diff --git a/client/src/reducers/competitionsReducer.ts b/client/src/reducers/competitionsReducer.ts index 8a99b29bfcea7f10ab7e6b83393b76bc16756fa5..62b7006ebe0e379ab58774b6e317a1fdbe592d22 100644 --- a/client/src/reducers/competitionsReducer.ts +++ b/client/src/reducers/competitionsReducer.ts @@ -3,6 +3,7 @@ import Types from '../actions/types' import { Competition } from '../interfaces/ApiModels' import { CompetitionFilterParams } from './../interfaces/FilterParams' +/** Define a type for competitions state */ interface CompetitionState { competitions: Competition[] total: number @@ -10,7 +11,7 @@ interface CompetitionState { filterParams: CompetitionFilterParams } -// Define the initial values for the competition state +/** Define the initial values for the competition state */ const initialState: CompetitionState = { competitions: [], total: 0, @@ -18,6 +19,7 @@ const initialState: CompetitionState = { filterParams: { pageSize: 10, page: 0 }, } +/** Intercept actions for competitions state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_COMPETITIONS: diff --git a/client/src/reducers/editorReducer.ts b/client/src/reducers/editorReducer.ts index 4f245d1d05638cc059cf8d26921642d8239c169a..8aa14592cb403652eb3c2e42c22312cfd824d0ca 100644 --- a/client/src/reducers/editorReducer.ts +++ b/client/src/reducers/editorReducer.ts @@ -2,6 +2,7 @@ import { AnyAction } from 'redux' import Types from '../actions/types' import { RichCompetition } from '../interfaces/ApiRichModels' +/** Define a type for editor state */ interface EditorState { competition: RichCompetition activeSlideId: number @@ -9,6 +10,7 @@ interface EditorState { loading: boolean } +/** Define initial values for the editor state */ const initialState: EditorState = { competition: { name: '', @@ -24,6 +26,7 @@ const initialState: EditorState = { loading: true, } +/** Intercept actions for editor state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_EDITOR_COMPETITION: diff --git a/client/src/reducers/presentationReducer.ts b/client/src/reducers/presentationReducer.ts index 578b0a279c824210892be87bd69e0f62b74d7c89..374baf32c9cf88001ee0ff8bd740a211f12f3740 100644 --- a/client/src/reducers/presentationReducer.ts +++ b/client/src/reducers/presentationReducer.ts @@ -4,7 +4,7 @@ import { Slide } from '../interfaces/ApiModels' import { Timer } from '../interfaces/Timer' import { RichCompetition } from './../interfaces/ApiRichModels' -// Define a type for the presentation state +/** Define a type for the presentation state */ interface PresentationState { competition: RichCompetition slide: Slide @@ -12,7 +12,7 @@ interface PresentationState { timer: Timer } -// Define the initial values for the presentation state +/** Define the initial values for the presentation state */ const initialState: PresentationState = { competition: { name: '', @@ -38,6 +38,7 @@ const initialState: PresentationState = { }, } +/** Intercept actions for presentation state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_PRESENTATION_COMPETITION: diff --git a/client/src/reducers/rolesReducer.ts b/client/src/reducers/rolesReducer.ts index 8fc1465ae10f50dbf25d52b0f013c72647f5321a..994ebb1e18c3f855bb3b6fd5a9bc98a54d4ee004 100644 --- a/client/src/reducers/rolesReducer.ts +++ b/client/src/reducers/rolesReducer.ts @@ -2,16 +2,17 @@ import { AnyAction } from 'redux' import Types from '../actions/types' import { Role } from '../interfaces/ApiModels' -// Define a type for the role state +/** Define a type for the role state */ interface RoleState { roles: Role[] } -// Define the initial values for the role state +/** Define the initial values for the role state */ const initialState: RoleState = { roles: [], } +/** Intercept actions for roles state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_ROLES: diff --git a/client/src/reducers/searchUserReducer.ts b/client/src/reducers/searchUserReducer.ts index 38269dfb604ddd5072293f8c101088012ce8f7f5..1e78f8961e014714dd6f1a8b762902298a2287a2 100644 --- a/client/src/reducers/searchUserReducer.ts +++ b/client/src/reducers/searchUserReducer.ts @@ -3,7 +3,7 @@ import Types from '../actions/types' import { User } from '../interfaces/ApiModels' import { UserFilterParams } from '../interfaces/FilterParams' -// Define a type for the search user state +/** Define a type for the search user state */ interface SearchUserState { users: User[] total: number @@ -11,7 +11,7 @@ interface SearchUserState { filterParams: UserFilterParams } -// Define the initial values for the search user state +/** Define the initial values for the search user state */ const initialState: SearchUserState = { users: [], total: 0, @@ -19,6 +19,7 @@ const initialState: SearchUserState = { filterParams: { pageSize: 10, page: 0 }, } +/** Intercept actions for searchUser state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_SEARCH_USERS: diff --git a/client/src/reducers/statisticsReducer.ts b/client/src/reducers/statisticsReducer.ts index bc957ccb97f2fde20eca5d44bf818650a7a01eb7..4975bd7f381e728ac6d05237b66d050f8369b50d 100644 --- a/client/src/reducers/statisticsReducer.ts +++ b/client/src/reducers/statisticsReducer.ts @@ -1,20 +1,21 @@ import { AnyAction } from 'redux' import Types from '../actions/types' -// Define a type for the statistics state +/** Define a type for the statistics state */ interface StatisticsState { users: number competitions: number regions: number } -// Define the initial values for the statistics state +/** Define the initial values for the statistics state */ const initialState: StatisticsState = { users: 0, competitions: 0, regions: 0, } +/** Intercept actions for statistics state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_STATISTICS: diff --git a/client/src/reducers/typesReducer.ts b/client/src/reducers/typesReducer.ts index 10ea1c63b3f9f8f2b47f997d1036f71bc51450ac..927077435f27573aea52c71c809102fed325cb94 100644 --- a/client/src/reducers/typesReducer.ts +++ b/client/src/reducers/typesReducer.ts @@ -2,14 +2,14 @@ import { AnyAction } from 'redux' import Types from '../actions/types' import { ComponentType, MediaType, QuestionType, ViewType } from '../interfaces/ApiModels' -// Define a type for the Types state +/** Define a type for the Types state */ interface TypesState { componentTypes: ComponentType[] viewTypes: ViewType[] questionTypes: QuestionType[] mediaTypes: MediaType[] } -// Define the initial values for the types state +/** Define the initial values for the types state */ const initialState: TypesState = { componentTypes: [], viewTypes: [], @@ -17,6 +17,7 @@ const initialState: TypesState = { mediaTypes: [], } +/** Intercept actions for types state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_TYPES: diff --git a/client/src/reducers/uiReducer.ts b/client/src/reducers/uiReducer.ts index 350f7b8e8aaa08752252343a95f4703770d2bb77..0b650683b8b90d10dc3c7567b771c4b9b24f13f4 100644 --- a/client/src/reducers/uiReducer.ts +++ b/client/src/reducers/uiReducer.ts @@ -1,23 +1,24 @@ import { AnyAction } from 'redux' import Types from '../actions/types' -// Define a type for the UI error +/** Define a type for the UI error */ interface UIError { message: string } -// Define a type for the UI state +/** Define a type for the UI state */ interface UIState { loading: boolean errors: null | UIError } -// Define the initial values for the UI state +/** Define the initial values for the UI state */ const initialState: UIState = { loading: false, errors: null, } +/** Intercept actions for ui state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_ERRORS: diff --git a/client/src/reducers/userReducer.ts b/client/src/reducers/userReducer.ts index 6b4f985b43a80a8f2cd91213a6b4c938f6543560..155cf2a804ed175407eccd2b8a937b99d4b7246b 100644 --- a/client/src/reducers/userReducer.ts +++ b/client/src/reducers/userReducer.ts @@ -1,7 +1,7 @@ import { AnyAction } from 'redux' import Types from '../actions/types' -// Define a type for users info +/** Define a type for users info */ interface UserInfo { name: string email: string @@ -10,20 +10,21 @@ interface UserInfo { id: number } -// Define a type for the users state +/** Define a type for the users state */ interface UserState { authenticated: boolean userInfo: UserInfo | null loading: boolean } -// Define the initial values for the users state +/** Define the initial values for the users state */ const initialState: UserState = { authenticated: false, loading: false, userInfo: null, } +/** Intercept actions for user state and update the state */ export default function (state = initialState, action: AnyAction) { switch (action.type) { case Types.SET_AUTHENTICATED: diff --git a/client/src/store.ts b/client/src/store.ts index 8eec0a48d943be786ec85b4bd7ac06b16e0989e2..66e384d33b364864175b8ecd52e9e417d106dfda 100644 --- a/client/src/store.ts +++ b/client/src/store.ts @@ -2,7 +2,7 @@ import { AnyAction, applyMiddleware, compose, createStore } from 'redux' import { composeWithDevTools } from 'redux-devtools-extension' import thunk, { ThunkAction, ThunkDispatch } from 'redux-thunk' import allReducers from './reducers/allReducers' -/* +/** TypeScript does not know the type of the property. Therefore, you will get the error; Property ‘__REDUX_DEVTOOLS_EXTENSION_COMPOSE__’ does not exist on type ‘Window’. Hence, you need to add the property to the global window as below. @@ -19,10 +19,13 @@ const middleware = [thunk] // const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose // allows Mozilla plugin to view state in a GUI, https://github.com/zalmoxisus/redux-devtools-extension#13-use-redux-devtools-extension-package-from-npm // const store = createStore(allReducers, composeEnhancers(applyMiddleware())) -// simple store with plugin +/** Simple store with plugins and middleware */ const store = createStore(allReducers, initialState, composeWithDevTools(applyMiddleware(...middleware))) +/** Type of thunk */ export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, RootState, unknown, AnyAction> +/** Type of state */ export type RootState = ReturnType<typeof store.getState> +/** Type of dispatch */ export type AppDispatch = ThunkDispatch<RootState, void, AnyAction> export default store