You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
659 B
27 lines
659 B
// redux/actions/moveAction.ts
|
|
|
|
import { FETCH_MOVES } from '../constants';
|
|
import { Move } from "../../entities/Move";
|
|
import { Dispatch } from "redux";
|
|
import { API_BASE_URL } from "../../config";
|
|
|
|
export const setMoves = (moves: Move[]) => {
|
|
return {
|
|
type: FETCH_MOVES,
|
|
payload: moves,
|
|
};
|
|
}
|
|
|
|
export const getMoves = () => {
|
|
return async (dispatch: Dispatch) => {
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/move`);
|
|
const data = await response.json();
|
|
dispatch(setMoves(data));
|
|
}
|
|
catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
}
|