Files
monitor-im-flur/src/store/kvv.ts

32 lines
1.0 KiB
TypeScript

import { create } from "zustand";
import { devtools } from "zustand/middleware";
import { fetchKvvDepartures } from "@/api/kvv";
import type { DepartureType } from "@/types/departureType";
const useKVVStore = create(
devtools(
(set) => ({
pStreet: [] as DepartureType[],
hStreet: [] as DepartureType[],
fetch: async () => {
const hStreetStopId = 7000044;
const pStreetStopId = 7000045;
const hStreetData = await fetchKvvDepartures(hStreetStopId);
const pStreetData = await fetchKvvDepartures(pStreetStopId);
const hStreetJson = await hStreetData.json();
const pStreetJson = await pStreetData.json();
set({
hStreet: hStreetJson as DepartureType[],
pStreet: pStreetJson as DepartureType[],
});
},
}),
{
name: "kvv-store",
},
),
);
export { useKVVStore };