mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:49:45 +00:00
Сверстать страницу проектов, сделать временное хранилище проектов, скорректировать маршрутизацию
This commit is contained in:
1 parent
b4fdabc853
commit
cb69de3427
9 files changed
+63
-14
No files matched your search
+14
-1
@@ -2,6 +2,7 @@ import * as WPAPI from 'wpapi';
|
|||||||
import { flatten } from 'lodash';
|
import { flatten } from 'lodash';
|
||||||
|
|
||||||
import reactPress from './reactPress';
|
import reactPress from './reactPress';
|
||||||
|
import projects from './projects.json';
|
||||||
|
|
||||||
const wp = new WPAPI(
|
const wp = new WPAPI(
|
||||||
process.env.NODE_ENV === 'development'
|
process.env.NODE_ENV === 'development'
|
||||||
@@ -69,7 +70,6 @@ export async function getMedia(category, target = false) {
|
|||||||
for (let media of mediaLibrary[category]) {
|
for (let media of mediaLibrary[category]) {
|
||||||
target[media.name].image = media.image;
|
target[media.name].image = media.image;
|
||||||
target[media.name].id = media.id;
|
target[media.name].id = media.id;
|
||||||
console.log(target[media.name].id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
@@ -80,4 +80,17 @@ export async function getMedia(category, target = false) {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getProjects(id) {
|
||||||
|
try {
|
||||||
|
if (typeof id != 'undefined') {
|
||||||
|
return projects[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return projects;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ function Projects() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader className="header">
|
<PageHeader className="header">
|
||||||
<h1>Projects</h1>
|
<h1>Проекты</h1>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<PageContent className="content">
|
<PageContent className="content">
|
||||||
|
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { useLoaderData, useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
import { PageHeader, PageContent } from "../../components";
|
||||||
|
import { getProjects } from "../../../api";
|
||||||
|
|
||||||
|
export async function loader() {
|
||||||
|
const projects = await getProjects();
|
||||||
|
return { projects };
|
||||||
|
}
|
||||||
|
|
||||||
|
function Project() {
|
||||||
|
const params = useParams();
|
||||||
|
const projectID = params.id;
|
||||||
|
|
||||||
|
const { projects } = useLoaderData();
|
||||||
|
const project = projects[projectID];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<PageHeader className="header">
|
||||||
|
<h1>{project.name}</h1>
|
||||||
|
</PageHeader>
|
||||||
|
<PageContent className="content">
|
||||||
|
<p>{project.desc}</p>
|
||||||
|
</PageContent>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Project;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default as Project, loader } from "./Project";
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Outlet } from "react-router-dom";
|
import { Outlet } from "react-router-dom";
|
||||||
import { createContext, useEffect } from 'react';
|
import { createContext, useEffect } from 'react';
|
||||||
|
|
||||||
import { getMedia } from "../../api";
|
import { getProjects } from "../../api";
|
||||||
import useElementOnScreen from '../../lib/useElementOnScreen';
|
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';
|
||||||
@@ -9,11 +9,6 @@ import './Root.styles.scss';
|
|||||||
|
|
||||||
export const RootContext = createContext();
|
export const RootContext = createContext();
|
||||||
|
|
||||||
async function loader() {
|
|
||||||
const media = getMedia();
|
|
||||||
return { media };
|
|
||||||
}
|
|
||||||
|
|
||||||
function Root() {
|
function Root() {
|
||||||
const [setRef, isVisible] = useElementOnScreen({
|
const [setRef, isVisible] = useElementOnScreen({
|
||||||
root: null,
|
root: null,
|
||||||
@@ -43,5 +38,4 @@ function Root() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { loader };
|
|
||||||
export default Root;
|
export default Root;
|
||||||
@@ -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 ErrorPage} from './ErrorPage';
|
||||||
export { default as Main } from './Main';
|
export { default as Main } from './Main';
|
||||||
export { default as AboutUs } from './AboutUs';
|
export { default as AboutUs } from './AboutUs';
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"tag": "ambr",
|
||||||
|
"name": "Амброзия",
|
||||||
|
"desc": "Невероятный проект, завоевавший сердца жителей Таганрога."
|
||||||
|
}
|
||||||
|
]
|
||||||
+6
-2
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Root,
|
Root,
|
||||||
loader as rootLoader,
|
|
||||||
ErrorPage,
|
ErrorPage,
|
||||||
Main,
|
Main,
|
||||||
AboutUs,
|
AboutUs,
|
||||||
@@ -8,13 +7,13 @@ import {
|
|||||||
Projects,
|
Projects,
|
||||||
Contact
|
Contact
|
||||||
} from './pages';
|
} from './pages';
|
||||||
|
import { Project, loader as projectsLoader } from './pages/Projects/components';
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
element: <Root />,
|
element: <Root />,
|
||||||
errorElement: <ErrorPage />,
|
errorElement: <ErrorPage />,
|
||||||
loader: rootLoader,
|
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
@@ -32,6 +31,11 @@ const routes = [
|
|||||||
path: "/projects",
|
path: "/projects",
|
||||||
element: <Projects />,
|
element: <Projects />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/projects/:id",
|
||||||
|
element: <Project />,
|
||||||
|
loader: projectsLoader,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/contact",
|
path: "/contact",
|
||||||
element: <Contact />,
|
element: <Contact />,
|
||||||
|
|||||||
Reference in new issue
Block a user