-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.tsx
32 lines (25 loc) · 1 KB
/
handlers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// utils/handlers.ts
import { AppDispatch } from "../store";
import { setSearchName, setSearchType, setDistance, searchExercises } from "../Model/addWorkout/addWorkoutSlice";
import { ExerciseType } from "../Model/workouts/workoutsSlice";
import { SelectChangeEvent } from "@mui/material";
import { useDispatch } from "react-redux";
export function useHandlers() {
const dispatch = useDispatch<AppDispatch>();
function handleSetName(name: string) {
dispatch(setSearchName(name));
}
async function handleSearch() {
const response = await dispatch(searchExercises());
if (response.meta.requestStatus === "rejected") {
console.log("Error fetching exercises. Try again later.", "error");
}
}
function handleSetType(event: SelectChangeEvent) {
dispatch(setSearchType(event.target.value as ExerciseType | "all"));
}
function handleSetDistance(distance: number) {
dispatch(setDistance(distance));
}
return { handleSetName, handleSearch, handleSetType, handleSetDistance };
}