57 lines
1.6 KiB
Vue
57 lines
1.6 KiB
Vue
<script setup>
|
|
import {ref, computed, onMounted} from "vue";
|
|
import {request} from "../lib/gateway.js";
|
|
import {loadToken} from "../scripts/load_token.js";
|
|
|
|
const pending = Symbol('pending')
|
|
|
|
const qref = ref(pending)
|
|
const isPending = computed(() => qref.value === pending)
|
|
const data = computed(() => qref.value.data)
|
|
|
|
async function loadAuctions() { // TODO: add params
|
|
let token = loadToken()
|
|
if(!token.token) return;
|
|
|
|
try {
|
|
let response = await request("/auctions", {cors: true, token: token.token})
|
|
qref.value = {error: null, headers: response.headers, data: await response.json()}
|
|
} catch (error) {
|
|
qref.value = {error}
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await loadAuctions()
|
|
})
|
|
|
|
function formatPrice(price) {
|
|
const fmt = new Intl.NumberFormat("en-US", {style: "currency", currency: "USD"}) // TODO: maybe load currency from backend or env
|
|
|
|
return fmt.format(price)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<template v-if="isPending">
|
|
<div class="spinner-border me-1" role="status"></div>
|
|
<span>Loading…</span>
|
|
</template>
|
|
<div v-else-if="!isPending && data != null && data.length > 0" class="auctions-section" role="list">
|
|
<div v-for="auction in data" :key="auction.id" class="card" role="listitem">
|
|
<div class="card-body">
|
|
<h2 class="h5">{{ auction.name }}</h2>
|
|
<p class="text-end">{{ formatPrice(auction.currentBid || auction.startingPrice) }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p v-else>No auctions available</p>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.auctions-section {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(20em, 1fr));
|
|
gap: 1em;
|
|
}
|
|
</style> |