thêm zustand để cấu hình global state, hook để lấy platform, thêm polyline và polygon b vào map
This commit is contained in:
27
state/use-banzones.ts
Normal file
27
state/use-banzones.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { queryBanzones } from "@/controller/MapController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type Banzone = {
|
||||
banzones: Model.Zone[];
|
||||
getBanzone: () => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const useBanzones = create<Banzone>()((set) => ({
|
||||
banzones: [],
|
||||
getBanzone: async () => {
|
||||
set({ loading: true });
|
||||
try {
|
||||
const response = await queryBanzones();
|
||||
console.log("Banzone fetching: ", response.data.length);
|
||||
|
||||
set({ banzones: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch Banzones: ", error);
|
||||
set({ error: "Failed to fetch banzone data", loading: false });
|
||||
set({ banzones: [] });
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
}));
|
||||
Reference in New Issue
Block a user