mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
This commit is contained in:
parent
91a91cb6a3
commit
491d72bd3c
7 changed files with 122 additions and 45 deletions
|
|
@ -3,53 +3,26 @@ import prismaClient from 'utils/prisma-client'
|
|||
import * as m from 'paraglide/messages'
|
||||
import { AlbumStatus } from '@prisma/client'
|
||||
|
||||
import BaseLayout from 'layouts/base.astro'
|
||||
import AlbumBox from 'components/AlbumBox.astro'
|
||||
import FooterNav from 'components/lastAdded/FooterNav.astro'
|
||||
import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro'
|
||||
|
||||
const page = parseInt(Astro.params.page ?? '1')
|
||||
const page = Math.min(1, parseInt(Astro.params.page ?? '1'))
|
||||
const take = 40
|
||||
const limitMD = 12
|
||||
const limitXS = 5
|
||||
|
||||
if (page < 1) {
|
||||
Astro.redirect('/last-added')
|
||||
}
|
||||
|
||||
const lastAlbums = await prismaClient.albums.findMany({
|
||||
const albums = await prismaClient.albums.findMany({
|
||||
where: { status: AlbumStatus.SHOW },
|
||||
select: { id: true, title: true },
|
||||
take,
|
||||
skip: take * (page - 1),
|
||||
orderBy: { createdAt: 'desc' }
|
||||
orderBy: { publishedAt: 'desc' }
|
||||
})
|
||||
const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } })
|
||||
|
||||
if (lastAlbums.length === 0) {
|
||||
Astro.redirect('/404')
|
||||
}
|
||||
|
||||
const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1)
|
||||
const listProps = { fullPageList, page }
|
||||
const listProps = { fullPageList, page, albums, limitMD, limitXS }
|
||||
---
|
||||
|
||||
<BaseLayout>
|
||||
<div class='w-full min-h-100vh mx-auto max-w-[1440px]'>
|
||||
<div class='px-2 mb-2'>
|
||||
<h1 class='uppercase font-medium tracking-wide text-5xl drop-shadow-2xl mt-5 mb-2 text-center'>
|
||||
{m.lastAdded()}
|
||||
</h1>
|
||||
<div class='grid grid-cols-2 md:grid-cols-4 gap-x-1.5'>
|
||||
{
|
||||
lastAlbums.map((album) => (
|
||||
<AlbumBox title={album.title} href={`/album/${album.id}`} image={`/album/${album.id}.png`} />
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<nav class='bg-dark p-2'>
|
||||
<FooterNav class='flex md:hidden' pageLimit={limitXS} {...listProps} />
|
||||
<FooterNav class='hidden md:flex' pageLimit={limitMD} {...listProps} />
|
||||
</nav>
|
||||
</div>
|
||||
</BaseLayout>
|
||||
<PaginatedAlbumList {...listProps}>
|
||||
{m.lastAdded()}
|
||||
</PaginatedAlbumList>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue