Skip to content

Commit b0db9e3

Browse files
authored
Merge pull request #35 from yaseerokino/counter
Add function to count and render number of meals
2 parents 2257ac3 + fbd2083 commit b0db9e3

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
<p>Ready Meals</p>
2222
</div>
2323
<div class="nav-buttons">
24-
<a href="index.html" class="nav-button">Home</a>
24+
<a href="index.html" class="nav-button"
25+
>Meals(<span id="meal-counter"></span>)</a
26+
>
2527
<a href="#Planets" class="nav-button">Planets</a>
2628
<a href="#Races" class="nav-button">Races</a>
2729
</div>

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import './style/style.css';
22

33
import API from './modules/data';
4+
import counter from './modules/counter';
45
import render from './modules/render/meals';
56

7+
const mealCounter = document.getElementById('meal-counter');
8+
69
const endpoint = 'https://www.themealdb.com/api/json/v1/1/';
710
const likesEndpoint = 'https://us-central1-involvement-api.cloudfunctions.net/capstoneApi/apps/lvQFdeSbvijlsDX1Y4VY/likes/';
811

@@ -12,7 +15,9 @@ const displayMeals = () => {
1215
API.getLikes(likesEndpoint),
1316
]).then((data) => {
1417
render(data[0], data[1]);
18+
const length = counter.meals(data[0].meals);
19+
mealCounter.innerText = length;
1520
});
1621
};
1722

18-
window.addEventListener('load', displayMeals);
23+
window.addEventListener('load', displayMeals);

src/modules/counter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const counter = {
2+
meals: (allMeals) => allMeals.length,
3+
comments: (allComments) => allComments.length,
4+
reservation: (allReservations) => allReservations.length,
5+
};
6+
7+
export default counter;

src/style/style.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ footer {
201201
border-radius: 1em;
202202
box-shadow: rgba(100, 100, 111, 0.5) 0 10px 20px 0;
203203
justify-content: center;
204-
text-align: center;
205204
}
206205

207206
.modal-header {
@@ -212,7 +211,6 @@ footer {
212211
.modal-details {
213212
display: flex;
214213
gap: 2em;
215-
flex-direction: column;
216214
}
217215

218216
.modal-img {
@@ -343,14 +341,11 @@ input {
343341
}
344342

345343
.comment-form {
346-
margin: auto;
347344
font-family: 'Space Grotesk', sans-serif;
348345
margin-top: 2em;
349346
display: flex;
350347
flex-direction: column;
351348
gap: 1em;
352-
width: 70%;
353-
text-align: center;
354349
}
355350

356351
.no-comments {
@@ -364,7 +359,6 @@ input {
364359
display: flex;
365360
flex-direction: column;
366361
gap: 1em;
367-
align-items: center;
368362
width: 100%;
369363
}
370364

0 commit comments

Comments
 (0)