mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:49:45 +00:00
Перебросил useEffect из Main в Root и оформил как контекст
This commit is contained in:
1 parent
8496cae1aa
commit
ce0752c7eb
5 files changed
+68
-51
No files matched your search
+7
-16
@@ -1,31 +1,22 @@
|
|||||||
import { useEffect } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
import { News, Projects, Labs, Partners, Gallery, ContactUs } from './components';
|
import { News, Projects, Labs, Partners, Gallery, ContactUs } from './components';
|
||||||
import useElementOnScreen from '../../lib/useElementOnScreen';
|
import { RootContext } from '../Root';
|
||||||
|
|
||||||
|
import './Main.styles.scss';
|
||||||
|
|
||||||
function Main() {
|
function Main() {
|
||||||
const [containerRef, isVisible] = useElementOnScreen({
|
const { containerRef } = useContext(RootContext);
|
||||||
root: null,
|
|
||||||
rootMargin: '0px',
|
|
||||||
threshold: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const [ navbar ] = document.getElementsByClassName('navbar');
|
|
||||||
if (isVisible) {
|
|
||||||
navbar.classList.add('absolute');
|
|
||||||
} else {
|
|
||||||
navbar.classList.remove('absolute');
|
|
||||||
}
|
|
||||||
}, [isVisible]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<header className="header" id="mainpageheader" ref={containerRef}>
|
<header className="header" id="mainpageheader" ref={containerRef}>
|
||||||
|
<div className="container">
|
||||||
<h1>Думай иначе, будь креативным!</h1>
|
<h1>Думай иначе, будь креативным!</h1>
|
||||||
<h2>Студенческое конструкторское бюро<br />
|
<h2>Студенческое конструкторское бюро<br />
|
||||||
"Компьютерное инновационное творчество"</h2>
|
"Компьютерное инновационное творчество"</h2>
|
||||||
<a className="btn" href="">Связаться с нами</a>
|
<a className="btn" href="">Связаться с нами</a>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div className="content">
|
<div className="content">
|
||||||
<News />
|
<News />
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
@import "../../assets/styles/theme.scss";
|
||||||
|
|
||||||
|
#mainpageheader {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
height: 100vh;
|
||||||
|
padding: 0 10%;
|
||||||
|
|
||||||
|
color: $text-secondary;
|
||||||
|
background-image: url(/assets/images/car.jpeg);
|
||||||
|
background-color: $bg-image;
|
||||||
|
background-blend-mode: multiply;
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
|
|
||||||
|
.container {
|
||||||
|
position: absolute;
|
||||||
|
top: 40%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 60px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 63px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 36px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
-3
@@ -1,25 +1,46 @@
|
|||||||
import { Outlet, useLoaderData } from "react-router-dom";
|
import { Outlet, useLoaderData } from "react-router-dom";
|
||||||
|
import { createContext, useEffect } from 'react';
|
||||||
|
|
||||||
import { getContacts } from "../../api";
|
import { getContacts } from "../../api";
|
||||||
|
import useElementOnScreen from '../../lib/useElementOnScreen';
|
||||||
import Navbar from '../../components/Navbar';
|
import Navbar from '../../components/Navbar';
|
||||||
import Footer from "../../components/Footer";
|
import Footer from "../../components/Footer";
|
||||||
import './Root.styles.scss';
|
import './Root.styles.scss';
|
||||||
|
|
||||||
|
export const RootContext = createContext();
|
||||||
|
|
||||||
async function loader() {
|
async function loader() {
|
||||||
const contacts = await getContacts();
|
const contacts = await getContacts();
|
||||||
return { contacts };
|
return { contacts };
|
||||||
}
|
}
|
||||||
|
|
||||||
function Root() {
|
function Root() {
|
||||||
const { contacts } = useLoaderData();
|
|
||||||
|
const [containerRef, isVisible] = useElementOnScreen({
|
||||||
|
root: null,
|
||||||
|
rootMargin: '0px',
|
||||||
|
threshold: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const [navbar] = document.getElementsByClassName('navbar');
|
||||||
|
if (isVisible) {
|
||||||
|
navbar.classList.add('absolute');
|
||||||
|
} else {
|
||||||
|
navbar.classList.remove('absolute');
|
||||||
|
}
|
||||||
|
}, [isVisible]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<RootContext.Provider
|
||||||
|
value={{ containerRef }}
|
||||||
|
>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<div id="page">
|
<div id="page">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</>
|
</RootContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,6 @@
|
|||||||
@import "../../assets/styles/theme.scss";
|
@import "../../assets/styles/theme.scss";
|
||||||
|
|
||||||
#page {
|
#page {
|
||||||
|
|
||||||
.header {
|
|
||||||
height: 100vh;
|
|
||||||
padding: 0 10%;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
color: $text-secondary;
|
|
||||||
background-image: url(/assets/images/car.jpeg);
|
|
||||||
background-color: $bg-image;
|
|
||||||
background-blend-mode: multiply;
|
|
||||||
background-position: center;
|
|
||||||
background-size: cover;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 60px;
|
|
||||||
font-weight: 600;
|
|
||||||
line-height: 63px;
|
|
||||||
|
|
||||||
margin-top: 40vh;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
line-height: 36px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
background: $bg-primary;
|
background: $bg-primary;
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export { default as Root, loader } from './Root';
|
export { default as Root, RootContext, loader } from './Root';
|
||||||
Reference in new issue
Block a user