import { PayloadAction } from '@reduxjs/toolkit' ; import { call , CallEffect , ForkEffect , put , PutEffect , takeLatest } from 'redux-saga/effects' ; import isEmpty from 'lodash/isEmpty' ; import { getAllFilmsFailed , getAllFilmsRequest , getAllFilmsSuccess } from './actions' ; import * as FilmsAPI from './apiCall' ; import { GetAllFilmsRequestPayload , GetAllFilmsSuccessPayload } from './types' ; function * getAllFilmsSaga ( { payload } ) { const { limit } = payload ; try { const filmsRes = yield call ( FilmsAPI . getAllFilms , { limit } ) ; if ( ! isEmpty ( filmsRes ) ) { yield put ( getAllFilmsSuccess ( filmsRes ) ) ; } else { yield put ( getAllFilmsFailed ( ) ) ; } } catch ( err ) { yield put ( getAllFilmsFailed ( ) ) ; } } function * artworkSaga ( ) { yield takeLatest ( getAllFilmsRequest . type , getAllFilmsSaga ) ; } export default artworkSaga ;