New component for displaying userprojects
This commit is contained in:
parent
4568d68746
commit
3fea87a88a
2 changed files with 42 additions and 31 deletions
40
frontend/src/Components/DisplayUserProjects.tsx
Normal file
40
frontend/src/Components/DisplayUserProjects.tsx
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Project } from "../Types/goTypes";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
|
||||||
|
function DisplayUserProject(): JSX.Element {
|
||||||
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
|
const getProjects = async (): Promise<void> => {
|
||||||
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
|
const response = await api.getUserProjects(token);
|
||||||
|
console.log(response);
|
||||||
|
if (response.success) {
|
||||||
|
setProjects(response.data ?? []);
|
||||||
|
} else {
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Call getProjects when the component mounts
|
||||||
|
useEffect(() => {
|
||||||
|
void getProjects();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
||||||
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||||
|
{projects.map((project, index) => (
|
||||||
|
<Link to={`/project/${project.name}`} key={index}>
|
||||||
|
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||||
|
{project.name}
|
||||||
|
</h1>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DisplayUserProject;
|
|
@ -1,39 +1,10 @@
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { Project } from "../Types/goTypes";
|
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import BasicWindow from "../Components/BasicWindow";
|
import BasicWindow from "../Components/BasicWindow";
|
||||||
import { api } from "../API/API";
|
import DisplayUserProjects from "../Components/DisplayUserProjects";
|
||||||
|
|
||||||
function UserProjectPage(): JSX.Element {
|
function UserProjectPage(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
|
||||||
|
|
||||||
const getProjects = async (): Promise<void> => {
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
const response = await api.getUserProjects(token);
|
|
||||||
console.log(response);
|
|
||||||
if (response.success) {
|
|
||||||
setProjects(response.data ?? []);
|
|
||||||
} else {
|
|
||||||
console.error(response.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Call getProjects when the component mounts
|
|
||||||
useEffect(() => {
|
|
||||||
void getProjects();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
<DisplayUserProjects />
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
|
||||||
{projects.map((project, index) => (
|
|
||||||
<Link to={`/project/${project.name}`} key={index}>
|
|
||||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
|
||||||
{project.name}
|
|
||||||
</h1>
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue