2022-04-05 02:19:08 -04:00
import React from "react" ;
2022-04-05 13:16:09 -04:00
import { Button , InputGroup , FormControl } from "react-bootstrap" ;
import "../styles/Dashboard.css" ;
2022-04-05 14:52:19 -05:00
import { apiClient } from "../utils/httpClients.js" ;
2022-04-05 14:51:15 -04:00
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay" ;
2022-04-05 20:17:50 -04:00
import SportInfoCardDisplay from "../components/SportInfoCardDisplay" ;
// import { needUser } from "../utils/routing.js";
2022-04-05 14:52:19 -05:00
export default class Dashboard extends React . Component {
2022-04-05 02:19:08 -04:00
constructor ( props ) {
super ( props ) ;
2022-04-05 13:16:09 -04:00
this . state = {
displayedMatches : [ ] ,
2022-04-05 14:51:15 -04:00
displayedSports : [ ] ,
2022-04-05 14:52:19 -05:00
displayedEquipment : [ ] ,
user : null
2022-04-05 13:16:09 -04:00
} ;
2022-04-05 20:17:50 -04:00
// this.getFirstName();
2022-04-05 14:51:15 -04:00
}
2022-04-05 20:17:50 -04:00
// async componentDidMount() {
// this.setState({ user: await needUser() }); // needUser says this page needs a user, and therefore, if there isn't a user, get them to login first. It returns the authenticated user.
// this.setState({ displayedMatches: await this.latestMatches() });
// }
2022-04-05 14:51:15 -04:00
async componentDidMount ( ) {
2022-04-05 20:17:50 -04:00
await this . latestMatches ( ) ;
await this . availableSports ( ) ;
// await this.availableEquipment();
2022-04-05 13:16:09 -04:00
}
2022-04-05 14:51:15 -04:00
async latestMatches ( ) {
let recentMatchesRes = await apiClient . get ( "/match/recent/15" ) ;
if ( recentMatchesRes . status === 200 ) {
this . setState ( { displayedMatches : recentMatchesRes . data . recent } ) ;
}
}
2022-04-05 20:17:50 -04:00
async availableSports ( ) {
let availableSportsRes = await apiClient . get ( "/sport" ) ;
if ( availableSportsRes . status === 200 ) {
this . setState ( { displayedSports : availableSportsRes . data . recent } ) ;
2022-04-05 14:51:15 -04:00
}
}
2022-04-05 20:17:50 -04:00
// async availableEquipment() {
// let availableEquipmentRes = await apiClient.get("/rentals");
// if (availableEquipmentRes.status === 200) {
// this.setState({ displayedEquipment: availableEquipmentRes.data.recent });
// }
// }
2022-04-05 14:51:15 -04:00
2022-04-05 20:17:50 -04:00
// async getFirstName() {
// // let result = await apiClient.post("/user/login", {"email": "johndoe@gmail.com", "password": "csc309h1"}).then(apiClient.get("/user"));
// let user = await apiClient.get("/user");
// let tags = document.getElementsByTagName("h1");
// tags[0].innerHTML = user.firstName;
// }
2022-04-05 02:19:08 -04:00
render ( ) {
2022-04-05 14:52:19 -05:00
return (
2022-04-05 13:16:09 -04:00
< React . Fragment >
2022-04-05 14:51:15 -04:00
< h1 > < / h 1 >
2022-04-05 13:16:09 -04:00
< InputGroup className = "w-50" >
< FormControl
placeholder = "Search for Matches"
aria - label = "Search Bar"
aria - describedby = "basic-addon2"
/ >
< Button variant = "outline-secondary" id = "button-addon2" >
2022-04-05 14:52:19 -05:00
Search
2022-04-05 13:16:09 -04:00
< / B u t t o n >
< / I n p u t G r o u p >
2022-04-05 14:51:15 -04:00
< div className = "p-4" >
< h2 > Available Matches < / h 2 >
< MatchInfoCardDisplay recommendedmatches = { this . state . displayedMatches } / >
< / d i v >
< div className = "p-4" >
< h2 > Available Sports < / h 2 >
2022-04-05 20:17:50 -04:00
< SportInfoCardDisplay recommendedsports = { this . state . displayedSports } / >
2022-04-05 14:51:15 -04:00
< / d i v >
2022-04-05 20:17:50 -04:00
{ / * < d i v c l a s s N a m e = " p - 4 " >
2022-04-05 14:51:15 -04:00
< h2 > Available Equipment < / h 2 >
< MatchInfoCardDisplay recommendedmatches = { this . state . displayedEquipment } / >
2022-04-05 20:17:50 -04:00
< /div> */ }
2022-04-05 13:16:09 -04:00
< / R e a c t . F r a g m e n t >
) ;
2022-04-05 02:19:08 -04:00
}
}