mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:59:45 +00:00
Merge pull request #19 from ifraimka1/feature/projects
Feature/projects
This commit is contained in:
27 files changed
+447
-145
No files matched your search
Generated
+139
@@ -12,6 +12,7 @@
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"html-react-parser": "^5.1.10",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
@@ -9226,6 +9227,84 @@
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser": {
|
||||
"version": "5.0.8",
|
||||
"resolved": "https://registry.npmjs.org/html-dom-parser/-/html-dom-parser-5.0.8.tgz",
|
||||
"integrity": "sha512-vuWiX9EXgu8CJ5m9EP5c7bvBmNSuQVnrY8tl0z0ZX96Uth1IPlYH/8W8VZ/hBajFf18EN+j2pukbCNd01HEd1w==",
|
||||
"dependencies": {
|
||||
"domhandler": "5.0.3",
|
||||
"htmlparser2": "9.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser/node_modules/dom-serializer": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
|
||||
"integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.3.0",
|
||||
"domhandler": "^5.0.2",
|
||||
"entities": "^4.2.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser/node_modules/domhandler": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
|
||||
"integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domhandler?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser/node_modules/domutils": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz",
|
||||
"integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==",
|
||||
"dependencies": {
|
||||
"dom-serializer": "^2.0.0",
|
||||
"domelementtype": "^2.3.0",
|
||||
"domhandler": "^5.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domutils?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser/node_modules/entities": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
|
||||
"integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
|
||||
"engines": {
|
||||
"node": ">=0.12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/html-dom-parser/node_modules/htmlparser2": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz",
|
||||
"integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==",
|
||||
"funding": [
|
||||
"https://github.com/fb55/htmlparser2?sponsor=1",
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fb55"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.3.0",
|
||||
"domhandler": "^5.0.3",
|
||||
"domutils": "^3.1.0",
|
||||
"entities": "^4.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/html-encoding-sniffer": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",
|
||||
@@ -9277,6 +9356,40 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/html-react-parser": {
|
||||
"version": "5.1.10",
|
||||
"resolved": "https://registry.npmjs.org/html-react-parser/-/html-react-parser-5.1.10.tgz",
|
||||
"integrity": "sha512-gV22PvLij4wdEdtrZbGVC7Zy2OVWnQ0bYhX63S196ZRSx4+K0TuutCreHSXr+saUia8KeKB+2TYziVfijpH4Tw==",
|
||||
"dependencies": {
|
||||
"domhandler": "5.0.3",
|
||||
"html-dom-parser": "5.0.8",
|
||||
"react-property": "2.0.2",
|
||||
"style-to-js": "1.1.12"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "17 || 18",
|
||||
"react": "0.14 || 15 || 16 || 17 || 18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/html-react-parser/node_modules/domhandler": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
|
||||
"integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domhandler?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/html-webpack-plugin": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-5.6.0.tgz",
|
||||
@@ -9556,6 +9669,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
|
||||
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
|
||||
},
|
||||
"node_modules/inline-style-parser": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.2.3.tgz",
|
||||
"integrity": "sha512-qlD8YNDqyTKTyuITrDOffsl6Tdhv+UC4hcdAVuQsK4IMQ99nSgd1MIA/Q+jQYoh9r3hVUXhYh7urSRmXPkW04g=="
|
||||
},
|
||||
"node_modules/internal-slot": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz",
|
||||
@@ -15045,6 +15163,11 @@
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
|
||||
},
|
||||
"node_modules/react-property": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/react-property/-/react-property-2.0.2.tgz",
|
||||
"integrity": "sha512-+PbtI3VuDV0l6CleQMsx2gtK0JZbZKbpdu5ynr+lbsuvtmgbNcS3VM0tuY2QjFNOcWxvXeHjDpy42RO+4U2rug=="
|
||||
},
|
||||
"node_modules/react-refresh": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.11.0.tgz",
|
||||
@@ -16521,6 +16644,22 @@
|
||||
"webpack": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/style-to-js": {
|
||||
"version": "1.1.12",
|
||||
"resolved": "https://registry.npmjs.org/style-to-js/-/style-to-js-1.1.12.tgz",
|
||||
"integrity": "sha512-tv+/FkgNYHI2fvCoBMsqPHh5xovwiw+C3X0Gfnss/Syau0Nr3IqGOJ9XiOYXoPnToHVbllKFf5qCNFJGwFg5mg==",
|
||||
"dependencies": {
|
||||
"style-to-object": "1.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/style-to-object": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-1.0.6.tgz",
|
||||
"integrity": "sha512-khxq+Qm3xEyZfKd/y9L3oIWQimxuc4STrQKtQn8aSDRHb8mFgpukgX1hdzfrMEW6JCjyJ8p89x+IUMVnCBI1PA==",
|
||||
"dependencies": {
|
||||
"inline-style-parser": "0.2.3"
|
||||
}
|
||||
},
|
||||
"node_modules/stylehacks": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-5.1.1.tgz",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"html-react-parser": "^5.1.10",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
||||
+86
-7
@@ -2,6 +2,8 @@ import * as WPAPI from 'wpapi';
|
||||
import { flatten } from 'lodash';
|
||||
|
||||
import reactPress from './reactPress';
|
||||
import HTMLReactParser from 'html-react-parser/lib/index';
|
||||
//import projects from './projects.json';
|
||||
|
||||
const wp = new WPAPI(
|
||||
process.env.NODE_ENV === 'development'
|
||||
@@ -13,7 +15,7 @@ const wp = new WPAPI(
|
||||
: { endpoint: reactPress.api.rest_url, nonce: reactPress.api.nonce }
|
||||
);
|
||||
|
||||
async function getAllMedia(request) {
|
||||
async function getAllContent(request) {
|
||||
return request.then(function (response) {
|
||||
if (!response._paging || !response._paging.next) {
|
||||
return response;
|
||||
@@ -21,7 +23,7 @@ async function getAllMedia(request) {
|
||||
// Запрос к следующей странице и возврат ответов одной коллекцией
|
||||
return Promise.all([
|
||||
response,
|
||||
getAllMedia(response._paging.next)
|
||||
getAllContent(response._paging.next)
|
||||
]).then(function (responses) {
|
||||
return flatten(responses);
|
||||
});
|
||||
@@ -30,7 +32,7 @@ async function getAllMedia(request) {
|
||||
|
||||
// Функция загрузки медабиблиотеки и сортировки по категориям
|
||||
async function loadMedia() {
|
||||
const response = await getAllMedia(wp.media());
|
||||
const response = await getAllContent(wp.media());
|
||||
|
||||
// Нам потребуется id, категория и url
|
||||
const result = {};
|
||||
@@ -53,10 +55,64 @@ async function loadMedia() {
|
||||
const mediaLibrary = await loadMedia();
|
||||
console.log(mediaLibrary);
|
||||
|
||||
export async function getPosts(q = '') {
|
||||
async function loadPosts() {
|
||||
// Получаем рубрики
|
||||
const responseCategories = await getAllContent(wp.categories());
|
||||
const categories = {};
|
||||
|
||||
for (let { id, name } of responseCategories) {
|
||||
categories[id] = name;
|
||||
}
|
||||
|
||||
// Получаем метки
|
||||
const responseTags = await getAllContent(wp.tags());
|
||||
const tags = {};
|
||||
|
||||
for (let { id, name } of responseTags) {
|
||||
tags[id] = name;
|
||||
}
|
||||
|
||||
// Получаем записи
|
||||
const responsePosts = await getAllContent(wp.posts());
|
||||
|
||||
for (let post of responsePosts) {
|
||||
post.categories = post.categories.map(el => categories[el]);
|
||||
post.tags = post.tags.map(el => tags[el]);
|
||||
}
|
||||
|
||||
return responsePosts;
|
||||
}
|
||||
|
||||
const posts = await loadPosts();
|
||||
console.log(posts);
|
||||
|
||||
|
||||
function createProjectList() {
|
||||
const result = {};
|
||||
|
||||
for (let post of posts) {
|
||||
if (post.categories.includes('projects')) {
|
||||
const { image } = mediaLibrary['projects'].find(item => item.id === post.featured_media);
|
||||
|
||||
result[post.id] = {
|
||||
id: post.id,
|
||||
name: post.title.rendered,
|
||||
tag: post.tags[0],
|
||||
preview: image
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const projects = createProjectList();
|
||||
console.log(projects);
|
||||
|
||||
export async function getPosts(name) {
|
||||
try {
|
||||
const posts = await wp.posts().search(q);
|
||||
return posts;
|
||||
const result = posts.filter(post => post.id == name)[0];
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return [];
|
||||
@@ -69,7 +125,6 @@ export async function getMedia(category, target = false) {
|
||||
for (let media of mediaLibrary[category]) {
|
||||
target[media.name].image = media.image;
|
||||
target[media.name].id = media.id;
|
||||
console.log(target[media.name].id);
|
||||
}
|
||||
|
||||
return target;
|
||||
@@ -80,4 +135,28 @@ export async function getMedia(category, target = false) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getProjectByID(id) {
|
||||
try {
|
||||
if (typeof id != 'undefined') {
|
||||
return projects[id];
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getProjects(filter) {
|
||||
try {
|
||||
if (typeof filter != 'undefined') {
|
||||
return projects.filter(project => project.includes(filter));
|
||||
}
|
||||
|
||||
return projects;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ a {
|
||||
}
|
||||
|
||||
.image {
|
||||
max-width: 100%;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
@@ -69,4 +70,20 @@ header h1 {
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
line-height: 44px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#root {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
|
||||
#page {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
#footer {
|
||||
margin-top: auto;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ $bg-image: rgba(0, 0, 0, .75);
|
||||
|
||||
$text-primary: black;
|
||||
$text-secondary: white;
|
||||
$text-card-project: #767676;
|
||||
$text-card-project: white;
|
||||
$text-card-project-bg: rgba(255, 255, 255, 0.75);
|
||||
|
||||
$shadow-primary: rgba(0, 0, 0, 0.25);
|
||||
|
||||
@@ -41,7 +41,7 @@ function Footer({ links = mockLinks, contacts = mockContacts }) {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<footer className="footer">
|
||||
<footer id="footer">
|
||||
<div className="logo-container">
|
||||
<img className="logo" alt="logo" src={ logo } />
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@import "../../assets/styles/theme.scss";
|
||||
|
||||
.footer {
|
||||
#footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function MediaContainer({ src, key }) {
|
||||
function MediaContainer({ src }) {
|
||||
return (
|
||||
<div className="media-container">
|
||||
<img className="image" alt="" src={src} key={key} />
|
||||
<img className="image" alt="" src={src} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Executable → Regular
+6
-4
@@ -1,11 +1,13 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import "./ProjectCard.styles.scss";
|
||||
|
||||
function ProjectCard({ project }) {
|
||||
return (
|
||||
<Link className="card" to={`/projects`}>
|
||||
<img className="image" alt="project_image" src={project.image}></img>
|
||||
<div className="link-label">
|
||||
Перейти →
|
||||
<Link className="card" to={ `/projects/` + project.id }>
|
||||
<img className="image" alt="project_image" src={project.preview}></img>
|
||||
<div className="label">
|
||||
{ `Проект "${project.name}"` }
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
@@ -0,0 +1,32 @@
|
||||
@import "../../assets/styles/theme.scss";
|
||||
|
||||
.card {
|
||||
display: block;
|
||||
position: relative;
|
||||
height: 250px;
|
||||
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: transparent;
|
||||
|
||||
.image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.label {
|
||||
position: absolute;
|
||||
left: 22px;
|
||||
bottom: 16px;
|
||||
|
||||
padding: 2px;
|
||||
border-radius: 4px;
|
||||
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
color: $text-card-project;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import ProjectCard from "./ProjectCard";
|
||||
import { getProjects } from "../../api";
|
||||
|
||||
import "./ProjectList.styles.scss";
|
||||
|
||||
function ProjectList({ laboratory }) {
|
||||
const [projectList, setProjectList] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const newProjectList = await getProjects(laboratory);
|
||||
setProjectList(newProjectList);
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="row project-list">
|
||||
{Object.keys(projectList).map(id => <ProjectCard key={id} project={projectList[id]} />)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectList;
|
||||
@@ -0,0 +1,12 @@
|
||||
@import "../../assets/styles/theme.scss";
|
||||
|
||||
.project-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 32px;
|
||||
|
||||
.card {
|
||||
flex: 1 1 30%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "./ProjectList";
|
||||
@@ -0,0 +1,8 @@
|
||||
export { default as ContactForm } from './ContactForm';
|
||||
export { default as Field } from './Field';
|
||||
export { default as Footer } from './Footer';
|
||||
export { default as MediaBlock } from './MediaBlock';
|
||||
export { default as MediaContainer } from './MediaContainer';
|
||||
export { default as Navbar } from './Navbar';
|
||||
export { default as Slider } from './Slider';
|
||||
export { default as ProjectList } from './Projects';
|
||||
@@ -41,4 +41,34 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.block {
|
||||
|
||||
h1 {
|
||||
font-family: Montserrat;
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
line-height: 44px;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
a {
|
||||
font-size: 24px;
|
||||
font-weight: 400;
|
||||
line-height: 29px;
|
||||
text-align: right;
|
||||
color: $text-primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.block:not(:last-child) {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ function BlockHeading({ heading, link, linkText }) {
|
||||
<div className="heading">
|
||||
<h1>{heading}</h1>
|
||||
{link && linkText &&
|
||||
<Link to={link} target="_blank">{linkText} →</Link>
|
||||
<Link to={link}>{linkText} →</Link>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,57 +1,13 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import BlockHeading from '../BlockHeading';
|
||||
import ProjectCard from './ProjectCard';
|
||||
|
||||
import { getMedia } from '../../../../api';
|
||||
import ProjectList from '../../../../components/Projects';
|
||||
|
||||
import './Projects.styles.scss';
|
||||
import {
|
||||
drone,
|
||||
ttt,
|
||||
comBattle
|
||||
} from '../../../../assets/images/projects';
|
||||
|
||||
const mock = {
|
||||
drone: {
|
||||
image: drone,
|
||||
link: "/projects",
|
||||
},
|
||||
ttt: {
|
||||
image: ttt,
|
||||
link: "/projects",
|
||||
},
|
||||
comBattle: {
|
||||
image: comBattle,
|
||||
link: "/projects",
|
||||
},
|
||||
comBattle2: {
|
||||
image: comBattle,
|
||||
link: "/projects",
|
||||
},
|
||||
comBattle3: {
|
||||
image: comBattle,
|
||||
link: "/projects",
|
||||
},
|
||||
};
|
||||
|
||||
function Projects({ projects = mock }) {
|
||||
const [mediaList, setMediaList] = useState(projects);
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const newMediaList = await getMedia('projects', mediaList);
|
||||
setMediaList(newMediaList);
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
function Projects() {
|
||||
return (
|
||||
<div className="block" id="projects">
|
||||
<BlockHeading heading="Наши проекты" linkText="Все проекты" link="/projects" />
|
||||
<div className="row">
|
||||
{ Object.keys(mediaList).map(project => <ProjectCard key={ mediaList[project].id } project={ mediaList[project] } />) }
|
||||
</div>
|
||||
<ProjectList />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,43 +7,5 @@
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 32px;
|
||||
|
||||
.card:nth-child(-n + 2) {
|
||||
flex: 1.5 1 40%;
|
||||
}
|
||||
|
||||
.card {
|
||||
display: block;
|
||||
position: relative;
|
||||
flex: 1 0.5 30%;
|
||||
height: 250px;
|
||||
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: transparent;
|
||||
|
||||
.image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.link-label {
|
||||
position: absolute;
|
||||
right: 22px;
|
||||
bottom: 16px;
|
||||
|
||||
padding: 2px;
|
||||
border-radius: 4px;
|
||||
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
color: $text-card-project;
|
||||
|
||||
background-color: $text-card-project-bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
import { PageContent, PageHeader } from "../components";
|
||||
import { ProjectList } from "../../components"
|
||||
|
||||
function Projects() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader className="header">
|
||||
<h1>Projects</h1>
|
||||
<h1>Проекты</h1>
|
||||
</PageHeader>
|
||||
<PageContent className="content">
|
||||
|
||||
<ProjectList />
|
||||
</PageContent>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useLoaderData, useParams } from "react-router-dom";
|
||||
import Parse from 'html-react-parser';
|
||||
|
||||
import { PageHeader, PageContent } from "../../components";
|
||||
|
||||
import { getProjects, getMedia, getPosts } from "../../../api";
|
||||
import { MediaContainer } from "../../../components";
|
||||
|
||||
export async function loader() {
|
||||
const projects = await getProjects();
|
||||
return { projects };
|
||||
}
|
||||
|
||||
function Project() {
|
||||
const [mediaList, setMediaList] = useState([]);
|
||||
const [post, setPost] = useState();
|
||||
|
||||
const params = useParams();
|
||||
const projectID = params.id;
|
||||
|
||||
const { projects } = useLoaderData(projectID);
|
||||
const project = projects[projectID];
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const newMediaList = await getMedia('projects')
|
||||
.then((result) => {
|
||||
return result.filter(el => el.name.includes(project.tag));
|
||||
});
|
||||
setMediaList(newMediaList);
|
||||
const newPost = await getPosts(projectID);
|
||||
setPost(newPost);
|
||||
};
|
||||
loadData();
|
||||
}, [projectID]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader className="header">
|
||||
<h1>{typeof post !== 'undefined' && post.title.rendered}</h1>
|
||||
</PageHeader>
|
||||
<PageContent className="content">
|
||||
{typeof post !== 'undefined' &&
|
||||
Parse(post.content.rendered)
|
||||
.map(el => {
|
||||
if (el.type === 'figure') {
|
||||
const media = mediaList.find(item => el.props.children.props.alt.includes(item.name));
|
||||
console.log(media);
|
||||
return <MediaContainer src={media.image} key={media.id} />;
|
||||
}
|
||||
return el;
|
||||
})
|
||||
}
|
||||
</PageContent>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Project;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Project, loader } from "./Project";
|
||||
+1
-10
@@ -1,7 +1,6 @@
|
||||
import { Outlet } from "react-router-dom";
|
||||
import { createContext, useEffect } from 'react';
|
||||
|
||||
import { getMedia } from "../../api";
|
||||
import useElementOnScreen from '../../lib/useElementOnScreen';
|
||||
import Navbar from '../../components/Navbar';
|
||||
import Footer from '../../components/Footer';
|
||||
@@ -9,11 +8,6 @@ import './Root.styles.scss';
|
||||
|
||||
export const RootContext = createContext();
|
||||
|
||||
async function loader() {
|
||||
const media = getMedia();
|
||||
return { media };
|
||||
}
|
||||
|
||||
function Root() {
|
||||
const [setRef, isVisible] = useElementOnScreen({
|
||||
root: null,
|
||||
@@ -31,9 +25,7 @@ function Root() {
|
||||
}, [isVisible]);
|
||||
|
||||
return (
|
||||
<RootContext.Provider
|
||||
value={{ setRef }}
|
||||
>
|
||||
<RootContext.Provider value={{ setRef }}>
|
||||
<Navbar />
|
||||
<div id="page">
|
||||
<Outlet />
|
||||
@@ -43,5 +35,4 @@ function Root() {
|
||||
);
|
||||
}
|
||||
|
||||
export { loader };
|
||||
export default Root;
|
||||
@@ -10,33 +10,6 @@
|
||||
|
||||
.content {
|
||||
background: $bg-primary;
|
||||
|
||||
.block {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h1 {
|
||||
font-family: Montserrat;
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
line-height: 44px;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
a {
|
||||
font-size: 24px;
|
||||
font-weight: 400;
|
||||
line-height: 29px;
|
||||
text-align: right;
|
||||
color: $text-primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { default as Root, RootContext, loader } from './Root';
|
||||
export { default as Root, RootContext } from './Root';
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export { Root, loader } from './Root';
|
||||
export { Root } from './Root';
|
||||
export { default as ErrorPage} from './ErrorPage';
|
||||
export { default as Main } from './Main';
|
||||
export { default as AboutUs } from './AboutUs';
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"tag": "ambr",
|
||||
"name": "Амброзия",
|
||||
"desc": "Невероятный проект, завоевавший сердца жителей Таганрога."
|
||||
}
|
||||
]
|
||||
+6
-2
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
Root,
|
||||
loader as rootLoader,
|
||||
ErrorPage,
|
||||
Main,
|
||||
AboutUs,
|
||||
@@ -8,13 +7,13 @@ import {
|
||||
Projects,
|
||||
Contact
|
||||
} from './pages';
|
||||
import { Project, loader as projectsLoader } from './pages/Projects/components';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
element: <Root />,
|
||||
errorElement: <ErrorPage />,
|
||||
loader: rootLoader,
|
||||
children: [
|
||||
{
|
||||
path: "/",
|
||||
@@ -32,6 +31,11 @@ const routes = [
|
||||
path: "/projects",
|
||||
element: <Projects />,
|
||||
},
|
||||
{
|
||||
path: "/projects/:id",
|
||||
element: <Project />,
|
||||
loader: projectsLoader,
|
||||
},
|
||||
{
|
||||
path: "/contact",
|
||||
element: <Contact />,
|
||||
|
||||
Reference in new issue
Block a user