diff --git a/lib/contentful/search.ts b/lib/contentful/search.ts index 56ce267..ec4b0bb 100644 --- a/lib/contentful/search.ts +++ b/lib/contentful/search.ts @@ -4,14 +4,14 @@ import type { TypeArticleFields, TypeArtist, TypeArtistFields, - TypeShow, TypeShowFields, } from "../../types/contentful"; import { client } from "./client"; import { previewClient } from "./client"; import { s } from "@fullcalendar/core/internal-common"; +import { PastShowSchema } from "../../types/shared"; export interface SearchData { - shows: TypeShow[]; + shows: PastShowSchema[]; articles: TypeArticle[]; artists: TypeArtist[]; } @@ -36,12 +36,14 @@ export async function getSearchData( query: query, select: [ + "sys.id", "fields.title", "fields.slug", "fields.date", "fields.artists", "fields.genres", "fields.coverImage", + "fields.mixcloudLink", ], }), client.getEntries({ @@ -74,9 +76,9 @@ export async function getSearchData( const end = Date.now(); - const { items: shows } = showsCollection; - const { items: articles } = articlesCollection; - const { items: artists } = artistsCollection; + const shows = showsCollection.items.map(parseShowToPastShowSchema); + const articles = articlesCollection.items; + const artists = artistsCollection.items; return { data: { shows, articles, artists } as SearchData, @@ -163,3 +165,18 @@ export async function getArtistSearchData( duration: end - start, }; } + +// TODO: move to shared function alongside shows page. +function parseShowToPastShowSchema(show): PastShowSchema { + return { + date: show.fields?.date, + id: show.sys?.id, + title: show.fields?.title, + slug: show.fields?.slug, + coverImage: show.fields?.coverImage?.fields.file.url, + mixcloudLink: show.fields?.mixcloudLink, + genres: show.fields.genres + .map((genre) => genre.fields?.name) + .filter(Boolean), + }; +} diff --git a/pages/search.tsx b/pages/search.tsx index 0a7540f..3df5575 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -6,7 +6,7 @@ import ArtistPreview from "../components/artistPreview"; import Layout from "../components/layout"; import Pill from "../components/pill"; import PageMeta from "../components/seo/page"; -import { ShowPreviewWithoutPlayer } from "../components/showPreview"; +import ShowPreview from "../components/showPreview"; import useSearchData from "../hooks/useSearch"; import { getSearchData } from "../lib/contentful/search"; import { useRouter } from "next/router"; @@ -130,8 +130,8 @@ export default function SearchPage({