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

Resolve "Documentation for redux"

parent ac4d03fa
No related branches found
No related tags found
1 merge request!95Resolve "Documentation for redux"
Pipeline #42333 passed with warnings
/*
This file handles actions for the cities redux state
*/
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
export const getCities = () => async (dispatch: AppDispatch) => {
await axios
.get('/api/misc/cities')
......
/*
This file handles actions for the competitionLogin redux state
*/
import axios from 'axios'
import { History } from 'history'
import { AppDispatch } from '../store'
import { AccountLoginModel } from './../interfaces/FormModels'
import Types from './types'
// Action creator to attempt to login with competition code
export const loginCompetition = (code: string, history: History) => async (dispatch: AppDispatch) => {
dispatch({ type: Types.LOADING_COMPETITION_LOGIN })
await axios
......
/*
This file handles actions for the competitions redux state
*/
import axios from 'axios'
import { CompetitionFilterParams } from '../interfaces/FilterParams'
import { AppDispatch, RootState } from './../store'
import Types from './types'
// 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
......@@ -34,6 +39,8 @@ export const getCompetitions = () => async (dispatch: AppDispatch, getState: ()
console.log(err)
})
}
// 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
*/
import axios from 'axios'
import { AppDispatch, RootState } from './../store'
import Types from './types'
// Save competition in editor state from input id
export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch, getState: () => RootState) => {
await axios
.get(`/api/competitions/${id}`)
......@@ -19,6 +24,7 @@ export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch
})
}
// Set currentSlideId in editor state
export const setEditorSlideId = (id: number) => (dispatch: AppDispatch) => {
dispatch({
type: Types.SET_EDITOR_SLIDE_ID,
......
/*
This file handles actions for the presentation redux state
*/
import axios from 'axios'
import { Slide } from '../interfaces/ApiModels'
import { Timer } from '../interfaces/Timer'
import store, { AppDispatch } from './../store'
import Types from './types'
// Save competition in presentation state from input id
export const getPresentationCompetition = (id: string) => async (dispatch: AppDispatch) => {
await axios
.get(`/api/competitions/${id}`)
......@@ -18,6 +23,7 @@ export const getPresentationCompetition = (id: string) => async (dispatch: AppDi
})
}
// Get all teams from current presentation competition
export const getPresentationTeams = (id: string) => async (dispatch: AppDispatch) => {
await axios
.get(`/api/competitions/${id}/teams`)
......
/*
This file handles actions for the roles redux state
*/
import axios from 'axios'
import { AppDispatch } from './../store'
import Types from './types'
// 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
*/
import axios from 'axios'
import { UserFilterParams } from '../interfaces/FilterParams'
import { AppDispatch, RootState } from './../store'
import Types from './types'
// 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
......@@ -34,6 +39,7 @@ export const getSearchUsers = () => async (dispatch: AppDispatch, getState: () =
console.log(err)
})
}
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
*/
import axios from 'axios'
import { AppDispatch } from './../store'
import Types from './types'
// 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
*/
export default {
LOADING_UI: 'LOADING_UI',
LOADING_USER: 'LOADING_USER',
......
/*
This file handles actions for the types redux state
*/
import axios from 'axios'
import { AppDispatch } from './../store'
import Types from './types'
// 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
*/
import axios from 'axios'
import { History } from 'history'
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
export const loginUser = (userData: AccountLoginModel, history: History) => async (dispatch: AppDispatch) => {
dispatch({ type: Types.LOADING_UI })
await axios
......@@ -25,6 +30,7 @@ export const loginUser = (userData: AccountLoginModel, history: History) => asyn
})
}
// Get data for user and save to user state
export const getUserData = () => async (dispatch: AppDispatch) => {
dispatch({ type: Types.LOADING_USER })
await axios
......@@ -40,6 +46,7 @@ export const getUserData = () => async (dispatch: AppDispatch) => {
})
}
// 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(() => {
......
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