Получение, хранение и отображение проектов; новый компонент ProjectList, перенос к нему ProjectCard; реализация страниц проектов

This commit is contained in:
ifraimka committed 2024-05-17 16:44:45 +03:00
1 parent 81d2a009e0
commit 0ef02b2220
13 files changed
+132 -115

No files matched your search

@@ -5,7 +5,7 @@ function BlockHeading({ heading, link, linkText }) {
<div className="heading">
<h1>{heading}</h1>
{link && linkText &&
<Link to={link} target="_blank">{linkText} &rarr;</Link>
<Link to={link}>{linkText} &rarr;</Link>
}
</div>
);
@@ -1,14 +0,0 @@
import { Link } from 'react-router-dom';
function ProjectCard({ project }) {
return (
<Link className="card" to={`/projects`}>
<img className="image" alt="project_image" src={project.image}></img>
<div className="link-label">
Перейти &rarr;
</div>
</Link>
);
}
export default ProjectCard;
@@ -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;
}
}
}
}