40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { EsiMarketOrderHistory, getHistory, MarketType, MarketTypePrice } from "@/market";
|
|
import log from "loglevel";
|
|
import { defineStore } from "pinia";
|
|
import { computed, ref } from "vue";
|
|
|
|
export type TrackingResult = {
|
|
type: MarketType;
|
|
history: EsiMarketOrderHistory[];
|
|
buy: number,
|
|
sell: number,
|
|
orderCount: number,
|
|
}
|
|
|
|
const endpoint = '/api/types_tracking/';
|
|
|
|
export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
|
const trackedTypes = ref<any[]>([]); // TODO
|
|
|
|
const types = computed(() => trackedTypes.value.map(item => item.type) ?? []);
|
|
const addType = async (type: number) => {
|
|
const found = trackedTypes.value.find(item => item.type === type);
|
|
|
|
if (!found) {
|
|
log.info(`Tracking type ${type}`);
|
|
}
|
|
}
|
|
const removeType = async (type: number) => {
|
|
const found = trackedTypes.value.find(item => item.type === type);
|
|
|
|
if (!found) {
|
|
return;
|
|
}
|
|
|
|
trackedTypes.value = trackedTypes.value.filter(t => t.id !== found.id);
|
|
}
|
|
|
|
return { types, addType, removeType };
|
|
});
|
|
|
|
export const createResult = async (id: number, price: MarketTypePrice): Promise<TrackingResult> => ({ history: await getHistory(id), ...price }); |