update netDetail

This commit is contained in:
2025-11-07 11:54:16 +07:00
parent b9cd637b33
commit 25b9e831d1
6 changed files with 93 additions and 17 deletions

26
state/use-fish.ts Normal file
View File

@@ -0,0 +1,26 @@
import { queryFish } from "@/controller/FishController";
import { create } from "zustand";
type Fish = {
fishSpecies: Model.FishSpeciesResponse | null;
getFishSpecies: () => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useFishes = create<Fish>((set) => ({
fishSpecies: null,
getFishSpecies: async () => {
try {
const response = await queryFish();
console.log("Fish fetching API");
set({ fishSpecies: response.data, loading: false });
} catch (error) {
console.error("Error when fetch fish: ", error);
set({ error: "Failed to fetch fish data", loading: false });
set({ fishSpecies: null });
}
},
error: null,
}));