- wrap root layout with QueryProvider for React Query - replace market UnderConstruction placeholder with MarketClient and real data fetching - implement search, pagination, and sort via search params using getActiveListings - add necessary client components and queries - update dependencies (e.g., prisma, pkg-types)
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import Header from "@/components/Header";
|
|
import { getTranslations } from "next-intl/server";
|
|
import type { Metadata } from "next";
|
|
import MarketClient from "./MarketClient";
|
|
import { getActiveListings } from "@/lib/prisma/queries/listings";
|
|
|
|
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",
|
|
});
|
|
|
|
return (
|
|
<div className="min-h-screen">
|
|
<Header />
|
|
<main className="container mx-auto px-4 py-8">
|
|
<MarketClient
|
|
initial={{
|
|
listings: listingsData.listings,
|
|
total: listingsData.total,
|
|
page,
|
|
pageSize,
|
|
totalPages: Math.ceil(listingsData.total / pageSize),
|
|
}}
|
|
/>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|