Added cards and scroll styling

This commit is contained in:
Piyush Sharma 2022-04-05 20:17:50 -04:00
parent b2c4178482
commit 8f46ad77b8
5 changed files with 85 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import React from "react";
import propTypes from "prop-types";
import MatchInfoCard from "./MatchInfoCard";
import "../styles/MatchInfoCardDisplay.css";
export default class MatchInfoCardDisplay extends React.Component {
constructor(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 { apiClient } from "../utils/httpClients.js";
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 {
constructor(props) {
super(props);
@ -13,11 +14,16 @@ export default class Dashboard extends React.Component {
displayedEquipment: [],
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() {
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() });
await this.latestMatches();
await this.availableSports();
// await this.availableEquipment();
}
async latestMatches() {
let recentMatchesRes = await apiClient.get("/match/recent/15");
@ -26,26 +32,26 @@ export default class Dashboard extends React.Component {
}
}
async availableMatches() {
let availableMatchesRes = await apiClient.get("/sports");
if (availableMatchesRes.status === 200) {
this.setState({ displayedSports: availableMatchesRes.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 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;
}
// 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>
@ -66,12 +72,13 @@ export default class Dashboard extends React.Component {
</div>
<div className="p-4">
<h2>Available Sports</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedSports} />
<SportInfoCardDisplay recommendedsports={this.state.displayedSports} />
</div>
<div className="p-4">
{/* <div className="p-4">
<h2>Available Equipment</h2>
<MatchInfoCardDisplay recommendedmatches={this.state.displayedEquipment} />
</div>
</div> */}
</React.Fragment>
);
}

View File

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