import { Dispatch } from "redux" ; import { fetchImageService } from "../services/user" ; export const IMAGE_DATA_FETCHED = "IMAGE_DATA_FETCHED" ; export const DATA_LOADING = "DATA_LOADING" ; export const FETCH_MORE = "FETCH_MORE" ; export function fetchImageData ( page ? , limit ? ) { return ( dispatch ) => { dispatch ( loading ( true ) ) ; fetchImageService ( page , limit ) . then ( ( res ) => { dispatch ( imageDataFetched ( res ) ) ; dispatch ( loading ( false ) ) ; } ) . catch ( err => { dispatch ( loading ( false ) ) ; } ) ; } ; } export function fetchMoreImageData ( page ? , limit ? ) { return ( dispatch ) => { dispatch ( loading ( true ) ) ; fetchImageService ( page , limit ) . then ( ( res ) => { dispatch ( fetchMore ( res ) ) ; dispatch ( loading ( false ) ) ; } ) . catch ( err => { dispatch ( loading ( false ) ) ; } ) ; } ; } const imageDataFetched = ( data ) => ( { type : IMAGE_DATA_FETCHED , payload : data } ) ; const fetchMore = ( data ) => ( { type : FETCH_MORE , payload : data } ) ; export const loading = ( loader ) => ( { type : DATA_LOADING , payload : loader } ) ;