Skip to content

Commit

Permalink
components for join created
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitcoffee committed Jan 9, 2024
1 parent 8d0a0b1 commit 1716467
Show file tree
Hide file tree
Showing 32 changed files with 198 additions and 42 deletions.
Binary file added public/img/icons/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 32 additions & 16 deletions server/routes/league.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ router.get('/', rejectUnauthenticated, (req, res) => {
;
});

// GET info on a specific league
router.get('/:id', rejectUnauthenticated, (req, res) => {
let queryText = `
SELECT * FROM "leagues"
JOIN "teams_leagues" ON "teams_leagues"."league_id" = "leagues"."id"
WHERE "leagues"."id" = $1;
`;
pool.query(queryText,[req.params.id])
.then((result) => {res.send(result.rows)})
.catch((error) => {
console.error("Error in league/:id GET", error);
res.sendStatus(500);
})
;
});

// Create league
router.post('/', rejectUnauthenticated, (req, res) => {
let queryText = `
Expand Down Expand Up @@ -83,4 +67,36 @@ router.post('/', rejectUnauthenticated, (req, res) => {
})
});

// GET a specific league
router.get('/:id', rejectUnauthenticated, (req, res) => {
console.log(`Triggered GET ${req.params.id}`);
let queryText = `
SELECT
leagues.*,
COUNT(DISTINCT teams_leagues.team_id) AS teams_joined,
MAX(users_teams.team_id) AS user_team_id,
MAX(teams.team_name) AS user_team_name
FROM
leagues
JOIN
users_leagues ON leagues.id = users_leagues.league_id
LEFT JOIN
teams_leagues ON leagues.id = teams_leagues.league_id
LEFT JOIN
users_teams ON teams_leagues.team_id = users_teams.team_id AND users_leagues.user_id = users_teams.user_id
LEFT JOIN
teams ON users_teams.team_id = teams.id
WHERE
users_leagues.user_id = $1 AND leagues.id = $2
GROUP BY "leagues"."id";
`;
pool.query(queryText,[req.user.id, req.params.id])
.then((result) => {res.send(result.rows[0])})
.catch((error) => {
console.error("Error in specific league GET", error);
res.sendStatus(500);
})
;
});

module.exports = router;
19 changes: 18 additions & 1 deletion server/routes/team.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,24 @@ router.get('/:id', rejectUnauthenticated, (req,res) => {
JOIN "user" ON "user"."id" = "users_teams"."user_id"
WHERE "teams"."id" = $1;
`;
pool.query(queryText[req.params.id])
pool.query(queryText,[req.params.id])
.then((result) => {
res.send(result.rows)
})
.catch((error) => {
console.error("Error in GET teamid", error);
res.sendStatus(500);
})
})

