majic / src /redux /sagas /poiSaga.ts
nolual's picture
Upload 55 files
0c20ea8
import { put, takeLatest, call } from "redux-saga/effects";
import axios, { AxiosResponse, AxiosError, AxiosRequestConfig } from "axios";
import {
fetchPoiRequest,
fetchPoiSuccess,
fetchPoiFailure,
} from "../actions/poiActions";
import { Poi } from "../types/Poi";
function* fetchPoiData() {
try {
const config: AxiosRequestConfig = {
headers: {
key: "", // no more credits
},
};
const response: AxiosResponse = yield call(() =>
axios.get("https://api.seiki.co/v1/pois", config)
);
const data = response.data as Poi[];
yield put(fetchPoiSuccess(data));
} catch (error) {
const errorMessage = (error as AxiosError).message || "An error occurred.";
yield put(fetchPoiFailure(errorMessage));
}
}
export function* watchFetchPoi() {
yield takeLatest(fetchPoiRequest.type, fetchPoiData);
}