starchart/web/src/state/stars.ts

55 lines
1.1 KiB
TypeScript

import { conf } from "@/api";
import { Protostar, StarsApi } from "@/swagger";
import { defineStore } from "pinia";
type ChartInfoState = {
loading: boolean;
protostars: Protostar[];
};
export const useChartStore = defineStore({
id: "chart",
state: () =>
({
loading: true,
protostars: [],
} as ChartInfoState),
actions: {
async fetchChart() {
this.loading = true;
this.protostars = await new StarsApi(conf())
.chart()
.catch((e) => {
console.error(e);
return this.protostars;
})
.finally(() => {
this.loading = false;
});
},
},
});
export const useVisitStore = defineStore({
id: "chart",
state: () =>
({
loading: true,
protostars: [],
} as ChartInfoState),
actions: {
async fetchChart() {
this.loading = true;
this.protostars = await new StarsApi(conf())
.chart()
.catch((e) => {
console.error(e);
return this.protostars;
})
.finally(() => {
this.loading = false;
});
},
},
});