-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgroupRoutingController.jsx
55 lines (48 loc) · 1.72 KB
/
groupRoutingController.jsx
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { useNavigate } from "react-router-dom";
import { Container } from "reactstrap";
import {useRecoilState} from "recoil";
import selectedGroupAtom from "../Recoil/selectedGroupAtom";
/**
* Returns a button that when clicked, routes user to the appropriate group playback
* @param props.group {JSON} Contains group information
* @param props.householdID {string} Current household ID
* @returns {JSX.Element} Group button
*/
export default function GroupRoutingController(props) {
// Used to change currently displayed path and send data to new path
let navigate = useNavigate();
// groupStatusState (unused) accesses and setGroupStatusState modifies the state of groupStatusAtom
const [selectedGroupState, setSelectedGroupState] = useRecoilState(selectedGroupAtom);
/**
* onClick listener of button. Updates groupStatusAtom and navigates to group's path
*/
const routeChange = () => {
// Path to navigate to for current group
let path = "../groups/" + props.group.id;
// Updates the state of selectedGroupAtom to values of this button's group
setSelectedGroupState({
groupId: props.group.id,
groupName: props.group.name,
groupGoneFlag: false
});
// Navigates to new path for current group, sending data for the group ID and household ID along with
const data = {
state: {
householdId: props.householdId,
groupId: props.group.id
},
};
navigate(path, data);
};
// Returns button with routeChange as onClick listener
return (
<div className="group_det">
<Container>
<a onClick={routeChange}>
<p className="group_ind">{props.group.name}</p>
</a>
</Container>
</div>
);
}