menu moved to const
This commit is contained in:
1 parent
ccca4237ac
commit
3172e9c91e
9 files changed
+30
-69
No files matched your search
@@ -3,7 +3,7 @@ import { notFound } from "next/navigation"
|
|||||||
import { App } from "@/components/App"
|
import { App } from "@/components/App"
|
||||||
import { PageContent } from "@/components/PageContent"
|
import { PageContent } from "@/components/PageContent"
|
||||||
import { MetaBuilder, buildMetadata } from "@/lib/meta"
|
import { MetaBuilder, buildMetadata } from "@/lib/meta"
|
||||||
import { getMenu, getPageBySlug, getUrls } from "@/remote/api"
|
import { getPageBySlug, getUrls } from "@/remote/api"
|
||||||
import { tail } from "@/lib/array"
|
import { tail } from "@/lib/array"
|
||||||
|
|
||||||
export const revalidate = 30
|
export const revalidate = 30
|
||||||
|
|||||||
+1
-7
@@ -7,9 +7,7 @@ import "src/style/kazimir/video.css"
|
|||||||
import type { Metadata, Viewport } from "next"
|
import type { Metadata, Viewport } from "next"
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
import { Roboto } from "next/font/google"
|
import { Roboto } from "next/font/google"
|
||||||
import { Providers } from "@/components/Providers"
|
|
||||||
import { YMetrika } from "@/components/YMetrika"
|
import { YMetrika } from "@/components/YMetrika"
|
||||||
import { getMenu } from "@/remote/api"
|
|
||||||
|
|
||||||
const roboto = Roboto({
|
const roboto = Roboto({
|
||||||
weight: ["300", "900"],
|
weight: ["300", "900"],
|
||||||
@@ -61,8 +59,6 @@ export const viewport: Viewport = {
|
|||||||
export const revalidate = 30
|
export const revalidate = 30
|
||||||
|
|
||||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||||
const menu = await getMenu()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="ru" className={roboto.className}>
|
<html lang="ru" className={roboto.className}>
|
||||||
<head>
|
<head>
|
||||||
@@ -71,9 +67,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
|||||||
)}
|
)}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<Providers menu={menu}>
|
{children}
|
||||||
{children}
|
|
||||||
</Providers>
|
|
||||||
<Script src="https://culturaltracking.ru/static/js/spxl.js?pixelId=27154" data-pixel-id="27154" />
|
<Script src="https://culturaltracking.ru/static/js/spxl.js?pixelId=27154" data-pixel-id="27154" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
import s from "./app.module.css"
|
import s from "./app.module.css"
|
||||||
|
|
||||||
import { useContext } from "react"
|
|
||||||
import { Wrapper } from "../Wrapper"
|
import { Wrapper } from "../Wrapper"
|
||||||
import { MenuContext } from "@/context/MenuContext"
|
|
||||||
import { Footer } from "../Footer"
|
import { Footer } from "../Footer"
|
||||||
import { Content } from "../Content"
|
import { Content } from "../Content"
|
||||||
import { Breadcrumbs } from "../Breadcrumbs"
|
import { Breadcrumbs } from "../Breadcrumbs"
|
||||||
@@ -42,7 +40,6 @@ export function App({ showAuthor = false, ...props }: AppProps) {
|
|||||||
const hideBreadcrumbs = useMobile()
|
const hideBreadcrumbs = useMobile()
|
||||||
const accessibility = useAccessibility()
|
const accessibility = useAccessibility()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const menu = useContext(MenuContext)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { Menu } from "../Menu"
|
import { Menu } from "../Menu"
|
||||||
import { useContext } from "react"
|
|
||||||
import { MenuContext } from "@/context/MenuContext"
|
|
||||||
import { Box } from "@/ui/Box"
|
import { Box } from "@/ui/Box"
|
||||||
import HudozkaLogo from "../HudozkaLogo"
|
import HudozkaLogo from "../HudozkaLogo"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { AccessibilityButton } from "../AccessibilityButton"
|
import { AccessibilityButton } from "../AccessibilityButton"
|
||||||
import { Spacer } from "../Spacer"
|
import { Spacer } from "../Spacer"
|
||||||
|
import { menu } from "@/const"
|
||||||
|
|
||||||
export type DesktopNavigationProps = {
|
export type DesktopNavigationProps = {
|
||||||
className?: string
|
className?: string
|
||||||
@@ -13,8 +12,6 @@ export type DesktopNavigationProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DesktopNavigation({ style, className }: DesktopNavigationProps) {
|
export function DesktopNavigation({ style, className }: DesktopNavigationProps) {
|
||||||
const menu = useContext(MenuContext)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box wrap className={className} gap={"var(--size-s)"} style={style}>
|
<Box wrap className={className} gap={"var(--size-s)"} style={style}>
|
||||||
<Link href="/">
|
<Link href="/">
|
||||||
@@ -30,4 +27,3 @@ export function DesktopNavigation({ style, className }: DesktopNavigationProps)
|
|||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,8 +3,7 @@
|
|||||||
import s from "./nav.module.css"
|
import s from "./nav.module.css"
|
||||||
|
|
||||||
import { Menu } from "../Menu"
|
import { Menu } from "../Menu"
|
||||||
import { useCallback, useContext, useEffect, useRef } from "react"
|
import { useCallback, useEffect, useRef } from "react"
|
||||||
import { MenuContext } from "@/context/MenuContext"
|
|
||||||
import { Box } from "@/ui/Box"
|
import { Box } from "@/ui/Box"
|
||||||
import { Spacer } from "../Spacer"
|
import { Spacer } from "../Spacer"
|
||||||
import HudozkaLogo from "../HudozkaLogo"
|
import HudozkaLogo from "../HudozkaLogo"
|
||||||
@@ -12,6 +11,7 @@ import { HudozkaTitle } from "../HudozkaTitle"
|
|||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { HiOutlineMenuAlt4, HiOutlineX } from "react-icons/hi"
|
import { HiOutlineMenuAlt4, HiOutlineX } from "react-icons/hi"
|
||||||
|
import { menu } from "@/const"
|
||||||
|
|
||||||
export type MobileNavigationProps = {
|
export type MobileNavigationProps = {
|
||||||
className?: string
|
className?: string
|
||||||
@@ -19,7 +19,6 @@ export type MobileNavigationProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function MobileNavigation({ className, style }: MobileNavigationProps) {
|
export function MobileNavigation({ className, style }: MobileNavigationProps) {
|
||||||
const menu = useContext(MenuContext)
|
|
||||||
const detailsRef = useRef<HTMLDetailsElement>(null)
|
const detailsRef = useRef<HTMLDetailsElement>(null)
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { MenuContext } from "@/context/MenuContext"
|
|
||||||
import type { MenuItem } from "@/types"
|
|
||||||
|
|
||||||
export type ProvidersProps = {
|
|
||||||
menu: MenuItem[]
|
|
||||||
children: React.ReactNode
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Providers({ menu, children }: ProvidersProps) {
|
|
||||||
return (
|
|
||||||
<MenuContext.Provider value={menu}>
|
|
||||||
{children}
|
|
||||||
</MenuContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,2 +1,27 @@
|
|||||||
|
import type { MenuItem } from "./types"
|
||||||
|
|
||||||
export const yearRange = [2012, 2026].join("—")
|
export const yearRange = [2012, 2026].join("—")
|
||||||
export const siteUrl = "https://art.shlisselburg.org"
|
export const siteUrl = "https://art.shlisselburg.org"
|
||||||
|
|
||||||
|
export const menu: MenuItem[] = [
|
||||||
|
{
|
||||||
|
name: "Школа",
|
||||||
|
href: "/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Предметы",
|
||||||
|
href: "/cources",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Коллектив",
|
||||||
|
href: "/collective",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Документы",
|
||||||
|
href: "/documents",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Сведения об образовательной организации",
|
||||||
|
href: "/info",
|
||||||
|
},
|
||||||
|
]
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { createContext } from "react"
|
|
||||||
|
|
||||||
export const menu = [
|
|
||||||
{
|
|
||||||
name: "Школа",
|
|
||||||
href: "/",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export const MenuContext = createContext(menu)
|
|
||||||
@@ -142,29 +142,6 @@ export async function getHomeCards(): Promise<PageCardDto[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMenu(): Promise<MenuItem[]> {
|
|
||||||
try {
|
|
||||||
const kv = await pb.collection("kv").getFirstListItem<{ data: PbMenuData }>(
|
|
||||||
"key=\"menu\"",
|
|
||||||
)
|
|
||||||
const data = kv.data
|
|
||||||
if (!data.items || data.items.length === 0) {
|
|
||||||
return [{
|
|
||||||
href: "/",
|
|
||||||
name: data.homeLabel,
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
const pageIds = data.items.map(i => i.page)
|
|
||||||
const pages = await fetchPagesByIds(pageIds)
|
|
||||||
|
|
||||||
return createMenu(data, pages)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Failed to fetch menu: ${error}`)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getRecentPages(limit: number = 30): Promise<FeedPage[]> {
|
export async function getRecentPages(limit: number = 30): Promise<FeedPage[]> {
|
||||||
try {
|
try {
|
||||||
const result = await pb.collection("pages").getList<PbPage>(1, limit, {
|
const result = await pb.collection("pages").getList<PbPage>(1, limit, {
|
||||||
|
|||||||
Reference in new issue
Block a user