pocketbase login
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, getPrice, getPrices, jitaId } from "@/market";
|
||||
import { BuyModal, ScanResult, ScanResultTable } from '@/market/scan';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { usePocketBase } from "@/pocketbase";
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
const pb = usePocketBase();
|
||||
|
||||
type MarketScan = {
|
||||
id?: string;
|
||||
owner: string;
|
||||
types: number[];
|
||||
}
|
||||
|
||||
const buyModal = ref<typeof BuyModal>();
|
||||
|
||||
const item = ref("");
|
||||
const itemsStorage = useStorage<number[]>('market-scan-items', []);
|
||||
|
||||
const items = ref<ScanResult[]>([]);
|
||||
const addOrRelaod = async (type: MarketType) => {
|
||||
const typeID = type.id;
|
||||
@@ -35,15 +43,28 @@ const addItem = async () => {
|
||||
addOrRelaod(type);
|
||||
}
|
||||
|
||||
watch(items, itms => itemsStorage.value = itms.map(i => i.type.id));
|
||||
const getMarketScan = () => pb.collection('marketScans').getFirstListItem<MarketScan>("").catch(() => null);
|
||||
|
||||
watch(items, async itms => {
|
||||
const types = itms.map(i => i.type.id);
|
||||
const marketScan = await getMarketScan();
|
||||
|
||||
if (marketScan?.id) {
|
||||
pb.collection('marketScans').update(marketScan.id, { owner: pb.authStore.model!.id, types });
|
||||
} else {
|
||||
pb.collection('marketScans').create({ owner: pb.authStore.model!.id, types });
|
||||
}
|
||||
});
|
||||
onMounted(async () => {
|
||||
if (itemsStorage.value.length === 0) {
|
||||
const marketScan = await getMarketScan();
|
||||
|
||||
if (!marketScan || marketScan.types.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prices = await getPrices(await getMarketTypes(itemsStorage.value));
|
||||
const prices = await getPrices(await getMarketTypes(marketScan.types));
|
||||
|
||||
items.value = await Promise.all(itemsStorage.value.map(async i => {
|
||||
items.value = await Promise.all(marketScan.types.map(async i => {
|
||||
const price = prices.find(p => p.type.id === i) as MarketTypePrice;
|
||||
const history = await getHistory(jitaId, i);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user