rename config context to menu context; move config to state
This commit is contained in:
1 parent
20c59affd7
commit
945947aa22
8 files changed
+45
-36
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
import { Wrapper } from "../Wrapper"
|
import { Wrapper } from "../Wrapper"
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
import { MenuContext } from "@/context/MenuContext"
|
||||||
import config from "src/config"
|
|
||||||
import { Footer } from "../Footer"
|
import { Footer } from "../Footer"
|
||||||
import { Content } from "../Content"
|
import { Content } from "../Content"
|
||||||
import { Breadcrumbs } from "../Breadcrumbs"
|
import { Breadcrumbs } from "../Breadcrumbs"
|
||||||
@@ -10,7 +9,7 @@ import { useMobile } from "src/hooks/useMobile"
|
|||||||
import { Navigation } from "@/components/Navigation"
|
import { Navigation } from "@/components/Navigation"
|
||||||
import { Box } from "@/ui/Box"
|
import { Box } from "@/ui/Box"
|
||||||
import { AccessibilityButton } from "../AccessibilityButton"
|
import { AccessibilityButton } from "../AccessibilityButton"
|
||||||
import { Copyright } from "../Copyright"
|
import Copyright from "@/components/Copyright"
|
||||||
import { Spacer } from "../Spacer"
|
import { Spacer } from "../Spacer"
|
||||||
import { Author } from "../Author"
|
import { Author } from "../Author"
|
||||||
import { Title } from "@/ui/Title"
|
import { Title } from "@/ui/Title"
|
||||||
@@ -45,10 +44,7 @@ export const App: React.FC<AppProps> = ({ showAuthor = false, menu, ...props })
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigContext.Provider value={{
|
<MenuContext.Provider value={menu}>
|
||||||
...config,
|
|
||||||
menu,
|
|
||||||
}}>
|
|
||||||
<Wrapper
|
<Wrapper
|
||||||
header={(
|
header={(
|
||||||
<header>
|
<header>
|
||||||
@@ -157,6 +153,6 @@ export const App: React.FC<AppProps> = ({ showAuthor = false, menu, ...props })
|
|||||||
</Content>
|
</Content>
|
||||||
</Box>
|
</Box>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
</ConfigContext.Provider>
|
</MenuContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import s from "./contacts.module.css"
|
import s from "./contacts.module.css"
|
||||||
|
|
||||||
import { useContext } from "react"
|
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { Title } from "@/ui/Title"
|
import { Title } from "@/ui/Title"
|
||||||
|
import { useSnapshot } from "valtio"
|
||||||
|
import { state } from "@/store/config"
|
||||||
|
|
||||||
export const Contacts: React.FC = props => {
|
export const Contacts: React.FC = props => {
|
||||||
const { contacts } = useContext(ConfigContext)
|
const { contacts } = useSnapshot(state)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { useContext } from "react"
|
import { state } from "@/store/config"
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
import { useSnapshot } from "valtio"
|
||||||
|
|
||||||
export const Copyright: React.FC = () => {
|
function Copyright() {
|
||||||
const { yearStart, yearEnd } = useContext(ConfigContext)
|
const { years } = useSnapshot(state)
|
||||||
|
const year = years.map(String).join("—")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span>© {yearStart}—{yearEnd} Шлиссельбургская детская художественная школа</span>
|
<span>© {year} Шлиссельбургская детская художественная школа</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Copyright
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Menu } from "../Menu"
|
import { Menu } from "../Menu"
|
||||||
import { useContext } from "react"
|
import { useContext } from "react"
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
import { MenuContext } from "@/context/MenuContext"
|
||||||
import { Box } from "@/ui/Box"
|
import { Box } from "@/ui/Box"
|
||||||
import { HudozkaLogo } from "../HudozkaLogo"
|
import { HudozkaLogo } from "../HudozkaLogo"
|
||||||
import { useDarkTheme } from "@/hooks/useDarkTheme"
|
import { useDarkTheme } from "@/hooks/useDarkTheme"
|
||||||
@@ -14,7 +14,7 @@ export type DesktopNavigationProps = {
|
|||||||
|
|
||||||
export const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ style }) => {
|
export const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ style }) => {
|
||||||
const dark = useDarkTheme()
|
const dark = useDarkTheme()
|
||||||
const { menu } = useContext(ConfigContext)
|
const menu = useContext(MenuContext)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box wrap gap={"var(--size-s)"} style={style}>
|
<Box wrap gap={"var(--size-s)"} style={style}>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { MenuToggle } from "../MenuToggle"
|
|||||||
import { Menu } from "../Menu"
|
import { Menu } from "../Menu"
|
||||||
import { Overlay } from "@/ui/Overlay"
|
import { Overlay } from "@/ui/Overlay"
|
||||||
import { useContext } from "react"
|
import { useContext } from "react"
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
import { MenuContext } from "@/context/MenuContext"
|
||||||
import { Box } from "@/ui/Box"
|
import { Box } from "@/ui/Box"
|
||||||
import { Spacer } from "../Spacer"
|
import { Spacer } from "../Spacer"
|
||||||
import { useToggle } from "react-use"
|
import { useToggle } from "react-use"
|
||||||
@@ -18,7 +18,7 @@ export type MobileNavigationProps = {
|
|||||||
export const MobileNavigation: React.FC<MobileNavigationProps> = ({ style }) => {
|
export const MobileNavigation: React.FC<MobileNavigationProps> = ({ style }) => {
|
||||||
const dark = useDarkTheme()
|
const dark = useDarkTheme()
|
||||||
const [open, toggleOpen] = useToggle(false)
|
const [open, toggleOpen] = useToggle(false)
|
||||||
const { menu } = useContext(ConfigContext)
|
const menu = useContext(MenuContext)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
import { createContext } from "react"
|
|
||||||
import config from "src/config"
|
|
||||||
|
|
||||||
export const ConfigContext = createContext(config)
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { createContext } from "react"
|
||||||
|
|
||||||
|
export const menu = [
|
||||||
|
{
|
||||||
|
name: "Школа",
|
||||||
|
href: "/",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const MenuContext = createContext(menu)
|
||||||
@@ -1,8 +1,20 @@
|
|||||||
|
import { proxy } from "valtio"
|
||||||
|
|
||||||
const currentYear = () => (new Date()).getFullYear()
|
const currentYear = () => (new Date()).getFullYear()
|
||||||
|
|
||||||
const config = {
|
type Contact = {
|
||||||
yearStart: 2012,
|
type: string
|
||||||
yearEnd: currentYear(),
|
value: string
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
years: [number, number]
|
||||||
|
contacts: Contact[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const state = proxy<State>({
|
||||||
|
years: [2012, currentYear()],
|
||||||
contacts: [
|
contacts: [
|
||||||
{
|
{
|
||||||
type: "link",
|
type: "link",
|
||||||
@@ -35,12 +47,4 @@ const config = {
|
|||||||
title: "Инстаграм",
|
title: "Инстаграм",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
menu: [
|
})
|
||||||
{
|
|
||||||
name: "Школа",
|
|
||||||
href: "/",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
||||||
Reference in new issue
Block a user