Skip to content

Commit e3426b7

Browse files
committed
render fake data and add collapse feature
1 parent 44ba97d commit e3426b7

File tree

5 files changed

+93
-36
lines changed

5 files changed

+93
-36
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"react-dom": "^18.1.0",
2626
"react-router-dom": "^6.3.0",
2727
"react-scripts": "5.0.1",
28+
"react-spinners": "^0.13.4",
2829
"styled-components": "^5.3.5",
2930
"web-vitals": "^2.1.4"
3031
},

src/activity/events/EventsList.js

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useState, useEffect } from "react";
2+
import { PacmanLoader } from "react-spinners";
3+
import { eventsMap as eventsList } from "../fakeData";
24
import "./events.css";
35

46
function EventsList() {
@@ -10,46 +12,59 @@ function EventsList() {
1012
}
1113
export default EventsList;
1214

13-
// TODO: Remove eventsList when using fakeData.js
14-
const eventsList = [
15-
{
16-
id: 1,
17-
title: "Event #1",
18-
month: "Jul",
19-
day: "01",
20-
location: "Room101",
21-
time: "3:00pm",
22-
},
23-
{
24-
id: 2,
25-
title:
26-
"Event #2 Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
27-
month: "Aug",
28-
day: "08",
29-
location: "Room202",
30-
time: "4:00pm",
31-
},
32-
];
33-
3415
function ListEvents() {
35-
return eventsList.map(singleEvent => {
36-
const click = () => {
37-
console.log("Clicked");
38-
};
16+
const [isCollapse, setCollapse] = useState(false);
17+
const [index, setIndex] = useState(null);
18+
19+
function handleClick(id) {
20+
setCollapse(!isCollapse);
21+
setIndex(id);
22+
console.log("Clicked", isCollapse);
23+
console.log(id);
24+
}
3925

26+
const [isLoading, setLoading] = useState(false);
27+
useEffect(() => {
28+
setLoading(true);
29+
setTimeout(() => {
30+
setLoading(false);
31+
}, 2000);
32+
}, []);
33+
34+
return eventsList.map(singleEvent => {
4035
return (
4136
<button
42-
className="event"
4337
key={singleEvent.id}
38+
className="event"
4439
type="button"
45-
onClick={click}
40+
onClick={() => handleClick(singleEvent.id)}
4641
>
4742
<div className="event-date">
4843
<p id="month">{singleEvent.month}</p>
4944
<p id="day">{singleEvent.day}</p>
5045
</div>
5146
<div className="event-info">
5247
<h3 id="title">{singleEvent.title}</h3>
48+
49+
{isCollapse &&
50+
singleEvent.id === index &&
51+
(isLoading ? (
52+
<PacmanLoader
53+
cssOverride={{
54+
margin: 10,
55+
}}
56+
size={30}
57+
color="orange"
58+
loadding={isLoading}
59+
/>
60+
) : (
61+
<div className="event-expand">
62+
<img src={singleEvent.image} alt="event" />
63+
<p>Details: </p>
64+
<p>{singleEvent.description}</p>
65+
</div>
66+
))}
67+
5368
<p id="important">Time: {singleEvent.time}</p>
5469
<p id="important">Location: {singleEvent.location}</p>
5570
</div>

src/activity/events/events.css

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@
8989

9090
.event-date {
9191
display: inline-block;
92-
padding: 0 0.75rem 0 0.25rem;
92+
padding: 0 0.5rem 0 0.25rem;
9393
vertical-align: top;
9494
color: white;
9595
font-weight: normal;
9696
}
9797

9898
.event-date p {
99-
margin: 0;
99+
margin: 0 0.5rem 0 0;
100100
padding: inherit;
101101
}
102102

@@ -128,10 +128,30 @@
128128

129129
.event-info #important {
130130
display: inline-block;
131-
margin: 0px 20px 5px 0;
131+
margin: 0px 20px 10px 0;
132132
padding: 3px 10px;
133133
font-size: 16px;
134134
color: black;
135135
border-radius: 5px;
136136
background-color: white;
137137
}
138+
139+
.event-expand {
140+
margin-top: 20px;
141+
margin-right: 20px;
142+
color: white;
143+
font-size: 18px;
144+
}
145+
146+
.event-expand p {
147+
margin: 2rem 2rem 2rem 0;
148+
}
149+
150+
.event-expand img {
151+
max-width: 640px;
152+
max-height: 300px;
153+
}
154+
155+
.loading {
156+
margin: auto;
157+
}

src/activity/fakeData.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ const eventsMap = [];
55
for (let i = 1; i <= 20; i += 1) {
66
const title = faker.company.catchPhrase();
77
const description = faker.lorem.paragraph(3);
8-
const location = faker.address.buildingNumber();
9-
const image = faker.image.nature(640, 480, true);
10-
11-
const dateTime = faker.date.recent(30);
12-
const date = dateTime.toLocaleDateString();
8+
const location = `Room ${faker.address.buildingNumber()}`;
9+
const image = faker.image.nature(640, 360, true);
10+
11+
const dateTime = faker.date.future(60);
12+
const day =
13+
dateTime.getDate() < 10
14+
? `0${dateTime.getDate().toLocaleString()}`
15+
: dateTime.getDate().toLocaleString();
16+
const month = dateTime.toLocaleString("en-US", { month: "short" });
1317
const time = dateTime.toLocaleTimeString();
1418

1519
eventsMap.push({
1620
id: i,
1721
title,
1822
description,
19-
date,
23+
day,
24+
month,
2025
time,
2126
location,
2227
image,

0 commit comments

Comments
 (0)