import axios from 'axios' ; import { Dispatch } from 'redux' ; import { getAllLatestArticles } from '../../frontend-rest-client/rest/articles' ; import { ArticleSortingOption , ArticlesReducerAction , ArticlesReducerActionTypes , } from '../../types/redux/articles-reducer-types' ; EXPORTS export { loadLatestArticles , addFilterOption , removeFilterOption , applySortingOption , } ; Action function returns { function } const loadLatestArticles = ( ) => { return async ( dispatch ) : Promise < void > => { dispatch ( { type : ArticlesReducerActionTypes . LOAD_DEV_TO_ARTICLES } ) ; try { const { data } = await getAllLatestArticles ( ) ; dispatch ( { type : ArticlesReducerActionTypes . DEV_TO_ARTICLES_DID_LOAD , payload : data , } ) ; } catch ( error ) { if ( axios . isAxiosError ( error ) ) { dispatch ( { type : ArticlesReducerActionTypes . DEV_TO_ARTICLES_LOAD_ERROR , payload : JSON . stringify ( error . response ) , } ) ; } } } ; } ; Action function returns { function } const addFilterOption = ( filterOption ) : ArticlesReducerAction => ( { type : ArticlesReducerActionTypes . ADD_FILTER_OPTION , payload : filterOption , } ) ; Action function returns { function } const removeFilterOption = ( filterOption ) : ArticlesReducerAction => ( { type : ArticlesReducerActionTypes . REMOVE_FILTER_OPTION , payload : filterOption , } ) ; Action function returns { function } const applySortingOption = ( sortingOption ) : ArticlesReducerAction => ( { type : ArticlesReducerActionTypes . APPLY_SORTING_PARAM , payload : sortingOption , } ) ;