This commit is contained in:
2023-09-20 14:03:05 +02:00
parent 7c645b0d0b
commit 6a675c28bc
4 changed files with 22 additions and 46 deletions

View File

@@ -1,24 +1,13 @@
<script setup lang="ts">
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, getPrice, getPrices, jitaId } from "@/market";
import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, getPrice, getPrices, jitaId } from "@/market";
import { BuyModal, ScanResult, ScanResultTable } from '@/market/scan';
import { useStorage } from '@vueuse/core';
import { onMounted, ref, watch } from 'vue';
type MarketItemStorage = {
typeID: number;
history: MarketOrderHistory[];
}
const buyModal = ref<typeof BuyModal>();
const item = ref("");
/**
* @deprecated use itemsStorage instead
*
* TODO: remove this in the future
*/
const oldStorage = useStorage<MarketItemStorage[]>('market-items', []);
const itemsStorage = useStorage<MarketItemStorage[]>('market-scan-items', []);
const itemsStorage = useStorage<number[]>('market-scan-items', []);
const items = ref<ScanResult[]>([]);
const addOrRelaod = async (type: MarketType) => {
const typeID = type.id;
@@ -39,9 +28,6 @@ const addOrRelaod = async (type: MarketType) => {
items.value = [ ...items.value, item];
}
}
const reloadAll = async () => {
items.value = await Promise.all(items.value.map( async i => ({ ...i, history: await getHistory(jitaId, i.type.id) })));
}
const addItem = async () => {
const type = await getMarketType(item.value.split('\t')[0]);
@@ -49,26 +35,20 @@ const addItem = async () => {
addOrRelaod(type);
}
watch(items, itms => itemsStorage.value = itms.map(i => ({ typeID: i.type.id, history: i.history })));
watch(items, itms => itemsStorage.value = itms.map(i => i.type.id));
onMounted(async () => {
if (itemsStorage.value.length === 0) {
if (oldStorage.value.length > 0) {
itemsStorage.value = oldStorage.value;
oldStorage.value = [];
} else {
return;
}
return;
}
const prices = await getPrices(await getMarketTypes(itemsStorage.value.map(i => i.typeID)));
items.value = itemsStorage.value.map(i => {
const price = prices.find(p => p.type.id === i.typeID) as MarketTypePrice;
const prices = await getPrices(await getMarketTypes(itemsStorage.value));
items.value = await Promise.all(itemsStorage.value.map(async i => {
const price = prices.find(p => p.type.id === i) as MarketTypePrice;
const history = await getHistory(jitaId, i);
return { ...i, ...price };
});
return { id: i, history, ...price };
}));
});
</script>
@@ -83,7 +63,7 @@ onMounted(async () => {
</div>
<template v-if="items.length > 0">
<hr />
<ScanResultTable :items="items" @relaod="type => addOrRelaod(type)" @relaodAll="reloadAll" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" />
<ScanResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" />
<BuyModal ref="buyModal" />
</template>
</template>