-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4364937
commit 8e5893a
Showing
16 changed files
with
5,077 additions
and
629 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { notFound } from "next/navigation"; | ||
|
||
import { Show, type Props as ShowProps } from "@/components/book/Show"; | ||
import { Book } from "@/types/Book"; | ||
import { type FetchResponse, fetch } from "@/utils/dataAccess"; | ||
|
||
interface Query { | ||
id: number; | ||
page?: number|undefined; | ||
} | ||
|
||
async function getServerSideProps({ id, page = 1 }: Query): Promise<ShowProps|undefined> { | ||
try { | ||
const response: FetchResponse<Book> | undefined = await fetch(`/books/${id}`, { | ||
headers: { | ||
Preload: "/books/*/reviews", | ||
} | ||
}); | ||
if (!response?.data) { | ||
throw new Error(`Unable to retrieve data from /books/${id}.`); | ||
} | ||
|
||
return { data: response.data, hubURL: response.hubURL, page: Number(page ?? 1) }; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export default async function Page({ searchParams }: { searchParams: Query }) { | ||
const props = await getServerSideProps(searchParams); | ||
if (!props) { | ||
notFound(); | ||
} | ||
|
||
return <Show {...props}/>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.