From 491d72bd3c4abaa2915abaa27be12d6e3de0036b Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 16:32:15 -0600 Subject: [PATCH] Anim and game releases pages --- astro.config.mjs | 2 -- messages/en.json | 5 +++- src/components/Header.astro | 19 +++++++----- src/layouts/PaginatedAlbumList.astro | 42 ++++++++++++++++++++++++++ src/pages/anim/latest/[...page].astro | 28 +++++++++++++++++ src/pages/game/latest/[...page].astro | 28 +++++++++++++++++ src/pages/last-added/[...page].astro | 43 +++++---------------------- 7 files changed, 122 insertions(+), 45 deletions(-) create mode 100644 src/layouts/PaginatedAlbumList.astro create mode 100644 src/pages/anim/latest/[...page].astro create mode 100644 src/pages/game/latest/[...page].astro diff --git a/astro.config.mjs b/astro.config.mjs index bc7ed16..2d35aa0 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -48,10 +48,8 @@ export default defineConfig({ output: 'server', adapter: node({ mode: 'standalone' }), redirects: { - '/anim': { status: 307, destination: '/maintenance' }, '/anim/[id]': { status: 307, destination: '/maintenance' }, '/anim/list': { status: 307, destination: '/maintenance' }, - '/game': { status: 307, destination: '/maintenance' }, '/game/[slug]': { status: 307, destination: '/maintenance' }, '/game/list': { status: 307, destination: '/maintenance' }, '/platform/list': { status: 307, destination: '/maintenance' }, diff --git a/messages/en.json b/messages/en.json index 87c78bb..336f621 100644 --- a/messages/en.json +++ b/messages/en.json @@ -81,5 +81,8 @@ "holy12_2": "12 clicks till midnight", "holy12_3": "We let our technicians pick these", "holy12_4": "It's noisy outside, take one of these", - "holy12_5": "Silksong is hidden behind one of these" + "holy12_5": "Silksong is hidden behind one of these", + "latestGameReleases": "Latest game releases", + "latestAnimReleases": " Latest animation releases", + "latestReleases": "Latest releases" } diff --git a/src/components/Header.astro b/src/components/Header.astro index af839bb..ee3241d 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,6 +1,7 @@ --- import { Image, Picture } from 'astro:assets' import * as m from '../paraglide/messages.js' +import prismaClient from 'utils/prisma-client.js' import logo from 'img/logos/winter.png' import logoEs from 'img/logos/default_es.png' @@ -10,12 +11,16 @@ import DropdownItem from './header/DropdownItem.astro' import Toggler from './header/Toggler.astro' import NavButton from './header/NavButton.astro' import LoginNav from './header/LoginNav.astro' -import prismaClient from 'utils/prisma-client.js' -import { Icon } from 'astro-icon/components' import SearchBar from './search/SearchBar.astro' -const { value: bannerId } = (await prismaClient.config.findUnique({ where: { name: 'banner' } })) ?? {} -const { value: bannerPosition } = (await prismaClient.config.findUnique({ where: { name: 'banner-position' } })) ?? {} +const [bannerConfig, bannerPositionConfig] = await Promise.all([ + prismaClient.config.findUnique({ where: { name: 'banner' }, select: { value: true } }), + prismaClient.config.findUnique({ where: { name: 'banner-position' }, select: { value: true } }) +]) + +const bannerId = bannerConfig?.value || '' +const bannerPosition = bannerPositionConfig?.value || 'top' + const { session } = Astro.locals --- @@ -53,18 +58,18 @@ const { session } = Astro.locals {m.games()} - {m.albums()} + {m.latestReleases()} + {m.gamelist()} {m.series()} {m.publishers()} {m.platforms()} - {m.gamelist()} {m.animation()} - {m.albums()} + {m.latestReleases()} {m.animationlist()} {m.studios()} diff --git a/src/layouts/PaginatedAlbumList.astro b/src/layouts/PaginatedAlbumList.astro new file mode 100644 index 0000000..34bc19b --- /dev/null +++ b/src/layouts/PaginatedAlbumList.astro @@ -0,0 +1,42 @@ +--- +interface Props { + albums: { title: string | null; id: number }[] + limitXS: number + limitMD: number + fullPageList: number[] + page: number +} + +import Base from './base.astro' +import AlbumBox from 'components/AlbumBox.astro' +import FooterNav from 'components/lastAdded/FooterNav.astro' + +const { albums, limitMD, limitXS, ...listProps } = Astro.props + +if (albums.length === 0) { + Astro.redirect('/404') +} +--- + + +
+
+
+

+ +

+
+ { + albums.map((album) => ( + + )) + } +
+
+
+ +
+ diff --git a/src/pages/anim/latest/[...page].astro b/src/pages/anim/latest/[...page].astro new file mode 100644 index 0000000..2c015a2 --- /dev/null +++ b/src/pages/anim/latest/[...page].astro @@ -0,0 +1,28 @@ +--- +import prismaClient from 'utils/prisma-client' +import * as m from 'paraglide/messages' +import { AlbumStatus } from '@prisma/client' + +import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro' + +const page = Math.min(1, parseInt(Astro.params.page ?? '1')) +const take = 40 +const limitMD = 12 +const limitXS = 5 + +const albums = await prismaClient.albums.findMany({ + where: { status: AlbumStatus.SHOW, categories: { some: { categoryName: 'Animation' } } }, + select: { id: true, title: true }, + take, + skip: take * (page - 1), + orderBy: [{ releaseDate: 'desc' }, { publishedAt: 'desc' }, { createdAt: 'desc' }] +}) +const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } }) + +const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1) +const listProps = { fullPageList, page, albums, limitMD, limitXS } +--- + + + {m.latestAnimReleases()} + diff --git a/src/pages/game/latest/[...page].astro b/src/pages/game/latest/[...page].astro new file mode 100644 index 0000000..63f9aae --- /dev/null +++ b/src/pages/game/latest/[...page].astro @@ -0,0 +1,28 @@ +--- +import prismaClient from 'utils/prisma-client' +import * as m from 'paraglide/messages' +import { AlbumStatus } from '@prisma/client' + +import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro' + +const page = Math.min(1, parseInt(Astro.params.page ?? '1')) +const take = 40 +const limitMD = 12 +const limitXS = 5 + +const albums = await prismaClient.albums.findMany({ + where: { status: AlbumStatus.SHOW, categories: { some: { categoryName: 'Game' } } }, + select: { id: true, title: true }, + take, + skip: take * (page - 1), + orderBy: [{ releaseDate: 'desc' }, { publishedAt: 'desc' }, { createdAt: 'desc' }] +}) +const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } }) + +const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1) +const listProps = { fullPageList, page, albums, limitMD, limitXS } +--- + + + {m.latestGameReleases()} + diff --git a/src/pages/last-added/[...page].astro b/src/pages/last-added/[...page].astro index 61c02da..959b44f 100644 --- a/src/pages/last-added/[...page].astro +++ b/src/pages/last-added/[...page].astro @@ -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 } --- - -
-
-

- {m.lastAdded()} -

-
- { - lastAlbums.map((album) => ( - - )) - } -
-
- -
-
+ + {m.lastAdded()} +