mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:39:45 +00:00
Изменил страницу проекта под использование общего компонента PagePost
This commit is contained in:
1 parent
7b9db4aa57
commit
58a1bb81ca
2 files changed
+9
-39
No files matched your search
@@ -1,58 +1,28 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useLoaderData, useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import Parse from 'html-react-parser';
|
|
||||||
|
|
||||||
import { PageHeader, PageContent } from "../../components";
|
import { PagePost } from "../../components";
|
||||||
|
|
||||||
import { getProjects, getMedia, getPosts } from "../../../api";
|
import { getProjectByID } from "../../../api";
|
||||||
import { MediaContainer } from "../../../components";
|
|
||||||
|
|
||||||
export async function loader() {
|
|
||||||
const projects = await getProjects();
|
|
||||||
return { projects };
|
|
||||||
}
|
|
||||||
|
|
||||||
function Project() {
|
function Project() {
|
||||||
const [mediaList, setMediaList] = useState([]);
|
const [project, setProject] = useState();
|
||||||
const [post, setPost] = useState();
|
|
||||||
|
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const projectID = params.id;
|
const projectID = params.id;
|
||||||
|
|
||||||
const { projects } = useLoaderData(projectID);
|
|
||||||
const project = projects[projectID];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
const newMediaList = await getMedia('projects')
|
const newProject = await getProjectByID(projectID);
|
||||||
.then((result) => {
|
setProject(newProject);
|
||||||
return result.filter(el => el.name.includes(project.tag));
|
console.log('newProject', newProject);
|
||||||
});
|
|
||||||
setMediaList(newMediaList);
|
|
||||||
const newPost = await getPosts(projectID);
|
|
||||||
setPost(newPost);
|
|
||||||
};
|
};
|
||||||
loadData();
|
loadData();
|
||||||
}, [projectID]);
|
}, [projectID]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader className="header">
|
{project && <PagePost post={project} />}
|
||||||
<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>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export { default as Project, loader } from "./Project";
|
export { default as Project } from "./Project";
|
||||||
Reference in new issue
Block a user