fix(search): remove highlight page and make search links open the comic's source url
This commit is contained in:
parent
b52fae835e
commit
a33ea9af5f
2 changed files with 1 additions and 91 deletions
|
@ -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,
|
||||
},
|
||||
};
|
||||
};
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue