2022-04-05 20:17:50 -04:00

85 lines
3.3 KiB
JavaScript

import React from "react";
import { Button, InputGroup, FormControl } from "react-bootstrap";
import "../styles/Dashboard.css";
import { apiClient } from "../utils/httpClients.js";
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
import SportInfoCardDisplay from "../components/SportInfoCardDisplay";
// import { needUser } from "../utils/routing.js";
export default class Dashboard extends React.Component {
constructor(props) {
super(props);
this.state = {
displayedMatches: [],
displayedSports: [],
displayedEquipment: [],
user: null
};
// this.getFirstName();
}
// 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() });
// }
async componentDidMount() {
await this.latestMatches();
await this.availableSports();
// await this.availableEquipment();
}
async latestMatches() {
let recentMatchesRes = await apiClient.get("/match/recent/15");
if (recentMatchesRes.status === 200) {
this.setState({ displayedMatches: recentMatchesRes.data.recent });
}
}
async availableSports() {
let availableSportsRes = await apiClient.get("/sport");
if (availableSportsRes.status === 200) {
this.setState({ displayedSports: availableSportsRes.data.recent });
}
}
// async availableEquipment() {
// let availableEquipmentRes = await apiClient.get("/rentals");
// if (availableEquipmentRes.status === 200) {
// this.setState({ displayedEquipment: availableEquipmentRes.data.recent });
// }
// }
// 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;
// }
render() {
return (
<React.Fragment>
<h1></h1>
<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>
<div className="p-4">
<h2>Available Matches</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedMatches} />
</div>
<div className="p-4">
<h2>Available Sports</h2>
<SportInfoCardDisplay recommendedsports={this.state.displayedSports} />
</div>
{/* <div className="p-4">
<h2>Available Equipment</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedEquipment} />
</div> */}
</React.Fragment>
);
}
}