1 /* eslint-disable @typescript-eslint/ban-ts-comment */
2 import React from "react"
3 import AreaProvider from "@/providers/area"
4 import StoreContent from "@/markdown/store.mdx"
5 import AdminContent from "@/markdown/admin.mdx"
6 import Tags from "@/components/Tags"
7 import PageTitleProvider from "@/providers/page-title"
8 import { getBaseSpecs } from "../../../lib"
9 import BaseSpecsProvider from "../../../providers/base-specs"
10 import ScrollToSection from "@/components/ScrollToSection"
11 import { notFound } from "next/navigation"
12 import { getIntroSection, getTagBySlug, isArea } from "@/utils/area"
13
14 export const dynamic = "force-dynamic"
15
16 type SectionLayoutProps = {
17 children: React.ReactNode
18 params: Promise<{ area: string; section: string }>
19 }
20
21 /**
22 * Renders the section content (an intro section or a tag with all its
23 * operations) as a layout so that navigating between a tag and its operation
24 * pages only swaps the (empty) page segment — the tag content stays mounted and
25 * the browser just scrolls, instead of reloading the whole tag.
26 */
27 const SectionLayout = async ({ children, params }: SectionLayoutProps) => {
28 const { area, section } = await params
29 if (!isArea(area)) {
30 notFound()
31 }
32
33 const data = await getBaseSpecs(area)
34 const introSection = getIntroSection(area, section)
35 const tag = introSection ? undefined : getTagBySlug(data, section)
36
37 if (!introSection && !tag) {
38 notFound()
39 }
40
41 const Content = area === "store" ? StoreContent : AdminContent
42
43 return (
44 <BaseSpecsProvider baseSpecs={data}>
45 <AreaProvider area={area}>
46 <PageTitleProvider>
47 {introSection ? (
48 <>
49 <ScrollToSection slug={introSection.slug} />
50 {/* @ts-ignore React v19 doesn't see MDX as valid component */}
51 <Content />
52 </>
53 ) : (
54 <Tags tags={tag ? [tag] : []} />
55 )}
56 {children}
57 </PageTitleProvider>
58 </AreaProvider>
59 </BaseSpecsProvider>
60 )
61 }
62
63 export default SectionLayout