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
Showing
with 89 additions and 48 deletions
/*
/**
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')
......
/*
/**
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
......
/*
/**
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 })
}
/*
/**
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,
......
/*
/**
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,
......
/*
/**
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')
......
/*
/**
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 })
}
/*
/**
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')
......
/*
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',
}
/*
/**
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')
......
/*
/**
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(() => {
......
/** 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
// 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,
......
......@@ -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:
......
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:
......
......@@ -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:
......
......@@ -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:
......
......@@ -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:
......
......@@ -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:
......
......@@ -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:
......
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