send-gift: cuadrícula de objetos 4/fila centrada + paginación
Aplana el catálogo y lo pagina (8 por página = 2 filas de 4) con controles Atrás / 1 2 3 / Siguiente centrados. Nuevas clases .gift-grid (grid 4 cols, responsive a 2 en móvil) y .gift-pagination en novawow-style.css. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,17 @@ export function SendGiftForm({
|
|||||||
[cart],
|
[cart],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Catálogo aplanado y paginado: 4 objetos por fila, 2 filas (8) por página.
|
||||||
|
const PAGE_SIZE = 8
|
||||||
|
const allItems = useMemo(
|
||||||
|
() => catalog.flatMap((c) => c.items.map((it) => ({ ...it, category: c.name }))),
|
||||||
|
[catalog],
|
||||||
|
)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const totalPages = Math.max(1, Math.ceil(allItems.length / PAGE_SIZE))
|
||||||
|
const currentPage = Math.min(page, totalPages)
|
||||||
|
const pageItems = allItems.slice((currentPage - 1) * PAGE_SIZE, currentPage * PAGE_SIZE)
|
||||||
|
|
||||||
function addItem(item: GiftItem) {
|
function addItem(item: GiftItem) {
|
||||||
setCart((prev) => {
|
setCart((prev) => {
|
||||||
const next = new Map(prev)
|
const next = new Map(prev)
|
||||||
@@ -158,34 +169,45 @@ export function SendGiftForm({
|
|||||||
<SecretInput value={token} onChange={setToken} placeholder="Token de seguridad" />
|
<SecretInput value={token} onChange={setToken} placeholder="Token de seguridad" />
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
{/* Catálogo de objetos */}
|
{/* Catálogo de objetos: cuadrícula centrada de 4 por fila + paginación */}
|
||||||
<div className="justified">
|
<h3 className="first-brown centered">Objetos disponibles</h3>
|
||||||
{catalog.map((cat) => (
|
<div className="gift-grid">
|
||||||
<div key={cat.id}>
|
{pageItems.map((it) => (
|
||||||
<h3 className="first-brown">{cat.name}</h3>
|
<div className="item-box" key={it.id}>
|
||||||
<div>
|
<a href={`https://www.wowhead.com/wotlk/item=${it.itemId}`} target="_blank" rel="noreferrer noopener">
|
||||||
{cat.items.map((it) => (
|
<img className="item-img-box" src={it.imageUrl} alt={it.name} />
|
||||||
<div className="item-box" key={it.id}>
|
</a>
|
||||||
<a
|
<div className="third-brown" style={{ fontSize: '12px' }}>{it.category}</div>
|
||||||
href={`https://www.wowhead.com/wotlk/item=${it.itemId}`}
|
<div className="item-name second-brown">{it.name}</div>
|
||||||
target="_blank"
|
<div className="yellow-info">
|
||||||
rel="noreferrer noopener"
|
{it.price} {currency}
|
||||||
>
|
|
||||||
<img className="item-img-box" src={it.imageUrl} alt={it.name} />
|
|
||||||
</a>
|
|
||||||
<div className="item-name second-brown">{it.name}</div>
|
|
||||||
<div className="yellow-info">
|
|
||||||
{it.price} {currency}
|
|
||||||
</div>
|
|
||||||
<button type="button" className="store-add-button" onClick={() => addItem(it)}>
|
|
||||||
Añadir
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
|
<button type="button" className="store-add-button" onClick={() => addItem(it)}>
|
||||||
|
Añadir
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
{totalPages > 1 && (
|
||||||
|
<div className="gift-pagination">
|
||||||
|
<button type="button" onClick={() => setPage((p) => Math.max(1, Math.min(totalPages, p) - 1))} disabled={currentPage === 1}>
|
||||||
|
Atrás
|
||||||
|
</button>
|
||||||
|
{Array.from({ length: totalPages }, (_, i) => i + 1).map((n) => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
key={n}
|
||||||
|
className={n === currentPage ? 'active-page' : ''}
|
||||||
|
onClick={() => setPage(n)}
|
||||||
|
>
|
||||||
|
{n}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
<button type="button" onClick={() => setPage((p) => Math.min(totalPages, Math.min(totalPages, p) + 1))} disabled={currentPage === totalPages}>
|
||||||
|
Siguiente
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
{/* Carrito */}
|
{/* Carrito */}
|
||||||
|
|||||||
@@ -1957,6 +1957,41 @@ th {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Enviar regalo: cuadrícula de objetos (4 por fila) centrada + paginación */
|
||||||
|
.gift-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, 160px);
|
||||||
|
gap: 10px;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gift-grid .item-box {
|
||||||
|
width: auto;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gift-pagination {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gift-pagination button {
|
||||||
|
width: auto;
|
||||||
|
min-width: 34px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
margin: 0 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gift-pagination button.active-page {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #d79602;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
.gift-grid { grid-template-columns: repeat(2, 160px); }
|
||||||
|
}
|
||||||
|
|
||||||
/* Font Awesome */
|
/* Font Awesome */
|
||||||
.fa-caret-down {
|
.fa-caret-down {
|
||||||
color: #7e8d09;
|
color: #7e8d09;
|
||||||
|
|||||||
Reference in New Issue
Block a user