Compare commits
2 Commits
14b2f01ef1
...
575d4dc5ab
| Author | SHA1 | Date | |
|---|---|---|---|
| 575d4dc5ab | |||
| 2c728c7037 |
@@ -27,17 +27,27 @@ export const useApraisalStore = defineStore('appraisal', () => {
|
||||
|
||||
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
|
||||
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
const now = new Date().getTime();
|
||||
const cached = types.map(t => cache.value[t.id]).filter(c => c && now - c.date.getTime() < cacheDuration);
|
||||
const uncached = types.filter(t => !cached.find(c => c.price.type.id === t.id));
|
||||
const now = new Date();
|
||||
const cached: MarketTypePrice[] = [];
|
||||
const uncached: MarketType[] = [];
|
||||
|
||||
types.forEach(t => {
|
||||
const cachedPrice = cache.value[t.id];
|
||||
|
||||
if (cachedPrice && now.getTime() - cachedPrice.date.getTime() < cacheDuration) {
|
||||
cached.push(cachedPrice.price);
|
||||
} else {
|
||||
uncached.push(t);
|
||||
}
|
||||
});
|
||||
|
||||
if (uncached.length > 0) {
|
||||
const prices = await getPricesUncached(uncached);
|
||||
|
||||
prices.forEach(p => cache.value[p.type.id] = { price: p, date: new Date() });
|
||||
return [...cached.map(c => c.price), ...prices];
|
||||
prices.forEach(p => cache.value[p.type.id] = { price: p, date: now });
|
||||
return [...cached, ...prices];
|
||||
}
|
||||
return cached.map(c => c.price);
|
||||
return cached;
|
||||
};
|
||||
return { getPrice, getPrices };
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
import { formatIsk, percentFormater } from '@/formaters';
|
||||
import { MarketType, MarketTypeLabel } from "@/market";
|
||||
import { SortableHeader, useSort } from '@/table';
|
||||
import { ShoppingCartIcon } from '@heroicons/vue/24/outline';
|
||||
import { ShoppingCartIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed, ref } from 'vue';
|
||||
import { ScanResult, getHistoryQuartils } from '.';
|
||||
@@ -25,6 +25,7 @@ interface Props {
|
||||
|
||||
interface Emits {
|
||||
(e: 'buy', type: MarketType, buy: number, sell: number): void;
|
||||
(e: 'remove', type: MarketType): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -110,6 +111,7 @@ const getLineColor = (result: Result) => {
|
||||
<td class="text-right">{{ percentFormater.format(r.profit) }}</td>
|
||||
<td class="text-right">
|
||||
<button class="btn-icon-stroke me-1" @click="$emit('buy', r.type, r.buy, r.sell)"><ShoppingCartIcon /></button>
|
||||
<button class="btn-icon-stroke me-1" @click="$emit('remove', r.type)"><TrashIcon /></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -41,6 +41,9 @@ const addItem = async () => {
|
||||
}
|
||||
addOrRelaod(type);
|
||||
}
|
||||
const removeItem = (type: MarketType) => {
|
||||
items.value = items.value.filter(i => i.type.id !== type.id);
|
||||
}
|
||||
|
||||
|
||||
watch(items, async itms => markeyScanStore.setTypes(itms.map(i => i.type.id)));
|
||||
@@ -72,7 +75,7 @@ watch(() => markeyScanStore.types, async t => {
|
||||
</div>
|
||||
<template v-if="items.length > 0">
|
||||
<hr />
|
||||
<ScanResultTable :items="items" @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 })" @remove="removeItem" />
|
||||
<BuyModal ref="buyModal" />
|
||||
</template>
|
||||
</template>
|
||||
Reference in New Issue
Block a user