Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add search page #73

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
26 changes: 11 additions & 15 deletions src/app/(main)/(secondary)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@ export default async function Page({ searchParams }: { searchParams: SearchParam
data = { ...response, Songs: !response.Songs ? [] : response.Songs };
}

if (searchParams.artistUuid && searchParams.songUuid) {
const [artistResponse, versionsRespose] = await Promise.all([
fetch(`${API_DOMAIN}/api/v3/artists/${searchParams.artistUuid}`, { cache: 'no-cache' }),
fetch(
`${API_DOMAIN}/api/v3/artists/${searchParams.artistUuid}/songs/${searchParams.songUuid}`,
{ cache: 'no-cache' }
),
]);
if (data?.Songs.length && searchParams.songUuid) {
const song = data.Songs.find(({ uuid }) => uuid === searchParams.songUuid);

const [artistJson, versionsJson] = await Promise.all([
artistResponse.json(),
versionsRespose.json(),
]);
let versions = await fetch(
`${API_DOMAIN}/api/v3/artists/${song?.slim_artist?.uuid}/songs/${searchParams.songUuid}`,
{ cache: 'no-cache' }
);

versions = await versions.json();
nth-chile marked this conversation as resolved.
Show resolved Hide resolved

resultsType = 'versions';

versionsData = {
...versionsJson,
artistName: artistJson.name,
artistSlug: artistJson.slug,
...versions,
artistName: song?.slim_artist?.name || '',
artistSlug: song?.slim_artist?.slug || '',
};
}

Expand Down
1 change: 0 additions & 1 deletion src/components/search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function SearchBar({ resultsType }: { resultsType: SearchResultsT
}

function clearSearch() {
writableParams.delete('artistUuid');
writableParams.delete('q');
writableParams.delete('resultsType');
writableParams.delete('songUuid');
Expand Down
16 changes: 2 additions & 14 deletions src/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ import Link from 'next/link';
import { sortByKey } from '@/lib/utils';
import Column from '../Column';
import Row from '../Row';

// "1984-12-01T00:00:00Z" -> "1984/12/01"
function dateStringToPathSegment(inputDateStr) {
const originalDate = new Date(inputDateStr);
const yyyy = originalDate.getUTCFullYear();
const mm = String(originalDate.getUTCMonth() + 1).padStart(2, '0');
const dd = String(originalDate.getUTCDate()).padStart(2, '0');

return `${yyyy}/${mm}/${dd}`;
}
import { formatInTimeZone } from 'date-fns-tz';

export default function SearchResults({
data,
Expand Down Expand Up @@ -71,7 +62,6 @@ export default function SearchResults({
return 'search';
}

writableParams.set('artistUuid', slim_artist.uuid);
writableParams.set('songUuid', songUuid);

return `search?${writableParams.toString()}`;
Expand Down Expand Up @@ -157,9 +147,7 @@ export default function SearchResults({
return (
<Row
key={uuid}
href={`/${sortedVersions?.artistSlug}/${dateStringToPathSegment(
date
)}/${sortedVersions?.slug}`}
href={`/${sortedVersions?.artistSlug}/${formatInTimeZone(date as string, 'UTC', 'yyyy/MM/dd')}/${sortedVersions?.slug}`}
>
<div>
<div>{sortedVersions?.name}</div>
Expand Down