From 0fdfa05f24e7319ca3a639a837457323477987eb Mon Sep 17 00:00:00 2001 From: Maria Marinescu Date: Fri, 10 Jan 2025 10:55:04 +0100 Subject: [PATCH] feat: Add Project Details Modal --- src/components/projects/ProjectCard.tsx | 25 +--- src/components/projects/ProjectList.tsx | 74 ++++++++++-- src/pages/Project.tsx | 147 +++++++++--------------- 3 files changed, 123 insertions(+), 123 deletions(-) diff --git a/src/components/projects/ProjectCard.tsx b/src/components/projects/ProjectCard.tsx index af24a58..265eda6 100644 --- a/src/components/projects/ProjectCard.tsx +++ b/src/components/projects/ProjectCard.tsx @@ -2,8 +2,6 @@ import { MotionLayoutWrapper } from 'components'; import { Project as ProjectType } from 'interfaces'; import { FC } from 'react'; import { Link } from 'react-router-dom'; -import { useSetRecoilState } from 'recoil'; -import { activeProjectAtom } from '../../store/projects/activeProjectAtom'; /** * Project component displays a single project with its details. @@ -15,29 +13,16 @@ import { activeProjectAtom } from '../../store/projects/activeProjectAtom'; * @returns {JSX.Element} The rendered component */ -export const ProjectCard: FC<{ project?: ProjectType }> = ({ project }) => { - const setProjectIdInStore = useSetRecoilState(activeProjectAtom); - - // Set the project ID in the store when the component mounts - const setProjectId = () => { - if (project?.id) { - setProjectIdInStore(project); - } - }; - - // // Reset the project ID in the store when the component unmounts - // useEffect(() => { - // return () => { - // setProjectIdInStore(null); - // }; - // }, [setProjectId]); - +export const ProjectCard: FC<{ + project?: ProjectType; + setProjectDetailsModalOpen: React.Dispatch>; +}> = ({ project, setProjectDetailsModalOpen }) => { return ( setProjectDetailsModalOpen(true)} >
diff --git a/src/components/projects/ProjectList.tsx b/src/components/projects/ProjectList.tsx index 5cbfcd4..5f24899 100644 --- a/src/components/projects/ProjectList.tsx +++ b/src/components/projects/ProjectList.tsx @@ -1,23 +1,73 @@ -import { useState } from 'react'; -import { useRecoilState } from 'recoil'; +import { useCallback, useEffect, useState } from 'react'; +import { useNavigate, useParams } from 'react-router-dom'; import { projectsData } from 'src/data'; -import { activeProjectAtom } from '../../store/projects/activeProjectAtom'; +import { Project } from 'src/pages/Project'; import { ProjectCard } from './ProjectCard'; +interface Project { + id: string; + client: string; + description: string; + headline: string; + img: string; + year: string; + location: string; + tags: string[]; + referenceWebsite?: string; +} + const ProjectList = () => { const [projects] = useState(projectsData); - const projectId = useRecoilState(activeProjectAtom); + const [openProjectDetailsModal, setProjectDetailsModalOpen] = useState(false); + const [activeProject, setActiveProject] = useState(null); + const { projectId } = useParams(); + const navigate = useNavigate(); + + const setUpNewProject = useCallback(() => { + if (projectId) { + const activeProjectData = projectsData.find( + (project) => project.id === projectId + ); + if (activeProjectData) { + setActiveProject(activeProjectData); + } + } + }, [projectId]); + + useEffect(() => setUpNewProject(), [setUpNewProject]); + + useEffect(() => { + if (activeProject) { + setProjectDetailsModalOpen(true); + } + }, [activeProject]); - console.log(projectId); + const closeProjectDetailsModal = () => { + setProjectDetailsModalOpen(false); + navigate('/ji-yun/projects', { replace: true }); + }; return ( -
-
- {projects.map((project) => ( - - ))} -
-
+ <> + {openProjectDetailsModal ? ( + + ) : null} +
+
+ {projects.map((project) => ( + + ))} +
+
+ ); }; diff --git a/src/pages/Project.tsx b/src/pages/Project.tsx index 36a7baf..123eebb 100644 --- a/src/pages/Project.tsx +++ b/src/pages/Project.tsx @@ -1,107 +1,72 @@ +import { Modal } from 'components/Modal'; import { ProjectSlider } from 'components/projects'; -import { useEffect } from 'react'; -import { useParams } from 'react-router-dom'; -import { useRecoilState } from 'recoil'; -import { projectsData } from '../data/projects'; -import { activeProjectAtom } from '../store/projects/activeProjectAtom'; -const Project = () => { - const [activeStoredProject, setActiveProject] = - useRecoilState(activeProjectAtom); - const { projectId } = useParams(); +interface Project { + id: string; + client: string; + description: string; + headline: string; + img: string; + year: string; + location: string; + tags: string[]; + referenceWebsite?: string; +} +interface ProjectProps { + setProjectDetailsModalOpen?: () => void; + projectDetailsModalOpen?: boolean; + activeProject?: Project | null; +} - useEffect(() => { - if (!activeStoredProject) { - const activeProject = projectsData.find( - (project) => project.id === projectId - ); - if (activeProject) setActiveProject(activeProject); - } - }, [activeStoredProject]); +export const Project: React.FC = ({ + setProjectDetailsModalOpen, + projectDetailsModalOpen, + activeProject, +}) => { + if (!setProjectDetailsModalOpen || !activeProject || !projectDetailsModalOpen) + return null; return ( -
-

- {activeStoredProject?.client} -

-
-
- {/* Single project client details */} - - {/* Single project objectives */} -
-

- Description -

-

- {activeStoredProject?.headline} -

-
- {/*
-

-

-
*/} - - {activeStoredProject?.referenceWebsite ? ( + +
+

+ {activeProject?.client} +

+
+
-

- Website: - - {activeStoredProject.referenceWebsite} - +

+ Description +

+

+ {activeProject?.headline}

- ) : null} - - {/* Single project technologies */} - {/*
-

- {singleProjectData.ProjectInfo.Technologies[0].title} -

-

- {singleProjectData.ProjectInfo.Technologies[0].techs.join(', ')} -

-
*/} - {/* Single project social sharing */} - {/*
-

- {singleProjectData.ProjectInfo.SocialSharingHeading} -

-
- {singleProjectData.ProjectInfo.SocialSharing.map((social) => { - return ( - - {social.icon} - - ); - })} + {activeProject?.referenceWebsite ? ( + + ) : null}
-
*/} -
- {/* Single project right section */} -
-
- +
+
+ +
+
{activeProject?.description}
-
{activeStoredProject?.description}
- - {/* })} */}
-
+ ); }; - -export default Project;