router.get('/roster/:id', rejectUnauthenticated, (req,res) => {
let queryText = `
SELECT * FROM "teams"
JOIN "users_teams" ON "users_teams"."team_id" = "teams"."id"
JOIN "user" ON "user"."id" = "users_teams"."user_id"
WHERE "teams"."id" = $1;
`;
pool.query(queryText,[req.params.id])
.then((result) => {
res.send(result.rows)
})
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions src/components/AdminPage/LeagueAdminPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import './LeagueAdminPage.css';

// Component showing overall league stats and top players
function LeagueAdminPage(){
return(
<div>

</div>
)
}

export default LeagueAdminPage;
11 changes: 8 additions & 3 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import RegisterPage from '../RegisterPage/RegisterPage';
import './App.css';
import EditUserPage from '../EditUserPage/EditUserPage.jsx';
import CreateLeague from '../CreateLeague/CreateLeague.jsx';
import JoinLeague from '../JoinLeague/JoinLeague.jsx';
import TeamPage from '../TeamPage/TeamPage.jsx';
import CreateTeam from '../CreateTeam/CreateTeam.jsx';
import LeagueDetails from '../LeagueDetails/LeagueDetails.jsx';
import JoinTeam from '../JoinTeam/JoinTeam.jsx';

function App() {
const dispatch = useDispatch();
Expand Down Expand Up @@ -93,14 +94,18 @@ function App() {
<CreateTeam/>
</ProtectedRoute>

<ProtectedRoute exact path="/joinLeague">
<JoinLeague/>
<ProtectedRoute exact path="/joinTeam">
<JoinTeam/>
</ProtectedRoute>

<ProtectedRoute exact path="/teamdetails/:leagueid/:teamid">
<TeamPage/>
</ProtectedRoute>

<ProtectedRoute exact path="/leaguedetails/:leagueid/">
<LeagueDetails/>
</ProtectedRoute>

<Route
exact
path="/login"
Expand Down
6 changes: 6 additions & 0 deletions src/components/Home/Home.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#create-join-btns {
text-align: center;
}

#join-team-btn {
display: block;
margin-left: auto;
margin-right: auto;
}
9 changes: 6 additions & 3 deletions src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ function Home(){
history.push("/createLeague");
}

const joinLeague = () => {
history.push("/joinLeague");
const joinTeam = () => {
history.push("/joinTeam");
}

if (userLeagues.length > 0){
return(
<div>
<LeagueList/>
<br/>
<br/>
<button id="join-team-btn" onClick={joinTeam} className="btn">Join Team</button>
</div>
)
}
Expand All @@ -38,7 +41,7 @@ function Home(){
<br/><br/>
<button onClick={createLeague} className="btn">Create League</button>
<br/><br/>
<button onClick={joinLeague} className="btn">Join League</button>
<button onClick={joinTeam} className="btn">Join Team</button>
</div>
)
}
Expand Down
13 changes: 0 additions & 13 deletions src/components/JoinLeague/JoinLeague.jsx

This file was deleted.

4 changes: 4 additions & 0 deletions src/components/JoinTeam/JoinTeam.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#join-team-form {
display: block;
text-align: center;
}
44 changes: 44 additions & 0 deletions src/components/JoinTeam/JoinTeam.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import './JoinTeam.css';

// Component showing details of the league
function JoinTeam(){
const dispatch = useDispatch();
const [joinCode, setJoinCode] = useState("");
const user = useSelector(store=>store.user);
const userLeague = useSelector(store=>store.userLeague);

const handleSubmit = (e) =>{
e.preventDefault();
dispatch({type: "JOIN_TEAM", payload: {user: user, code: joinCode}});
};

const handleChange = (e) => {
setJoinCode(e.target.value);
};

// TODO: If join code syntax changes, the maxLength on input needs to be changed as well.
return(
<div>
<img id="landing-logo" src={'./img/corner-pocket_624x624.png'} alt={'logo'}/>
<br/>
<form id="join-team-form" onSubmit={handleSubmit}>
<label htmlFor="code-input">Enter Code (case-sensative)</label>
<br/><br/>
<input
name="code-input"
type="text"
value={joinCode}
onChange={handleChange}
placeholder='Enter Code'
maxLength={6}
></input>
<br/><br/>
<button className='btn'>Join Team</button>
</form>
</div>
)
}

export default JoinTeam;
Empty file.
35 changes: 35 additions & 0 deletions src/components/LeagueDetails/LeagueDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import LeagueAdminPage from '../AdminPage/LeagueAdminPage';
import './LeagueDetails.css';

// Component showing details of the league
function LeagueDetails(){
const dispatch = useDispatch();
const leagueId = useParams().leagueid;
const user = useSelector(store=>store.user);
const userLeague = useSelector(store=>store.userLeague);

useEffect(()=>{
dispatch({type: "FETCH_LEAGUE", payload: {id: leagueId}});
}, []);

if (user.id == userLeague.owner_id){
return(
<div>
<h3>{userLeague.league_name}</h3>
<LeagueAdminPage/>
</div>
)
}
else {
return(
<div>
<h3>{userLeague.league_name}</h3>
</div>
)
}
}

export default LeagueDetails;
1 change: 1 addition & 0 deletions src/components/LeagueList/LeagueList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function LeagueList(){
<div key={league.id}>
<h3
className="league-list-item"
onClick={()=>history.push(`/leaguedetails/${league.id}`)}
>{league.league_name}
</h3>
<div className='league-list-details'>
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions src/components/TeamAdminPage/TeamAdminPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import './TeamAdminPage.css';

// Component showing overall league stats and top players
function TeamAdminPage(){
return(
<div>

</div>
)
}

export default TeamAdminPage;
22 changes: 16 additions & 6 deletions src/components/TeamPage/TeamPage.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import React, { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { useParams } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import './TeamPage.css';

// Shows team roster with some base stats.
// Clicking on player opens player detail view
function TeamPage(){
const dispatch = useDispatch();

const teamId = useParams().teamid;
const userTeam = useSelector(store=>store.userTeam);

useEffect(() => {
dispatch({type: 'FETCH_LEAGUES'});
dispatch({type: "FETCH_TEAMS"})
dispatch({type: "FETCH_TEAMS"});
dispatch({type: "FETCH_TEAM", payload: {id: teamId}})
}, []);

return(
<div>
<div>

</div>
<h3>{userTeam.team_name}</h3>
<h5>Join code - {userTeam.join_code}</h5>
<h5>Roster:</h5>
<ul>
{userTeam.map((user)=>{
return(
<li key={user.id}>{user.first_name + " " + user.last_name}</li>
)})}
</ul>
</div>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/redux/sagas/_root.saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import userSaga from './user.saga';
import updateUserSaga from './updateUser.saga';
import activitiesSaga from './getActivities.saga';
import createLeagueSaga from './createLeague.saga';
import leagueSaga from './getLeague.saga';
import leaguesSaga from './getLeagues.saga';
import teamsSaga from './getTeams.saga';
import createTeamSaga from './createTeam.saga';
Expand All @@ -25,6 +26,7 @@ export default function* rootSaga() {
updateUserSaga(),
activitiesSaga(),
createLeagueSaga(),
leagueSaga(),
leaguesSaga(),
teamsSaga(),
teamSaga(),
Expand Down

0 comments on commit 1716467

Please sign in to comment.