update interface, diary

This commit is contained in:
2025-12-04 15:54:49 +07:00
parent 4d60ce279e
commit 0672f8adf9
10 changed files with 291 additions and 90 deletions

31
state/use-thing.ts Normal file
View File

@@ -0,0 +1,31 @@
import { querySearchThings } from "@/controller/DeviceController";
import { create } from "zustand";
type ThingState = {
things: Model.Thing[] | null;
getThings: (body: Model.SearchThingBody) => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useThings = create<ThingState>((set) => ({
things: null,
getThings: async (body: Model.SearchThingBody) => {
set({ loading: true, error: null });
try {
const response = await querySearchThings(body);
console.log("Things fetching API: ", response.data.things?.length);
set({ things: response.data.things ?? [], loading: false });
} catch (error) {
console.error("Error when fetch things: ", error);
set({
error: "Failed to fetch things data",
loading: false,
things: null,
});
}
},
error: null,
loading: false,
}));