Skip to content
Snippets Groups Projects
Commit cd3eac2c authored by Albin Henriksson's avatar Albin Henriksson
Browse files

Resolve "Comment misc redux files"

parent d67e23c5
No related branches found
No related tags found
1 merge request!136Resolve "Comment misc redux files"
Pipeline #44707 passed with warnings
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:
......
......@@ -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:
......
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:
......
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:
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment