Files
pokemon/src/pages/partials/card-modal.astro

262 lines
15 KiB
Plaintext

---
import ebay from "/vendors/ebay.svg?raw";
import SetIcon from '../../components/SetIcon.astro';
import EnergyIcon from '../../components/EnergyIcon.astro';
import RarityIcon from '../../components/RarityIcon.astro';
import { db } from '../../db/index.ts';
import { privateDecrypt } from "node:crypto";
import latestSales from '../../sampleData/latestsales.json';
import chartdata from '../../sampleData/chartdata.json';
const priceData = chartdata;
export const partial = true;
export const prerender = false;
const searchParams = Astro.url.searchParams;
const productId = Number(searchParams.get('productId')) || 0;
// query the database for the card with the given productId and return the card data as json
const card = await db.query.cards.findFirst({
where: { productId: Number(productId) },
with: {
prices: true,
set: true,
}
});
const nearMint = await db.query.skus.findFirst({
where: {
productId: Number(productId),
}
});
const nearMintPrice = nearMint?.marketPrice ?? null;
const calculatedAt = new Date(nearMint?.calculatedAt || 0);
function timeAgo(date: any) {
if (date==0) return "never";
const seconds = Math.floor((Date.now() - date) / 1000);
const intervals = {
year: 31536000,
month: 2592000,
day: 86400,
hour: 3600,
minute: 60
};
for (const [unit, value] of Object.entries(intervals)) {
const count = Math.floor(seconds / value);
if (count >= 1) return `${count} ${unit}${count > 1 ? "s" : ""} ago`;
}
return "just now";
}
---
<div class="modal-dialog modal-dialog-centered modal-fullscreen-md-down modal-xl">
<div class="modal-dialog modal-dialog-centered modal-fullscreen-md-down modal-xl">
<div class="modal-content">
<div class="modal-header border-0">
<div class="container-fluid">
<span class="h4 card-title pe-2">{card?.productName}</span><span class="text-secondary ps-2 border-start">{card?.number}</span><span class="text-secondary ps-2">{nearMint?.variant}</span>
</div>
<button type="button" class="btn-close" aria-label="Close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body pt-0">
<div class="container-fluid">
<div class="card mb-2 border-0">
<div class="row g-4">
<div class="col-sm-12 col-md-3">
<p class="text-secondary">{card?.set?.setName}</p>
<div class="position-relative d-inline-block"><img src={`/cards/${card?.productId}.jpg`} class="card-image img-fluid rounded" alt={card?.productName} onerror="this.onerror=null;this.src='/cards/noImage.webp'"><span class="position-absolute bottom-0 start-0 d-inline"><SetIcon set={card?.set?.setName} /></span><span class="position-absolute top-0 end-0 d-inline"><EnergyIcon energy={card?.energyType} /></span><span class="rarity-icon-large position-absolute bottom-0 end-0 d-inline"><RarityIcon rarity={card?.rarityName} /></span></div>
<div class="d-flex flex-row justify-content-between mt-2">
<div class="p text-secondary">{card?.Artist}</div>
</div>
</div>
<div class="col-sm-12 col-md-7">
<nav>
<div class="nav nav-tabs nav-sm-fill border-0" id="nav-tab" role="tablist">
<button class="nav-link nm active" id="nav-nm" data-bs-toggle="tab" data-bs-target="#nav-nm" type="button" role="tab" aria-controls="nav-nm" aria-selected="true"><span class="d-none d-md-inline">Near Mint</span><span class="d-md-none">NM</span></button>
<button class="nav-link lp" id="nav-lp" data-bs-toggle="tab" data-bs-target="#nav-lp" type="button" role="tab" aria-controls="nav-lp" aria-selected="false"><span class="d-none d-md-inline">Lightly Played</span><span class="d-md-none">LP</span></button>
<button class="nav-link mp" id="nav-mp" data-bs-toggle="tab" data-bs-target="#nav-mp" type="button" role="tab" aria-controls="nav-mp" aria-selected="false"><span class="d-none d-md-inline">Moderately Played</span><span class="d-md-none">MP</span></button>
<button class="nav-link hp" id="nav-hp" data-bs-toggle="tab" data-bs-target="#nav-hp" type="button" role="tab" aria-controls="nav-hp" aria-selected="false"><span class="d-none d-md-inline">Heavily Played</span><span class="d-md-none">HP</span></button>
<button class="nav-link dmg" id="nav-dmg" data-bs-toggle="tab" data-bs-target="#nav-dmg" type="button" role="tab" aria-controls="nav-dmg" aria-selected="false"><span class="d-none d-md-inline">Damaged</span><span class="d-md-none">DMG</span></button>
<button class="nav-link vendor" id="nav-vendor" data-bs-toggle="tab" data-bs-target="#nav-vendor" type="button" role="tab" aria-controls="nav-vendor" aria-selected="false"><span class="d-none d-md-inline">Inventory</span><span class="d-md-none">+/-</span></button>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-nm" role="tabpanel" aria-labelledby="nav-nm" tabindex="0">
<div class="row g-2 mt-2">
<div class="mt-2 col-12 col-md-3 row row-cols-3 row-cols-md-1">
<div class="col dark-callout rounded mb-1 py-2">
<p class="h6">Market Price</p>
<p class="py-0 mb-1">${nearMintPrice}</p>
</div>
<div class="col dark-callout rounded mb-1 py-2">
<p class="h6">Lowest List</p>
<p class="py-0 mb-1">${nearMint?.lowestPrice}</p>
</div>
<div class="col dark-callout rounded mb-1 py-2">
<p class="h6">Highest List</p>
<p class="py-0 mb-1">${nearMint?.highestPrice}</p>
</div>
<div class="col-12 alert alert-success mb-1 py-2">
<p class="h6">Low Volatility</p>
</div>
</div>
<div class="d-flex flex-column mt-2 col-12 col-md-9">
<div class="dark-callout rounded table-responsive pt-1 ps-2 mb-1">
<p class="h6">Latest Sales</p>
<table class="table small table-dark table-sm table-striped table-hover">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Price</th>
<th scope="col">Condition</th>
<th scope="col">Title</th>
</tr>
</thead>
<tbody>
{latestSales.data.map(sale => (
<tr>
<td>{new Date(sale.orderDate).toLocaleDateString()}</td>
<td>${sale.purchasePrice}</td>
<td>{sale.condition}</td>
<td>{sale.title}</td>
</tr>
))}
</tbody>
</table>
</div>
<div class="dark-callout rounded p-2 mb-0 flex-fill">
<p class="h6">Placeholder for graph</p>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-lp" role="tabpanel" aria-labelledby="nav-lp" tabindex="0">
<div class="row g-2 mt-2">
<div class="d-flex flex-column mt-2 col-3">
<div class="dark-callout rounded p-2 mb-2">
<h6>Market Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Lowest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Highest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Volatility</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2 flex-fill">
<h6>Latest Sales</h6>
<p></p>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-mp" role="tabpanel" aria-labelledby="nav-mp" tabindex="0">
<div class="row g-2 mt-2">
<div class="d-flex flex-column mt-2 col-3">
<div class="dark-callout rounded p-2 mb-2">
<h6>Market Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Lowest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Highest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Volatility</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2 flex-fill">
<h6>Latest Sales</h6>
<p></p>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-hp" role="tabpanel" aria-labelledby="nav-hp" tabindex="0">
<div class="row g-2 mt-2">
<div class="d-flex flex-column mt-2 col-3">
<div class="dark-callout rounded p-2 mb-2">
<h6>Market Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Lowest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Highest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Volatility</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2 flex-fill">
<h6>Latest Sales</h6>
<p></p>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-dmg" role="tabpanel" aria-labelledby="nav-dmg" tabindex="0">
<div class="row g-2 mt-2">
<div class="d-flex flex-column mt-2 col-3">
<div class="dark-callout rounded p-2 mb-2">
<h6>Market Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Lowest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Highest Price</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2">
<h6>Volatility</h6>
<p></p>
</div>
<div class="dark-callout rounded p-2 mb-2 flex-fill">
<h6>Latest Sales</h6>
<p></p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-2 mt-0 mt-md-5">
<a class="btn btn-secondary mb-2 w-100" href={`https://www.tcgplayer.com/product/${card?.productId}`} target="_blank"><img src="/vendors/tcgplayer.webp"> TCGPlayer</a>
<a class="btn btn-secondary mb-2 w-100" href={`https://www.ebay.com/sch/i.html?_nkw=${card?.productUrlName}+${card?.number}&LH_Sold=1&Graded=No&_dcat=183454${card?.productId}`} target="_blank"><span set:html={ebay} /></a>
</div>
</div>
<div class="text-end my-0"><small class="text-body-secondary">Prices last updated: {timeAgo(calculatedAt)}</small></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>