40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, jitaId } from "@/market";
|
|
import { defineStore } from "pinia";
|
|
import { computed, ref } from "vue";
|
|
|
|
export type ScanResult = {
|
|
type: MarketType;
|
|
history: MarketOrderHistory[];
|
|
buy: number,
|
|
sell: number,
|
|
orderCount: number,
|
|
}
|
|
|
|
type MarketScan = {
|
|
owner: string,
|
|
types: number[]
|
|
};
|
|
|
|
const marketScans = 'marketScans';
|
|
|
|
export const useMarketScanStore = defineStore(marketScans, () => {
|
|
const marketScan = ref<MarketScan>();
|
|
|
|
const types = computed(() => marketScan.value?.types ?? []);
|
|
const setTypes = async (types: number[]) => {
|
|
|
|
}
|
|
const addType = async (type: number) => {
|
|
if (!types.value.includes(type)) {
|
|
await setTypes([...types.value, type]);
|
|
}
|
|
}
|
|
const removeType = async (type: number) => {
|
|
if (types.value.includes(type)) {
|
|
await setTypes(types.value.filter(t => t !== type));
|
|
}
|
|
}
|
|
return { types, setTypes, addType, removeType };
|
|
});
|
|
|
|
export const createResult = async (id: number, price: MarketTypePrice): Promise<ScanResult> => ({ history: await getHistory(jitaId, id), ...price }); |