import { Level } from '@logo-quiz/models' ; import { LevelActionTypes , REQUEST_LEVEL , REQUEST_LEVEL_SUCCESS , FLUSH_LEVEL } from './types' ; import { Dispatch } from 'redux' ; import { fetchLevel as apiFetchLevel } from '../../shared/services' ; export function requestLevel ( id ) { return { type : REQUEST_LEVEL , id } ; } export function requestLevelSuccess ( level ) { return { type : REQUEST_LEVEL_SUCCESS , level } ; } export function flushLevel ( ) { return { type : FLUSH_LEVEL } ; } export function fetchLevel ( id ) { return function ( dispatch ) { dispatch ( requestLevel ( id ) ) ; return apiFetchLevel ( id ) . then ( ( level ) => { dispatch ( requestLevelSuccess ( level ) ) ; } ) . catch ( error => { } ) ; } ; }