25 lines
632 B
TypeScript
25 lines
632 B
TypeScript
import { queryAllShips } from "@/controller/DeviceController";
|
|
import { create } from "zustand";
|
|
|
|
type Ship = {
|
|
ships: Model.Ship[] | null;
|
|
getShip: () => Promise<void>;
|
|
error: string | null;
|
|
loading?: boolean;
|
|
};
|
|
|
|
export const useShip = create<Ship>((set) => ({
|
|
ships: null,
|
|
getShip: async () => {
|
|
try {
|
|
const response = await queryAllShips({});
|
|
set({ ships: response.data?.ships, loading: false });
|
|
} catch (error) {
|
|
console.error("Error when fetch Ship: ", error);
|
|
set({ error: "Failed to fetch Ship data", loading: false });
|
|
set({ ships: null });
|
|
}
|
|
},
|
|
error: null,
|
|
}));
|