Skip to content

Commit e390688

Browse files
committed
dynamic card
1 parent 393e005 commit e390688

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

frontend/family_tree/src/App.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import './App.css';
33
import Help from './Components/Help.js';
44
import SearchBar from "./Components/SearchBar";
@@ -17,7 +17,16 @@ function App() {
1717
}
1818
});
1919

20-
const x = StudentData[0];
20+
const [name, setCardName] = useState("name");
21+
const [branch, setCardBranch] = useState("branch");
22+
const [year, setCardYear] = useState("year");
23+
const [email, setCardEmail] = useState("email");
24+
const [picture, setCardPicture] = useState("picture");
25+
const [linkedIn, setCardLinkedIn] = useState("name");
26+
const [hometown, setCardHometown] = useState("name");
27+
const [coCurriculars, setCardCoCurriculars] = useState("");
28+
const [socialMedia, setCardSocialMedia] = useState("name");
29+
const [display, setCardDisplay] = useState(true);
2130

2231
return (
2332
<ThemeProvider theme={theme}>
@@ -27,20 +36,29 @@ function App() {
2736
<Help />
2837
</div>
2938

30-
<D3Tree />
39+
<D3Tree setCardName={setCardName}
40+
setCardBranch={setCardBranch}
41+
setCardYear={setCardYear}
42+
setCardEmail={setCardEmail}
43+
setCardPicture={setCardPicture}
44+
setCardLinkedIn={setCardLinkedIn}
45+
setCardHometown={setCardHometown}
46+
setCardCoCurriculars={setCardCoCurriculars}
47+
setCardSocialMedia={setCardSocialMedia}
48+
setCardDisplay = {setCardDisplay}
49+
/>
3150

32-
<PCard
33-
id={x.student.id}
34-
branch={x.student.branch}
35-
name={x.student.name}
36-
year={x.student.year}
37-
email={x.student.email}
38-
picture={x.student.picture}
39-
linkedIn={x.student.linkedIn}
40-
hometown={x.student.hometown}
41-
coCurriculars={x.student.coCurriculars}
42-
socialMedia={x.student.socialMedia}
43-
display= {true}
51+
<PCard
52+
branch={branch}
53+
name={name}
54+
year={year}
55+
email={email}
56+
picture={picture}
57+
linkedIn={linkedIn}
58+
hometown={hometown}
59+
coCurriculars={coCurriculars}
60+
socialMedia={socialMedia}
61+
display= {display}
4462
/>
4563
</div>
4664
</ThemeProvider>

frontend/family_tree/src/Components/ProfileCard.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ function PCard(props) {
113113
<Divider variant="middle" />
114114
<br />
115115
<Box sx={{ color: "#2a4158" ,textAlign:"center"}}>
116-
{props.coCurriculars.map((item) => (
116+
{/* {props.coCurriculars.map((item) => (
117117
<Typography variant="body2" key={item} gutterBottom>
118118
{item}
119119
</Typography>
120-
))}
120+
))} */}
121+
{props.coCurriculars}
121122
</Box>
122123
</React.Fragment>
123124
)}

frontend/family_tree/src/Components/Tree.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as d3 from 'd3';
22
import StudentData from "../Data1.json";
33
import React, { useLayoutEffect } from "react";
44

5-
function D3Tree(){
5+
function D3Tree(props){
66
useLayoutEffect(() =>{
77
var width = window.innerWidth;
88
var height = window.innerHeight;
@@ -56,7 +56,19 @@ function D3Tree(){
5656
.attr("transform", function(d) {
5757
return "translate(" + source.x0 + "," + source.y0 + ")";
5858
})
59-
.on('click', click);
59+
.on('click', click)
60+
.on('contextmenu', function(node,d){
61+
props.setCardName(d.id);
62+
props.setCardBranch(d.data.student.branch);
63+
props.setCardYear(d.data.student.year);
64+
props.setCardEmail(d.data.student.email);
65+
props.setCardPicture(d.data.student.picture);
66+
props.setCardLinkedIn(d.data.student.linkedIn);
67+
props.setCardHometown(d.data.student.hometown);
68+
props.setCardCoCurriculars(d.data.student.coCurriculars);
69+
props.setCardSocialMedia(d.data.student.socialMedia);
70+
props.setCardDisplay(true);
71+
});
6072

6173
nodeEnter.append('circle')
6274
.attr('class', 'node')

frontend/family_tree/src/Data1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
"email": "dummy@gmail.com",
219219
"picture": "url",
220220
"linkedIn": "url",
221-
"hometown": "",
221+
"hometown": "Gujarat",
222222
"coCurriculars": [],
223223
"socialMedia": { "insta": "link" }
224224
},

0 commit comments

Comments
 (0)