Merge branch 'Dashboard' into restructure

This commit is contained in:
Harrison Deng 2022-04-05 20:00:28 -05:00
commit 911e5a2c79
5 changed files with 85 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import propTypes from "prop-types"; import propTypes from "prop-types";
import MatchInfoCard from "./MatchInfoCard"; import MatchInfoCard from "./MatchInfoCard";
import "../styles/MatchInfoCardDisplay.css";
export default class MatchInfoCardDisplay extends React.Component { export default class MatchInfoCardDisplay extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);

View File

@ -0,0 +1,26 @@
import React from "react";
import { Card } from "react-bootstrap";
import propTypes from "prop-types";
export default class SportInfoCard extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<Card style={{ width: "20rem" }}>
<Card.Body>
<Card.Title>{this.props.sport.name}</Card.Title>
<Card.Subtitle className="mb-2 text-muted">{this.props.sport.minPlayers.toString()}</Card.Subtitle>
<Card.Text>
<p>{this.props.sport.description}</p>
</Card.Text>
</Card.Body>
</Card>
);
}
}
SportInfoCard.propTypes = {
sport: propTypes.object,
};

View File

@ -0,0 +1,24 @@
import React from "react";
import propTypes from "prop-types";
import SportInfoCard from "./SportInfoCard";
import "../styles/MatchInfoCardDisplay.css";
export default class SportInfoCardDisplay extends React.Component {
constructor(props) {
super(props);
}
render() {
let sports = null;
if(this.props.recommendedsports && this.props.recommendedsports.length > 0) {
sports = this.props.recommendedsports.map((sport) => <SportInfoCard key={sport._id} sport={sport}></SportInfoCard>);
}
return (
<div className="horizontal-scroller">
{sports}
</div>
);
}
}
SportInfoCardDisplay.propTypes = {
recommendedsports: propTypes.array,
};

View File

@ -3,7 +3,8 @@ import { Button, InputGroup, FormControl } from "react-bootstrap";
import "../styles/Dashboard.css"; import "../styles/Dashboard.css";
import { apiClient } from "../utils/httpClients.js"; import { apiClient } from "../utils/httpClients.js";
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay"; import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
import { needUser } from "../utils/routing.js"; import SportInfoCardDisplay from "../components/SportInfoCardDisplay";
// import { needUser } from "../utils/routing.js";
export default class Dashboard extends React.Component { export default class Dashboard extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -13,11 +14,16 @@ export default class Dashboard extends React.Component {
displayedEquipment: [], displayedEquipment: [],
user: null user: null
}; };
this.getFirstName(); // 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() { 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. await this.latestMatches();
this.setState({ displayedMatches: await this.latestMatches() }); await this.availableSports();
// await this.availableEquipment();
} }
async latestMatches() { async latestMatches() {
let recentMatchesRes = await apiClient.get("/match/recent/15"); let recentMatchesRes = await apiClient.get("/match/recent/15");
@ -26,26 +32,26 @@ export default class Dashboard extends React.Component {
} }
} }
async availableMatches() { async availableSports() {
let availableMatchesRes = await apiClient.get("/sports"); let availableSportsRes = await apiClient.get("/sport");
if (availableMatchesRes.status === 200) { if (availableSportsRes.status === 200) {
this.setState({ displayedSports: availableMatchesRes.data.recent }); this.setState({ displayedSports: availableSportsRes.data.recent });
} }
} }
async availableEquipment() { // async availableEquipment() {
let availableEquipmentRes = await apiClient.get("/rentals"); // let availableEquipmentRes = await apiClient.get("/rentals");
if (availableEquipmentRes.status === 200) { // if (availableEquipmentRes.status === 200) {
this.setState({ displayedEquipment: availableEquipmentRes.data.recent }); // this.setState({ displayedEquipment: availableEquipmentRes.data.recent });
} // }
} // }
async getFirstName() { // async getFirstName() {
// let result = await apiClient.post("/user/login", {"email": "johndoe@gmail.com", "password": "csc309h1"}).then(apiClient.get("/user")); // // let result = await apiClient.post("/user/login", {"email": "johndoe@gmail.com", "password": "csc309h1"}).then(apiClient.get("/user"));
let user = await apiClient.get("/user"); // let user = await apiClient.get("/user");
let tags = document.getElementsByTagName("h1"); // let tags = document.getElementsByTagName("h1");
tags[0].innerHTML = user.firstName; // tags[0].innerHTML = user.firstName;
} // }
render() { render() {
return ( return (
<React.Fragment> <React.Fragment>
@ -66,12 +72,13 @@ export default class Dashboard extends React.Component {
</div> </div>
<div className="p-4"> <div className="p-4">
<h2>Available Sports</h2> <h2>Available Sports</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedSports} /> <SportInfoCardDisplay recommendedsports={this.state.displayedSports} />
</div> </div>
<div className="p-4"> {/* <div className="p-4">
<h2>Available Equipment</h2> <h2>Available Equipment</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedEquipment} /> <MatchInfoCardDisplay recommendedmatches={this.state.displayedEquipment} />
</div> </div> */}
</React.Fragment> </React.Fragment>
); );
} }

View File

@ -0,0 +1,4 @@
.horizontal-scroller{
display: flex;
overflow-x: auto;
}