111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Header from "@/components/Header";
|
|
import { getActiveListings } from "@/lib/prisma/queries/listings";
|
|
import MarketClient from "./MarketClient";
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ locale: string }>;
|
|
}): Promise<Metadata> {
|
|
const { locale } = await params;
|
|
|
|
const titles = {
|
|
pt: "Mercado - Todos os Itens de Tibia",
|
|
en: "Market - All Tibia Items",
|
|
};
|
|
|
|
const descriptions = {
|
|
pt: "Explore todos os itens disponíveis no marketplace: armaduras, armas, escudos, poções e mais. Compre e venda com segurança usando nosso sistema de escrow.",
|
|
en: "Explore all items available in the marketplace: armors, weapons, shields, potions and more. Buy and sell safely using our escrow system.",
|
|
};
|
|
|
|
return {
|
|
title: titles[locale as keyof typeof titles],
|
|
description: descriptions[locale as keyof typeof descriptions],
|
|
keywords: [
|
|
"itens tibia",
|
|
"armaduras tibia",
|
|
"armas tibia",
|
|
"escudos tibia",
|
|
"comprar itens tibia",
|
|
"marketplace tibia",
|
|
],
|
|
};
|
|
}
|
|
|
|
export default async function MarketPage({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ locale: string }>;
|
|
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
|
}) {
|
|
const { locale } = await params;
|
|
const sp = (await searchParams) ?? {};
|
|
|
|
const page = typeof sp.page === "string" ? parseInt(sp.page, 10) : 1;
|
|
const pageSize =
|
|
typeof sp.pageSize === "string" ? parseInt(sp.pageSize, 10) : 20;
|
|
|
|
// Buscar anúncios ativos
|
|
const listingsData = await getActiveListings({
|
|
search: typeof sp.search === "string" ? sp.search : undefined,
|
|
server_name:
|
|
typeof sp.server_name === "string" ? sp.server_name : undefined,
|
|
page,
|
|
pageSize,
|
|
sortBy: (typeof sp.sortBy === "string" ? sp.sortBy : "created_at") as
|
|
| "created_at"
|
|
| "price_pix"
|
|
| "price_tibia_coins"
|
|
| "price_gold_coins"
|
|
| "views_count",
|
|
sortOrder: (typeof sp.sortOrder === "string" ? sp.sortOrder : "DESC") as
|
|
| "ASC"
|
|
| "DESC",
|
|
});
|
|
|
|
// Converter Date para string para compatibilidade com o tipo do cliente
|
|
const serializedListings = listingsData.listings.map((listing) => ({
|
|
...listing,
|
|
created_at:
|
|
listing.created_at instanceof Date
|
|
? listing.created_at.toISOString()
|
|
: listing.created_at,
|
|
updated_at:
|
|
listing.updated_at instanceof Date
|
|
? listing.updated_at.toISOString()
|
|
: listing.updated_at,
|
|
sold_at:
|
|
listing.sold_at instanceof Date
|
|
? listing.sold_at.toISOString()
|
|
: listing.sold_at,
|
|
auction_ends_at:
|
|
listing.auction_ends_at instanceof Date
|
|
? listing.auction_ends_at.toISOString()
|
|
: listing.auction_ends_at,
|
|
expires_at:
|
|
listing.expires_at instanceof Date
|
|
? listing.expires_at.toISOString()
|
|
: listing.expires_at,
|
|
}));
|
|
|
|
return (
|
|
<div className="min-h-screen">
|
|
<Header />
|
|
<main className="container mx-auto px-4 py-8">
|
|
<MarketClient
|
|
initial={{
|
|
listings: serializedListings as any,
|
|
total: listingsData.total,
|
|
page,
|
|
pageSize,
|
|
totalPages: Math.ceil(listingsData.total / pageSize),
|
|
}}
|
|
/>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|