scan front

This commit is contained in:
Sirttas
2026-06-11 20:32:46 +02:00
parent dd031551ca
commit 7ca38aee70
11 changed files with 155 additions and 175 deletions
+67
View File
@@ -0,0 +1,67 @@
<script setup lang="ts">
import { getMarketTypes, TaxInput, useApraisalStore, useMarketTaxStore } from "@/market";
import { BuyModal } from '@/market/acquisition';
import { ScanResult, ScanResultTable, toScanResult } from '@/market/scan';
import { marketApi } from "@/mammon";
import { useStorage } from "@vueuse/core";
import { ref, watch } from 'vue';
const buyModal = ref<typeof BuyModal>();
const apraisalStore = useApraisalStore();
const marketTaxStore = useMarketTaxStore();
const days = useStorage('market-scan-days', 365);
const items = ref<ScanResult[]>([]);
const loading = ref(false);
const scan = async () => {
loading.value = true;
try {
const { data } = await marketApi.scanMarket(
String(days.value),
String(marketTaxStore.brokerFee / 100),
String(marketTaxStore.scc / 100)
);
const types = await getMarketTypes(data.map(r => r.marketTypeId));
const prices = await apraisalStore.getPrices(types);
items.value = data.flatMap(r => {
const type = types.find(t => t.id === r.marketTypeId);
const price = prices.find(p => p.type.id === r.marketTypeId);
return type && price ? [toScanResult(r, type, price)] : [];
});
} finally {
loading.value = false;
}
}
watch([days, () => marketTaxStore.brokerFee, () => marketTaxStore.scc], scan, { immediate: true });
</script>
<template>
<div class="flex mb-2 mt-4">
<div class="flex justify-self-end ms-auto">
<TaxInput />
<div class="end">
<span>Days: </span>
<input type="number" min="1" max="365" step="1" v-model="days" />
</div>
</div>
</div>
<hr />
<div v-if="loading" class="text-center mt-4">
<span>Scanning market</span>
</div>
<template v-else>
<ScanResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" />
<BuyModal ref="buyModal" />
</template>
</template>
<style scoped>
@reference "@/style.css";
div.end {
@apply justify-self-end ms-2;
}
</style>