fix: add loading state when no uri is given
This commit is contained in:
9
app/[lang]/(preview)/error.tsx
Normal file
9
app/[lang]/(preview)/error.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
"use client"
|
||||
|
||||
export default function Error({ error }: { error: Error }) {
|
||||
return (
|
||||
<div>
|
||||
<h2>Something went wrong!</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,35 +1,32 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { previewRequest } from "@/lib/previewRequest";
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql";
|
||||
import { previewRequest } from "@/lib/previewRequest"
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||
|
||||
import Aside from "@/components/Current/Aside";
|
||||
import Blocks from "@/components/Current/Blocks";
|
||||
import Header from "@/components/Current/Header";
|
||||
import Hero from "@/components/Current/Hero";
|
||||
import Aside from "@/components/Current/Aside"
|
||||
import Blocks from "@/components/Current/Blocks"
|
||||
import Header from "@/components/Current/Header"
|
||||
import Hero from "@/components/Current/Hero"
|
||||
|
||||
import type { PageArgs, LangParams, UriParams } from "@/types/params";
|
||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage";
|
||||
import ContentstackLivePreview from "@contentstack/live-preview-utils";
|
||||
import type { PageArgs, LangParams, UriParams } from "@/types/params"
|
||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
|
||||
import ContentstackLivePreview from "@contentstack/live-preview-utils"
|
||||
import LoadingPreview from "@/components/Current/LoadingPreview"
|
||||
|
||||
export default async function CurrentContentPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageArgs<LangParams, UriParams>) {
|
||||
try {
|
||||
const livePreviewHash = searchParams["live_preview"]
|
||||
if (!livePreviewHash) {
|
||||
throw new Error("No hash found")
|
||||
}
|
||||
ContentstackLivePreview.setConfigFromParams(searchParams)
|
||||
|
||||
if (!searchParams.uri) {
|
||||
throw new Error("Bad URI")
|
||||
return <LoadingPreview />
|
||||
}
|
||||
|
||||
const response = await previewRequest<GetCurrentBlockPageData>(
|
||||
GetCurrentBlockPage,
|
||||
{ locale: params.lang, url: searchParams.uri }
|
||||
{ locale: params.lang, uid: searchParams.uri }
|
||||
)
|
||||
|
||||
if (!response.data?.all_current_blocks_page?.total) {
|
||||
@@ -53,8 +50,9 @@ export default async function CurrentContentPage({
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return notFound();
|
||||
} catch (error) {
|
||||
// TODO: throw 500
|
||||
console.error(error)
|
||||
throw new Error("Something went wrong")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user