From 945947aa221f6b4d7ae45d8aa033f33fedb47557 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 25 Aug 2025 23:56:35 +0300 Subject: [PATCH] rename config context to menu context; move config to state --- src/components/App/index.tsx | 12 +++----- src/components/Contacts/index.tsx | 6 ++-- src/components/Copyright/index.tsx | 13 +++++---- .../Navigation/DesktopNavigation.tsx | 4 +-- .../Navigation/MobileNavigation.tsx | 4 +-- src/context/ConfigContext.ts | 4 --- src/context/MenuContext.ts | 10 +++++++ src/{ => store}/config.ts | 28 +++++++++++-------- 8 files changed, 45 insertions(+), 36 deletions(-) delete mode 100644 src/context/ConfigContext.ts create mode 100644 src/context/MenuContext.ts rename src/{ => store}/config.ts (80%) diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 0f1d3912..113483fa 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -1,6 +1,5 @@ import { Wrapper } from "../Wrapper" -import { ConfigContext } from "src/context/ConfigContext" -import config from "src/config" +import { MenuContext } from "@/context/MenuContext" import { Footer } from "../Footer" import { Content } from "../Content" import { Breadcrumbs } from "../Breadcrumbs" @@ -10,7 +9,7 @@ import { useMobile } from "src/hooks/useMobile" import { Navigation } from "@/components/Navigation" import { Box } from "@/ui/Box" import { AccessibilityButton } from "../AccessibilityButton" -import { Copyright } from "../Copyright" +import Copyright from "@/components/Copyright" import { Spacer } from "../Spacer" import { Author } from "../Author" import { Title } from "@/ui/Title" @@ -45,10 +44,7 @@ export const App: React.FC = ({ showAuthor = false, menu, ...props }) } return ( - + @@ -157,6 +153,6 @@ export const App: React.FC = ({ showAuthor = false, menu, ...props }) - + ) } diff --git a/src/components/Contacts/index.tsx b/src/components/Contacts/index.tsx index 0c45bfd9..cea804cd 100644 --- a/src/components/Contacts/index.tsx +++ b/src/components/Contacts/index.tsx @@ -1,12 +1,12 @@ import s from "./contacts.module.css" -import { useContext } from "react" -import { ConfigContext } from "src/context/ConfigContext" import Link from "next/link" import { Title } from "@/ui/Title" +import { useSnapshot } from "valtio" +import { state } from "@/store/config" export const Contacts: React.FC = props => { - const { contacts } = useContext(ConfigContext) + const { contacts } = useSnapshot(state) return ( <> diff --git a/src/components/Copyright/index.tsx b/src/components/Copyright/index.tsx index 158db6ec..4df84aeb 100644 --- a/src/components/Copyright/index.tsx +++ b/src/components/Copyright/index.tsx @@ -1,10 +1,13 @@ -import { useContext } from "react" -import { ConfigContext } from "src/context/ConfigContext" +import { state } from "@/store/config" +import { useSnapshot } from "valtio" -export const Copyright: React.FC = () => { - const { yearStart, yearEnd } = useContext(ConfigContext) +function Copyright() { + const { years } = useSnapshot(state) + const year = years.map(String).join("—") return ( - © {yearStart}—{yearEnd} Шлиссельбургская детская художественная школа + © {year} Шлиссельбургская детская художественная школа ) } + +export default Copyright diff --git a/src/components/Navigation/DesktopNavigation.tsx b/src/components/Navigation/DesktopNavigation.tsx index b94666ca..7cca2850 100644 --- a/src/components/Navigation/DesktopNavigation.tsx +++ b/src/components/Navigation/DesktopNavigation.tsx @@ -1,6 +1,6 @@ import { Menu } from "../Menu" import { useContext } from "react" -import { ConfigContext } from "src/context/ConfigContext" +import { MenuContext } from "@/context/MenuContext" import { Box } from "@/ui/Box" import { HudozkaLogo } from "../HudozkaLogo" import { useDarkTheme } from "@/hooks/useDarkTheme" @@ -14,7 +14,7 @@ export type DesktopNavigationProps = { export const DesktopNavigation: React.FC = ({ style }) => { const dark = useDarkTheme() - const { menu } = useContext(ConfigContext) + const menu = useContext(MenuContext) return ( diff --git a/src/components/Navigation/MobileNavigation.tsx b/src/components/Navigation/MobileNavigation.tsx index 0ccdbf04..76491fc5 100644 --- a/src/components/Navigation/MobileNavigation.tsx +++ b/src/components/Navigation/MobileNavigation.tsx @@ -2,7 +2,7 @@ import { MenuToggle } from "../MenuToggle" import { Menu } from "../Menu" import { Overlay } from "@/ui/Overlay" import { useContext } from "react" -import { ConfigContext } from "src/context/ConfigContext" +import { MenuContext } from "@/context/MenuContext" import { Box } from "@/ui/Box" import { Spacer } from "../Spacer" import { useToggle } from "react-use" @@ -18,7 +18,7 @@ export type MobileNavigationProps = { export const MobileNavigation: React.FC = ({ style }) => { const dark = useDarkTheme() const [open, toggleOpen] = useToggle(false) - const { menu } = useContext(ConfigContext) + const menu = useContext(MenuContext) return ( <> diff --git a/src/context/ConfigContext.ts b/src/context/ConfigContext.ts deleted file mode 100644 index 4e58b4f2..00000000 --- a/src/context/ConfigContext.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { createContext } from "react" -import config from "src/config" - -export const ConfigContext = createContext(config) diff --git a/src/context/MenuContext.ts b/src/context/MenuContext.ts new file mode 100644 index 00000000..51e43928 --- /dev/null +++ b/src/context/MenuContext.ts @@ -0,0 +1,10 @@ +import { createContext } from "react" + +export const menu = [ + { + name: "Школа", + href: "/", + }, +] + +export const MenuContext = createContext(menu) diff --git a/src/config.ts b/src/store/config.ts similarity index 80% rename from src/config.ts rename to src/store/config.ts index 14ff5217..3a73aa90 100644 --- a/src/config.ts +++ b/src/store/config.ts @@ -1,8 +1,20 @@ +import { proxy } from "valtio" + const currentYear = () => (new Date()).getFullYear() -const config = { - yearStart: 2012, - yearEnd: currentYear(), +type Contact = { + type: string + value: string + title: string +} + +type State = { + years: [number, number] + contacts: Contact[] +} + +export const state = proxy({ + years: [2012, currentYear()], contacts: [ { type: "link", @@ -35,12 +47,4 @@ const config = { title: "Инстаграм", }, ], - menu: [ - { - name: "Школа", - href: "/", - }, - ], -} - -export default config +})