forked from UBC-LA-Hackathon/student-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscussion.js
36 lines (30 loc) · 902 Bytes
/
Discussion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { useState, useEffect } from 'react'
import Heatmap from './Heatmap'
import Dropdown from './Dropdown'
function Discussion () {
const [discussion, setDiscussion] = useState([])
const [timestamps, setTimestamps] = useState([])
const [selected, setSelected] = useState(null)
// add useEffect here for discussion
useEffect(() => {
if (selected){
fetch('http://localhost:4001/getDiscussions/'+selected)
.then(res => res.json())
.then(data => setDiscussion(data))
}
}, [selected])
useEffect(() => {
if (discussion.length > 0) {
const discussionTimestamps = discussion
.map(discussion => discussion.timestamp)
setTimestamps(discussionTimestamps)
}
}, [discussion])
return (
<div>
<Heatmap timestamps={timestamps} />
<Dropdown handleSelect={setSelected} />
</div>
)
}
export default Discussion