fix(search): remove highlight page and make search links open the comic's source url

This commit is contained in:
Ashhhleyyy 2022-08-01 17:40:05 +01:00
parent b52fae835e
commit a33ea9af5f
Signed by: ash
GPG key ID: 83B789081A0878FB
2 changed files with 1 additions and 91 deletions

View file

@ -1,76 +0,0 @@
import { Comic, ComicBubble, ComicPage } from '@prisma/client';
import { GetServerSideProps } from 'next';
import Head from 'next/head';
import { ParsedUrlQuery } from 'querystring';
import HighlightComic from '../../../../components/HighlightComic';
import { prisma } from '../../../../src/db';
interface Params extends ParsedUrlQuery {
comic: string;
page: string;
}
interface Props {
page: ComicPage & {
bubbles: ComicBubble[];
comic: Comic;
};
highlightedBubbles: number[] | null;
}
export default function Search(props: Props) {
return (
<main className='p-4'>
<Head>
<title>
{props.page.title} - {props.page.comic.title}
</title>
</Head>
<HighlightComic
page={props.page}
highlightedBubbles={props.highlightedBubbles}
/>
</main>
);
}
export const getServerSideProps: GetServerSideProps<Props, Params> = async ({
params,
query,
}) => {
const { comic: comicId, page: id } = params!;
const pageId = parseInt(id);
if (isNaN(pageId)) return { notFound: true };
const page = await prisma?.comicPage.findFirst({
where: {
comic: {
slug: comicId,
},
id: pageId,
},
include: {
bubbles: true,
comic: true,
},
});
if (!page) return { notFound: true };
const highlightedBubbles = (
Array.isArray(query.highlightedBubbles)
? query.highlightedBubbles
: query.highlightedBubbles
? [query.highlightedBubbles]
: undefined
)
?.map((bubble) => parseInt(bubble))
?.filter((bubble) => !isNaN(bubble));
return {
props: {
page,
highlightedBubbles: highlightedBubbles ?? null,
},
};
};

View file

@ -101,21 +101,7 @@ export default function Search(props: Props) {
<div>
<h2>
<LinkButton
href={{
pathname: `/comic/${
props.comic.slug
}/highlight/${
result.id.split(
'-'
)[1]
}`,
query: {
highlightedBubbles:
findHighlighedBubbles(
result
),
},
}}
href={result.url}
target='_blank'
onClick={(e) => {
e.preventDefault();