Skip to content

Commit e67a0ae

Browse files
authored
Merge pull request #36 from rubydevi/f/switch-buttons
Switch buttons and Display reserved rockets in My profile - Filters
2 parents 9f5b2d2 + ecca6ba commit e67a0ae

File tree

6 files changed

+100
-18
lines changed

6 files changed

+100
-18
lines changed

src/components/Profile.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1+
import React from 'react';
12
import Container from 'react-bootstrap/Container';
2-
import Row from 'react-bootstrap/Row';
33
import JoinedMissions from './JoinedMissions';
44
import ReservedRockets from './ReservedRockets';
55
import ReservedDragons from './ReservedDragons';
6+
import '../styles/Profile.css';
67

78
const ProfileComponent = () => (
89
<Container>
9-
<Row>
10-
<table>
10+
<div className="profile-table-container">
11+
<table className="profile-table">
1112
<thead>
1213
<tr>
1314
<th>My Missions</th>
14-
<th>My Rockets</th>
15-
<th>My Dragons</th>
1615
</tr>
1716
</thead>
1817
<tbody>
1918
<tr>
2019
<td>
2120
<JoinedMissions />
2221
</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
26+
<table className="profile-table">
27+
<thead>
28+
<tr>
29+
<th>My Rockets</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<tr>
2334
<td>
2435
<ReservedRockets />
2536
</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
41+
<table className="profile-table">
42+
<thead>
43+
<tr>
44+
<th>My Dragons</th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
<tr>
2649
<td>
2750
<ReservedDragons />
2851
</td>
2952
</tr>
3053
</tbody>
3154
</table>
32-
</Row>
33-
55+
</div>
3456
</Container>
3557
);
58+
3659
export default ProfileComponent;

src/components/ReservedRockets.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import React from 'react';
2+
import { useSelector } from 'react-redux';
23

3-
const ReservedRockets = () => (
4-
<div>ReservedRockets</div>
5-
);
4+
const ReservedRockets = () => {
5+
const rockets = useSelector((state) => state.rockets.rockets);
6+
const reservedRockets = rockets.filter((rocket) => rocket.reserved === true);
7+
8+
if (reservedRockets.length === 0) {
9+
return <div>You have no reserved rockets.</div>;
10+
}
11+
12+
return (
13+
<ul className="reserved-rockets">
14+
{reservedRockets.map((rocket) => (
15+
<li className="reserved-rocket" key={rocket.id}>{rocket.name}</li>
16+
))}
17+
</ul>
18+
);
19+
};
620

721
export default ReservedRockets;

src/components/Rocket.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ const Rocket = ({ rocket }) => {
2929
{rocket.description}
3030
</p>
3131
</div>
32-
<button className="reserve-button" type="submit" onClick={handleReserveRocket}>
33-
Reserve Rocket
34-
</button>
35-
<button className="cancel-button" type="submit" onClick={handleCancelRocket}>
36-
Cancel Reservation
37-
</button>
32+
{!rocket.reserved ? (
33+
<button className="reserve-button" type="submit" onClick={handleReserveRocket}>
34+
Reserve Rocket
35+
</button>
36+
) : (
37+
<button className="cancel-button" type="submit" onClick={handleCancelRocket}>
38+
Cancel Reservation
39+
</button>
40+
)}
3841
</div>
3942
</li>
4043
);

src/components/Rockets.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ const RocketsComponent = () => {
1111
const error = useSelector((state) => state.rockets.error);
1212

1313
useEffect(() => {
14-
dispatch(fetchRockets());
15-
}, [dispatch]);
14+
if (rockets.length === 0) {
15+
dispatch(fetchRockets());
16+
}
17+
}, [dispatch, rockets.length]);
1618

1719
if (loading) {
1820
return (

src/styles/Profile.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.profile-table-container {
2+
display: flex;
3+
justify-content: space-between;
4+
}
5+
6+
.profile-table {
7+
border-collapse: collapse;
8+
width: 30%; /* Adjust the width as needed */
9+
}
10+
11+
.profile-table th {
12+
padding: 10px;
13+
}
14+
15+
.profile-row {
16+
border-bottom: 1px solid #ccc;
17+
padding-bottom: 10px;
18+
margin-bottom: 10px;
19+
}
20+
21+
.profile-table tbody tr:nth-child(odd) {
22+
background-color: #f8f8f8;
23+
}
24+
25+
.profile-table tbody tr:hover {
26+
background-color: #f0f0f0;
27+
}

src/styles/ReservedRockets.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.reserved-rockets {
2+
margin: 0;
3+
padding: 0;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: flex-start;
7+
}
8+
9+
.reserved-rocket {
10+
padding: 3% 5%;
11+
border: 1px solid;
12+
width: 100%;
13+
}

0 commit comments

Comments
 (0)