diff --git a/messages/en.json b/messages/en.json index 834e20b..38d19b1 100644 --- a/messages/en.json +++ b/messages/en.json @@ -87,8 +87,5 @@ "latestReleases": "Latest releases", "firstRelease": "First Release", "newestRelease": "Newest Release", - "variousGames": "Various Games", - "searchResultsFor": "Search results for", - "firstResults": "Showing first {take} results", - "moreResults": "Showing {start}-{end} results" + "variousGames": "Various Games" } diff --git a/src/components/search/AlbumSearch.astro b/src/components/search/AlbumSearch.astro index c01cc1c..c2dc899 100644 --- a/src/components/search/AlbumSearch.astro +++ b/src/components/search/AlbumSearch.astro @@ -1,11 +1,9 @@ --- -import * as m from 'paraglide/messages' import type { Prisma } from '@prisma/client' import type { DefaultArgs } from '@prisma/client/runtime/library' import { Image } from 'astro:assets' import prismaClient from 'utils/prisma-client' -import SearchNav from './SearchNav.astro' interface Props { query: string @@ -19,17 +17,17 @@ let { page } = Astro.props if (page < 1) page = 1 const queryString = query - .trim() - .split(/[\s_\-:]+/) + .toLowerCase() + .split('_') + .map((w) => `+${w}`) .join(' ') - const findQuery: Prisma.albumsFindManyArgs = { select: { title: true, releaseDate: true, id: true }, where: { OR: [{ title: { search: queryString } }, { subTitle: { search: queryString } }] }, orderBy: { - _relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: queryString } + _relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: query.toLowerCase() } } } const countQuery: Prisma.albumsCountArgs = { @@ -40,18 +38,26 @@ const [count, search] = await Promise.all([ prismaClient.albums.count(countQuery), prismaClient.albums.findMany({ ...findQuery, take, skip: (page - 1) * take }) ]) - -const start = (page - 1) * take -const end = Math.min(page * take, count) --- -
- {m.albums()} ({count}) { - count > take ? / {page === 1 ? m.firstResults({ take }) : m.moreResults({ start, end })} : null - } -
-
- +
+
+ Albums ({count}) { + count > take ? ( + + {' '} + / Showing {page === 1 ? `first ${take}` : `${(page - 1) * take}-${Math.min(page * take, count)}`} results + + ) : null + } +
+
+ { + Array.from({ length: Math.ceil(count / take) }, (_, i) => + page === i + 1 ? {i + 1} : {i + 1} + ) + } +
{ @@ -69,13 +75,9 @@ const end = Math.min(page * take, count)
-
{album.releaseDate?.toISOString().split('T')[0]}
+
{album.releaseDate?.toISOString().split('T')[0]}
)) }
- -
- -
diff --git a/src/components/search/SearchBar.astro b/src/components/search/SearchBar.astro index b5e48bd..19cf271 100644 --- a/src/components/search/SearchBar.astro +++ b/src/components/search/SearchBar.astro @@ -44,12 +44,8 @@ const placeholder = getRandom(placeholders) searchForm?.addEventListener('submit', (ev: Event) => { ev.preventDefault() const formData = new FormData(searchForm) - const query = (formData.get('query') as string).trim() - - if (!query || query.length < 1) return - const url = new URL('/search', window.location.origin) - url.searchParams.append('q', query) + url.searchParams.append('q', formData.get('query') as string) window.location.href = url.toString() }) diff --git a/src/components/search/SearchNav.astro b/src/components/search/SearchNav.astro deleted file mode 100644 index 7b9fa2a..0000000 --- a/src/components/search/SearchNav.astro +++ /dev/null @@ -1,25 +0,0 @@ ---- -interface Props { - count: number - take: number - page: number - query: string -} - -const { count, take, page, query } = Astro.props -const pageCount = Math.ceil(count / take) ---- - -{ - pageCount > 1 - ? Array.from({ length: pageCount }, (_, i) => - page === i + 1 ? ( - {i + 1} - ) : ( - - {i + 1} - - ) - ) - : null -} diff --git a/src/pages/search.astro b/src/pages/search.astro index 841124c..42c9de2 100644 --- a/src/pages/search.astro +++ b/src/pages/search.astro @@ -1,20 +1,18 @@ --- -import * as m from 'paraglide/messages' - import AlbumSearch from 'components/search/AlbumSearch.astro' import BaseLayout from 'layouts/base.astro' -const query = (Astro.url.searchParams.get('q') ?? '').trim() -const page = Astro.url.searchParams.get('page') || '1' +const query = Astro.url.searchParams.get('q') +const page = Astro.url.searchParams.get('page') || "1" -if (!query || query.length < 1) return Astro.redirect(404) +if (!query) return Astro.redirect(404) ---
-
{m.searchResultsFor()}: {query}
-
+
Search results for: {query}
+