Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): ScopeContext implemented, close #6 issue #20

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { useStaticQuery, graphql } from "gatsby"

import Navigation from "./navigation"

interface HeaderProps {
scope?: string
}

const Header: React.FC<HeaderProps> = ({ scope = "" }) => {
const Header: React.FC = () => {
const meta = useStaticQuery(
graphql`query {
allFile(filter: {relativePath: {eq: "meta.json"}}) {
Expand Down Expand Up @@ -40,7 +36,7 @@ const Header: React.FC<HeaderProps> = ({ scope = "" }) => {
</div>
<button className="rounded-all" data-href="/join/">Заполнить бриф</button>
</div>
<Navigation scope={scope} />
<Navigation />
</div>
</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import "../fonts/fontawesome/css/solid.min.css"
import "../styles/app.css"

interface LayoutProps {
scope?: string
children?: ReactNode
}

const Layout: React.FC<LayoutProps> = ({ scope = "", children = undefined }) => {
const Layout: React.FC<LayoutProps> = ({ children = undefined }) => {
return (
<div id="master-container" className="master-container">
<Header scope={scope}></Header>
<Header />
{children}
<Footer />
</div>
Expand Down
22 changes: 10 additions & 12 deletions src/components/navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from "react"
import React, { useContext, useEffect } from "react"
import { Link } from "gatsby"

import ScopeContext from "../context/scopeContext"
import animate from "../scripts/animate"
import utils from "../scripts/utils"

Expand All @@ -14,13 +15,10 @@ const closeShowedSubnav = async () => {
document.querySelector(".subnav-container.showed")?.classList.remove("showed");
}

interface NavigationProps {
scope?: string
}
const Navigation: React.FC = () => {
const { scope } = useContext(ScopeContext);

const Navigation: React.FC<NavigationProps> = ({ scope = "" }) => {
useEffect(() => {
// Submenus
const elemSubnavWrappers = document.querySelectorAll('.subnav-container');

document.querySelectorAll("a.subnav").forEach(function (elem, i) {
Expand Down Expand Up @@ -80,18 +78,18 @@ const Navigation: React.FC<NavigationProps> = ({ scope = "" }) => {
return (
<nav className="nav-container">
<ul className="mnav">
<li><Link to="/" data-scope="home" className={checkActiveItem("home", scope)}>ГЛАВНАЯ</Link></li>
<li><Link to="/projects/" data-scope="projects"
<li><Link to="/" className={checkActiveItem("home", scope)}>ГЛАВНАЯ</Link></li>
<li><Link to="/projects/"
className={"subnav " + checkActiveItem("projects", scope)}
onClick={closeShowedSubnav}>ПРОЕКТЫ
</Link></li>
<li><Link to="/services/" data-scope="services"
<li><Link to="/services/"
className={"subnav " + checkActiveItem("services", scope)}
onClick={closeShowedSubnav}>УСЛУГИ
</Link></li>
<li><Link to="/blog/" data-scope="blog" className={checkActiveItem("blog", scope)}>БЛОГ</Link></li>
<li><Link to="/about/" data-scope="about" className={checkActiveItem("about", scope)}>О НАС</Link></li>
<li><Link to="/contacts/" data-scope="contacts" className={checkActiveItem("contacts", scope)}>КОНТАКТЫ</Link></li>
<li><Link to="/blog/" className={checkActiveItem("blog", scope)}>БЛОГ</Link></li>
<li><Link to="/about/" className={checkActiveItem("about", scope)}>О НАС</Link></li>
<li><Link to="/contacts/" className={checkActiveItem("contacts", scope)}>КОНТАКТЫ</Link></li>
</ul>
<div className="subnav-container animate-slidein-fadein-css">
<div className="subnav-column">
Expand Down
5 changes: 5 additions & 0 deletions src/context/scopeContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from "react";

const ScopeContext = createContext({ scope: "" });

export default ScopeContext;
22 changes: 13 additions & 9 deletions src/pages/about/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -8,15 +10,17 @@ const AboutPage = () => {
const currentPage: Page = { title: "О нас" };

return (
<Layout scope="about">
<SEO title={currentPage.title} description="Информация о нашей компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>О нас</h1>
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "about" }}>
<Layout>
<SEO title={currentPage.title} description="Информация о нашей компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>О нас</h1>
</div>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down
22 changes: 13 additions & 9 deletions src/pages/blog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -8,15 +10,17 @@ const BlogPage = () => {
const currentPage: Page = { title: "Блог" };

return (
<Layout scope="blog">
<SEO title={currentPage.title} description="Блог нашей компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Блог</h1>
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "blog" }}>
<Layout>
<SEO title={currentPage.title} description="Блог нашей компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Блог</h1>
</div>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down
40 changes: 22 additions & 18 deletions src/pages/contacts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react"
import { useStaticQuery, graphql } from "gatsby"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -27,26 +29,28 @@ const ContactsPage = () => {
).allFile?.nodes[0]?.childContentJson?.meta

return (
<Layout scope="contacts">
<SEO title={currentPage.title} description="Наши контакты" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши контакты</h1>
<div className="contacts-emails">
<div className="contacts-emails-column">
<h3>Обратная связь</h3>
<a href={`mailto:${meta.email_info}`}>{meta.email_info}</a>
</div>
<div className="contacts-emails-column">
<h3>Пресса / PR</h3>
<a href={`mailto:${meta.email_pr}`}>{meta.email_pr}</a>
<ScopeContext.Provider value={{ scope: "contacts" }}>
<Layout>
<SEO title={currentPage.title} description="Наши контакты" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши контакты</h1>
<div className="contacts-emails">
<div className="contacts-emails-column">
<h3>Обратная связь</h3>
<a href={`mailto:${meta.email_info}`}>{meta.email_info}</a>
</div>
<div className="contacts-emails-column">
<h3>Пресса / PR</h3>
<a href={`mailto:${meta.email_pr}`}>{meta.email_pr}</a>
</div>
</div>
<ContactsForm />
</div>
<ContactsForm />
</div>
</section>
</Layout>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down
20 changes: 12 additions & 8 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import React from "react"

import ScopeContext from "../context/scopeContext"

import Layout from "../components/layout"
import SEO from "../components/seo"
import Slider from "../components/slider"

const IndexPage = () => (
<Layout scope="home">
<SEO title="Главная" />
<section id="content-holder" className="container">
<div id="content" className="content animate-fadein-css">
<Slider />
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "home" }}>
<Layout>
<SEO title="Главная" />
<section id="content-holder" className="container">
<div id="content" className="content animate-fadein-css">
<Slider />
</div>
</section>
</Layout>
</ScopeContext.Provider>
)

export default IndexPage
22 changes: 13 additions & 9 deletions src/pages/projects/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -8,15 +10,17 @@ const ProjectsPage = () => {
const currentPage: Page = { title: "Проекты" };

return (
<Layout scope="projects">
<SEO title={currentPage.title} description="Все проекты" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши проекты</h1>
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "projects" }}>
<Layout>
<SEO title={currentPage.title} description="Все проекты" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши проекты</h1>
</div>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down
22 changes: 13 additions & 9 deletions src/pages/projects/it.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -12,15 +14,17 @@ const ProjectsITPage = () => {
};

return (
<Layout scope="projects">
<SEO title="IT-проекты" description="Проекты в сфере IT и высоких технологий" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} parentPages={[parentPage]} />
<div id="content" className="content animate-fadein-css">
<h1>Наши проекты в IT-сфере</h1>
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "projects" }}>
<Layout>
<SEO title="IT-проекты" description="Проекты в сфере IT и высоких технологий" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} parentPages={[parentPage]} />
<div id="content" className="content animate-fadein-css">
<h1>Наши проекты в IT-сфере</h1>
</div>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down
22 changes: 13 additions & 9 deletions src/pages/services/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"

import ScopeContext from "../../context/scopeContext"

import Layout from "../../components/layout"
import SEO from "../../components/seo"
import Breadcrumbs, { Page } from "../../components/breadcrumbs"
Expand All @@ -8,15 +10,17 @@ const ServicesPage = () => {
const currentPage: Page = { title: "Услуги" };

return (
<Layout scope="services">
<SEO title={currentPage.title} description="Услуги компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши услуги</h1>
</div>
</section>
</Layout>
<ScopeContext.Provider value={{ scope: "services" }}>
<Layout>
<SEO title={currentPage.title} description="Услуги компании" />
<section id="content-holder" className="container">
<Breadcrumbs page={currentPage} />
<div id="content" className="content animate-fadein-css">
<h1>Наши услуги</h1>
</div>
</section>
</Layout>
</ScopeContext.Provider>
)
}

Expand Down