type info

This commit is contained in:
2023-11-07 11:00:08 +01:00
parent 75f70cfd25
commit ee6bbfd442
12 changed files with 179 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import { MarketOrderHistory, MarketType } from "@/market";
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, jitaId } from "@/market";
import { usePocketBase, watchCollection } from "@/pocketbase";
import { defineStore } from "pinia";
import { RecordModel } from "pocketbase";
@@ -31,6 +31,16 @@ export const useMarketScanStore = defineStore(marketScans, () => {
marketScan.value = await pb.collection(marketScans).create({ owner: pb.authStore.model!.id, types });
}
}
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));
}
}
watchCollection<MarketScan>(marketScans, '*', data => {
if (data.action === 'delete') {
@@ -40,5 +50,7 @@ export const useMarketScanStore = defineStore(marketScans, () => {
}
});
onMounted(async () => marketScan.value = await pb.collection(marketScans).getFirstListItem<MarketScan>('').catch(() => undefined));
return { types, setTypes };
});
return { types, setTypes, addType, removeType };
});
export const createResult = async (id: number, price: MarketTypePrice): Promise<ScanResult> => ({ history: await getHistory(jitaId, id), ...price });