fix(dynozavry): fetch heroBackground from locations collection
heroBgUrl was never populated — page.tsx queried only the dinosaur-page global and didn't read the Location's heroBackground upload field. Now fetches the locations collection in parallel and passes heroBgUrl to DinoPageContent, which already handles the conditional hero-bg render. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4b064eee65
commit
00c3548272
1 changed files with 15 additions and 2 deletions
|
|
@ -3,7 +3,7 @@ import { getPayload } from 'payload'
|
|||
import configPromise from '@payload-config'
|
||||
import { DinoPageContent } from '@/components/sections/DinoPageContent'
|
||||
import { RefreshRouteOnSave } from '@/components/cms/RefreshRouteOnSave'
|
||||
import type { Media } from '@/payload-types'
|
||||
import type { Media, Location } from '@/payload-types'
|
||||
|
||||
export const revalidate = 60
|
||||
|
||||
|
|
@ -63,10 +63,22 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||
|
||||
export default async function DinosaurPage() {
|
||||
let data: DinoPageData = {}
|
||||
let heroBgUrl: string | null = null
|
||||
try {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
const raw = await payload.findGlobal({ slug: 'dinosaur-page' as never, overrideAccess: true })
|
||||
const [raw, locationResult] = await Promise.all([
|
||||
payload.findGlobal({ slug: 'dinosaur-page' as never, overrideAccess: true }),
|
||||
payload.find({
|
||||
collection: 'locations',
|
||||
where: { slug: { equals: 'dynozavry' } },
|
||||
limit: 1,
|
||||
depth: 1,
|
||||
}),
|
||||
])
|
||||
data = raw as unknown as DinoPageData
|
||||
const loc = locationResult.docs[0] as Location | undefined
|
||||
const bg = loc?.heroBackground
|
||||
if (bg && typeof bg !== 'number') heroBgUrl = (bg as Media).url ?? null
|
||||
} catch {
|
||||
// DB unavailable at build time — render with fallbacks; ISR will hydrate at runtime
|
||||
}
|
||||
|
|
@ -114,6 +126,7 @@ export default async function DinosaurPage() {
|
|||
statLabel={data.heroStatLabel}
|
||||
features={features && features.length > 0 ? features : undefined}
|
||||
heroImageUrl={mediaUrl(data.heroImage)}
|
||||
heroBgUrl={heroBgUrl}
|
||||
dinos={dinos && dinos.length >= 12 ? dinos : undefined}
|
||||
galleryImages={galleryImages && galleryImages.length >= 4 ? galleryImages : undefined}
|
||||
activitiesTitle={data.activitiesTitle}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue