diff --git a/src/components/search/AlbumSearch.astro b/src/components/search/AlbumSearch.astro index c2dc899..1fc3f11 100644 --- a/src/components/search/AlbumSearch.astro +++ b/src/components/search/AlbumSearch.astro @@ -4,6 +4,7 @@ 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 @@ -40,24 +41,18 @@ const [count, search] = await Promise.all([ ]) --- -
-
- 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} - ) - } -
+
+ Albums ({count}) { + count > take ? ( + + {' '} + / Showing {page === 1 ? `first ${take}` : `${(page - 1) * take}-${Math.min(page * take, count)}`} results + + ) : null + } +
+
+
{ @@ -75,9 +70,14 @@ const [count, search] = await Promise.all([
-
{album.releaseDate?.toISOString().split('T')[0]}
+
{album.releaseDate?.toISOString().split('T')[0]}
)) }
+
+
+ +
+
diff --git a/src/components/search/SearchNav.astro b/src/components/search/SearchNav.astro new file mode 100644 index 0000000..439e5c3 --- /dev/null +++ b/src/components/search/SearchNav.astro @@ -0,0 +1,25 @@ +--- +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 42c9de2..0e81959 100644 --- a/src/pages/search.astro +++ b/src/pages/search.astro @@ -3,7 +3,7 @@ import AlbumSearch from 'components/search/AlbumSearch.astro' import BaseLayout from 'layouts/base.astro' const query = Astro.url.searchParams.get('q') -const page = Astro.url.searchParams.get('page') || "1" +const page = Astro.url.searchParams.get('page') || '1' if (!query) return Astro.redirect(404) --- @@ -12,7 +12,7 @@ if (!query) return Astro.redirect(404)
Search results for: {query}
-
+