Skip to content

Commit

Permalink
Sudo (#130)
Browse files Browse the repository at this point in the history
Workspace card Data fetching done
  • Loading branch information
yp969803 authored Dec 28, 2023
2 parents 464ae61 + 41f3bfa commit 32df801
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 20 deletions.
23 changes: 18 additions & 5 deletions src/app/api/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios, { AxiosResponse } from 'axios';
import { BACKEND_URL } from 'envConstants';

export interface projectBody {
Expand All @@ -7,6 +7,19 @@ export interface projectBody {
link: string;
}

export interface GetProject{
id: number,
name: string,
description: string
}

export interface Member{
[key: string]:string
}
export interface ProjectMembers{
members:Member
}

export const addProject = async (
authorizationToken: string,
orgName: string,
Expand Down Expand Up @@ -146,14 +159,14 @@ export const getProject = async (
authorizationToken: string,
projectName: string,
orgName: string
) => {
):Promise<AxiosResponse<GetProject>> => {
const url =
BACKEND_URL +
'/api/protected/project/getProject/' +
projectName +
'/' +
orgName;
const response = await axios.get(url, {
const response = await axios.get<GetProject>(url, {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${authorizationToken}`,
Expand All @@ -166,14 +179,14 @@ export const getMembers = async (
authorizationToken: string,
projectName: string,
orgName: string
) => {
) : Promise<AxiosResponse<ProjectMembers>>=> {
const url =
BACKEND_URL +
'/api/protected/project/getMembers/' +
projectName +
'/' +
orgName;
const response = await axios.get(url, {
const response = await axios.get<ProjectMembers>(url, {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${authorizationToken}`,
Expand Down
1 change: 1 addition & 0 deletions src/app/constants/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const AVATAR_URL="https://api.multiavatar.com"
1 change: 1 addition & 0 deletions src/envConstants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const CLIENT_ID = '149d2857118e05e729a8';
export const BACKEND_URL = 'http://localhost:8080';
export const AVATAR_API= "w9zrqHdDa4MsYB";
65 changes: 54 additions & 11 deletions src/features/home/components/projectCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react';
import React, { useState } from 'react';
import './index.scss';

import axios from 'axios';
import { getMembers, getProject } from 'app/api/project';
import { useQuery } from 'react-query';
import { GetProject } from 'app/api/project';
import { ProjectMembers } from 'app/api/project';
import { AVATAR_URL } from 'app/constants/api';
import { AVATAR_API } from 'envConstants';
interface Props{
projectName: string,
orgName: string,
status: {
archeive: boolean,
bookmark: boolean,
Expand All @@ -16,15 +23,45 @@ import './index.scss';
}


const ProjectCard: React.FC<Props> = ({projectName, status, githubData}) => {



const ProjectCard: React.FC<Props> = ({projectName,orgName ,status, githubData}) => {
const token= localStorage.getItem('token')

const [ProjectData,SetProjectData]= useState<GetProject|null>(null)
const [projectMembers,setProjectMembers]= useState<ProjectMembers|null>(null)

const fetchProjectData= async()=>{
if(token!=null){
const project_data= await getProject(token,projectName, orgName);
SetProjectData(project_data.data)
return project_data.data
}else{
return null
}
}

const fetchProjectMembers=async()=>{
if(token!=null){
const members= await getMembers(token,projectName,orgName);
setProjectMembers(members.data)
return members.data

}
}


const {data:project_data}= useQuery(`${projectName}${orgName}`,fetchProjectData)
const {data: project_members}= useQuery(`${projectName}${orgName}Members`, fetchProjectMembers);



return (
<div className='projectcard'>
<h1>{projectName}</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Cum
repudiandae ex corporis quasi sequi porro est, tenetur ipsam assumenda
ab ratione recusandae atque quaerat. Voluptatem incidunt illo optio
aperiam consequuntur.
{project_data?project_data.description:<></>}
</p>
<div className='projectcard-status'>
<div>
Expand All @@ -41,12 +78,18 @@ const ProjectCard: React.FC<Props> = ({projectName, status, githubData}) => {
</div>
</div>

{/* <ul className='projectcard-contributor'>
<li>A</li>
<ul className='projectcard-contributor'>
{/* <li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul> */}
<li>D</li> */}
{
project_members&&Object.entries(project_members).slice(0,4).map(([key,value])=>{
const url= AVATAR_URL+"/"+key+".png?apikey="+AVATAR_API
return <li><img src={url} /></li>
})
}
</ul>
</div>
);
};
Expand Down
7 changes: 4 additions & 3 deletions src/features/home/components/projectCardContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { ProjectsGithubData } from 'app/api/githubData';
const arr = [1, 2, 3, 4, 5];
interface Props{
weekly: boolean,
orgName: string,
orgProjects: Projects | null,
monthlyOrgProjectsData:ProjectsGithubData | null,
weeklyOrgProjectsData: ProjectsGithubData | null
}

const ProjectCardCont: React.FC<Props> = ({weekly, orgProjects, monthlyOrgProjectsData, weeklyOrgProjectsData}) => {
const ProjectCardCont: React.FC<Props> = ({weekly,orgName ,orgProjects, monthlyOrgProjectsData, weeklyOrgProjectsData}) => {


const [archeive,setArcheive]= useState<boolean>(false);
Expand All @@ -32,13 +33,13 @@ const ProjectCardCont: React.FC<Props> = ({weekly, orgProjects, monthlyOrgProjec
githubData= weeklyOrgProjectsData[key]
}

return <ProjectCard key={key} projectName={key} status={value} githubData={githubData}/>;
return <ProjectCard key={key} orgName={orgName} projectName={key} status={value} githubData={githubData}/>;
}else{
let githubData=null
if(monthlyOrgProjectsData){
githubData= monthlyOrgProjectsData[key]
}
return <ProjectCard key={key} projectName={key} status={value} githubData={githubData}/>;
return <ProjectCard key={key} orgName={orgName} projectName={key} status={value} githubData={githubData}/>;

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const Home = () => {
</div>:

<div className='home-main-cont'>
<ProjectCardCont weekly={weekly} orgProjects={orgProjects} monthlyOrgProjectsData={monthlyOrgProjectsData} weeklyOrgProjectsData={weeklyOrgProjectsData}/>
<ProjectCardCont weekly={weekly} orgName={orgName} orgProjects={orgProjects} monthlyOrgProjectsData={monthlyOrgProjectsData} weeklyOrgProjectsData={weeklyOrgProjectsData}/>
<LeaderBoard />
</div>
}
Expand Down
1 change: 1 addition & 0 deletions src/features/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Login = () => {
navigate('/')

}catch(e){
localStorage.removeItem('token')
navigate('/login')
}

Expand Down

0 comments on commit 32df801

Please sign in to comment.