From 0ec019f959af2ea5ac0898aaba4be1ed6154aac7 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Sat, 15 Mar 2025 11:17:33 -0600 Subject: [PATCH] update --- astro.config.mjs | 3 +- .../migration.sql | 2 + prisma/schema.prisma | 2 + src/components/Header.astro | 8 ++- src/components/albumPage/TrackList.tsx | 6 +- src/components/header/NavButton.astro | 6 +- src/components/header/Toggler.astro | 12 +--- src/components/search/AlbumSearch.astro | 72 +++++++++++++++++++ src/components/search/SearchBar.astro | 52 ++++++++++++++ src/img/icons/close.svg | 13 ++++ src/img/icons/search.svg | 4 ++ src/pages/album/[id].astro | 34 ++++++--- src/pages/index.astro | 4 +- src/pages/last-added/[...page].astro | 2 +- src/pages/search.astro | 18 +++++ src/utils/form.ts | 5 ++ 16 files changed, 209 insertions(+), 34 deletions(-) create mode 100644 prisma/migrations/20250315153419_full_index_for_album_search/migration.sql create mode 100644 src/components/search/AlbumSearch.astro create mode 100644 src/components/search/SearchBar.astro create mode 100644 src/img/icons/close.svg create mode 100644 src/img/icons/search.svg create mode 100644 src/pages/search.astro diff --git a/astro.config.mjs b/astro.config.mjs index f36ecd5..eceea68 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -59,8 +59,7 @@ export default defineConfig({ '/studio/[slug]': { status: 307, destination: '/maintenance' }, '/studio/list': { status: 307, destination: '/maintenance' }, '/holy12': { status: 307, destination: '/maintenance' }, - '/request': { status: 307, destination: '/maintenance' }, - '/search': { status: 307, destination: '/maintenance' } + '/request': { status: 307, destination: '/maintenance' } }, security: { checkOrigin: false diff --git a/prisma/migrations/20250315153419_full_index_for_album_search/migration.sql b/prisma/migrations/20250315153419_full_index_for_album_search/migration.sql new file mode 100644 index 0000000..0104251 --- /dev/null +++ b/prisma/migrations/20250315153419_full_index_for_album_search/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE FULLTEXT INDEX `albums_title_subTitle_idx` ON `albums`(`title`, `subTitle`); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 53a7074..d6d1f7a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -153,6 +153,8 @@ model albums { relatedAlbums related_album[] @relation("related_album_albumIdToalbums") relatedTo related_album[] @relation("related_album_relatedIdToalbums") stores stores[] + + @@fulltext([title, subTitle]) } model animation { diff --git a/src/components/Header.astro b/src/components/Header.astro index f5bf8c5..af839bb 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -11,6 +11,8 @@ 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' } })) ?? {} @@ -42,7 +44,7 @@ const { session } = Astro.locals - + diff --git a/src/components/albumPage/TrackList.tsx b/src/components/albumPage/TrackList.tsx index 8376ae4..972c484 100644 --- a/src/components/albumPage/TrackList.tsx +++ b/src/components/albumPage/TrackList.tsx @@ -33,13 +33,13 @@ export default function TrackList(props: Props) {
-
+
{discs.length > 0 && discs[current].body?.split('\n').map((track, i) => ( - + ))} @@ -50,4 +50,4 @@ export default function TrackList(props: Props) { ) -} +} \ No newline at end of file diff --git a/src/components/header/NavButton.astro b/src/components/header/NavButton.astro index ede444c..f1b2b95 100644 --- a/src/components/header/NavButton.astro +++ b/src/components/header/NavButton.astro @@ -1,8 +1,5 @@ --- -import Button from '../Button' -import clsx from 'clsx' - -const { class: className } = Astro.props +const { class: className, ...rest } = Astro.props --- diff --git a/src/components/header/Toggler.astro b/src/components/header/Toggler.astro index 8c81a6a..fb5a1ce 100644 --- a/src/components/header/Toggler.astro +++ b/src/components/header/Toggler.astro @@ -2,17 +2,11 @@ import { Icon } from 'astro-icon/components' --- - +
- +
- @@ -102,18 +102,20 @@ const { currentLocale } = Astro { (album?.artists.length ?? 0) > 0 && (
- + ) } - + - + - + - + - + - +
{i + 1} {(i + 1).toString().padStart(2, '0')}. {track}
{m.artists()}{m.artists()} {album?.artists.map(({ artist }) => artist.name).join(', ')}
{m.classification()}{m.classification()} { [ - album?.categories.map(({ categoryName }) => (m as any)[`${categoryName}Osts`]()).join(' & '), + album?.categories + .map(({ categoryName }) => m[`${categoryName}Osts` as keyof typeof m]()) + .join(' & '), album?.classifications.map(({ classificationName }) => classificationName).join(', ') ] .filter((f) => f !== '') @@ -124,7 +126,7 @@ const { currentLocale } = Astro { album?.label && (
{m.publishedBy()}{m.publishedBy()} {album?.label} @@ -136,7 +138,7 @@ const { currentLocale } = Astro { (album?.platforms.length ?? 0) > 0 && (
{m.platforms()}{m.platforms()} {album?.platforms.map(({ platform }, i) => ( @@ -159,7 +161,7 @@ const { currentLocale } = Astro { (album?.games.length ?? 0) > 0 && (
{m.games()}{m.games()} {album?.games.map(({ game }, i) => ( @@ -176,7 +178,7 @@ const { currentLocale } = Astro { (album?.animations.length ?? 0) > 0 && (
{m.animations()}{m.animations()} {album?.animations.map(({ animation }, i) => ( @@ -192,13 +194,23 @@ const { currentLocale } = Astro }
{m.avgRating()}{m.avgRating()}
+ { + album?.vgmdb && ( +
+ {m.checkVGMDB()}: + + {'VGMdb'} + +
+ ) + }
diff --git a/src/pages/index.astro b/src/pages/index.astro index 3e31235..1d4eda7 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -27,7 +27,7 @@ const lastAlbums = await prismaClient.albums.findMany({

{m.recentReleases()}

-
+
{ recentAlbums.map((album) => ( @@ -42,7 +42,7 @@ const lastAlbums = await prismaClient.albums.findMany({

{m.lastAdded()}

-
+
{ lastAlbums.map((album) => ( diff --git a/src/pages/last-added/[...page].astro b/src/pages/last-added/[...page].astro index 7a1ac55..61c02da 100644 --- a/src/pages/last-added/[...page].astro +++ b/src/pages/last-added/[...page].astro @@ -39,7 +39,7 @@ const listProps = { fullPageList, page }

{m.lastAdded()}

-
+
{ lastAlbums.map((album) => ( diff --git a/src/pages/search.astro b/src/pages/search.astro new file mode 100644 index 0000000..f90c507 --- /dev/null +++ b/src/pages/search.astro @@ -0,0 +1,18 @@ +--- +import AlbumSearch from 'components/search/AlbumSearch.astro' +import BaseLayout from 'layouts/base.astro' + +const query = Astro.url.searchParams.get('q') +if (!query) return Astro.redirect(404) +--- + + +
+
+
Search results for: {query}
+
+ +
+
+
+
diff --git a/src/utils/form.ts b/src/utils/form.ts index bf8042f..2ae18b4 100644 --- a/src/utils/form.ts +++ b/src/utils/form.ts @@ -21,3 +21,8 @@ export async function parseForm(request: Request) { const data = JSON.parse(dataInput) return { ...data, ...rest } } + +export function getRandom(array: T[]): T { + const randomIndex = Math.floor(Math.random() * array.length) + return array[randomIndex] +}