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";
|
|
|
|
import { apiClient } from "../utils/httpClients";
|
2022-04-05 14:51:15 -04:00
|
|
|
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
|
2022-04-05 02:19:08 -04:00
|
|
|
export default class Dashboard extends React.Component{
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2022-04-05 13:16:09 -04:00
|
|
|
this.state = {
|
|
|
|
displayedMatches: [],
|
2022-04-05 14:51:15 -04:00
|
|
|
displayedSports: [],
|
|
|
|
displayedEquipment: []
|
2022-04-05 13:16:09 -04:00
|
|
|
};
|
2022-04-05 14:51:15 -04:00
|
|
|
this.getFirstName();
|
|
|
|
}
|
|
|
|
async componentDidMount() {
|
|
|
|
await this.latestMatches();
|
|
|
|
|
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 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async availableMatches() {
|
|
|
|
let availableMatchesRes = await apiClient.get("/sports");
|
|
|
|
if (availableMatchesRes.status === 200) {
|
|
|
|
this.setState({ displayedSports: availableMatchesRes.data.recent });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async availableEquipment() {
|
|
|
|
let availableEquipmentRes = await apiClient.get("/rentals");
|
|
|
|
if (availableEquipmentRes.status === 200) {
|
|
|
|
this.setState({ displayedEquipment: availableEquipmentRes.data.recent });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-05 13:16:09 -04:00
|
|
|
async getFirstName(){
|
2022-04-05 14:51:15 -04:00
|
|
|
// let result = await apiClient.post("/user/login", {"email": "johndoe@gmail.com", "password": "csc309h1"}).then(apiClient.get("/user"));
|
2022-04-05 13:16:09 -04:00
|
|
|
let user = await apiClient.get("/user");
|
2022-04-05 14:51:15 -04:00
|
|
|
let tags = document.getElementsByTagName("h1");
|
|
|
|
tags[0].innerHTML = user.firstName;
|
2022-04-05 02:19:08 -04:00
|
|
|
}
|
|
|
|
render() {
|
2022-04-05 13:16:09 -04:00
|
|
|
return(
|
|
|
|
<React.Fragment>
|
2022-04-05 14:51:15 -04:00
|
|
|
<h1></h1>
|
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">
|
|
|
|
Search
|
|
|
|
</Button>
|
|
|
|
</InputGroup>
|
2022-04-05 14:51:15 -04:00
|
|
|
<div className="p-4">
|
|
|
|
<h2>Available Matches</h2>
|
|
|
|
<MatchInfoCardDisplay recommendedmatches={this.state.displayedMatches} />
|
|
|
|
</div>
|
|
|
|
<div className="p-4">
|
|
|
|
<h2>Available Sports</h2>
|
|
|
|
<MatchInfoCardDisplay recommendedmatches={this.state.displayedSports} />
|
|
|
|
</div>
|
|
|
|
<div className="p-4">
|
|
|
|
<h2>Available Equipment</h2>
|
|
|
|
<MatchInfoCardDisplay recommendedmatches={this.state.displayedEquipment} />
|
|
|
|
</div>
|
2022-04-05 13:16:09 -04:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
2022-04-05 02:19:08 -04:00
|
|
|
}
|
|
|
|
}
|