Skip to content

Commit 4710232

Browse files
committed
add button for each scenario
1 parent 4fb60bb commit 4710232

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

forkify/src/js/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const controlSearchResults = async function () {
4242

4343
// 3) Render results
4444
// resultsView.render(model.state.search.results); // its calling ALL
45-
resultsView.render(model.getSearchResultsPage(1));
45+
resultsView.render(model.getSearchResultsPage(6));
4646

4747
// 4) Render initial pagination button
4848
paginationView.render(model.state.search);

forkify/src/js/views/paginationView.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,56 @@ class PaginationView extends View {
66
_parentElement = document.querySelector('.pagination');
77

88
_generateMarkup() {
9+
const curPage = this._data.page;
910
// calculate how many pages we need
1011
const numPages = Math.ceil(
1112
this._data.results.length / this._data.resultsPerPage
1213
);
1314
console.log(numPages);
1415

1516
// Page 1 and there are other pages
16-
if (this._data.page === 1 && numPages > 1) {
17-
return 'page 1';
17+
if (curPage === 1 && numPages > 1) {
18+
return `
19+
<button class="btn--inline pagination__btn--next">
20+
<span>Page ${curPage + 1}</span>
21+
<svg class="search__icon">
22+
<use href="${icons}#icon-arrow-right"></use>
23+
</svg>
24+
</button>
25+
`;
1826
}
27+
1928
// Last page
20-
if (this._data.page === numPages && numPages > 1) {
21-
return 'Last Page';
29+
if (curPage === numPages && numPages > 1) {
30+
return `
31+
<button class="btn--inline pagination__btn--prev">
32+
<svg class="search__icon">
33+
<use href="${icons}#icon-arrow-left"></use>
34+
</svg>
35+
<span>Page ${curPage - 1}</span>
36+
</button>
37+
`;
2238
}
2339
// Other page
24-
if (this._data.page < numPages) {
25-
return 'other page';
40+
if (curPage < numPages) {
41+
return `
42+
<button class="btn--inline pagination__btn--prev">
43+
<svg class="search__icon">
44+
<use href="${icons}#icon-arrow-left"></use>
45+
</svg>
46+
<span>Page ${curPage - 1}</span>
47+
</button>
48+
<button class="btn--inline pagination__btn--next">
49+
<span>Page ${curPage + 1}</span>
50+
<svg class="search__icon">
51+
<use href="${icons}#icon-arrow-right"></use>
52+
</svg>
53+
</button>
54+
`;
2655
}
2756

2857
// page 1, and there are NO other pages
29-
return 'only 1 page';
58+
return '';
3059
}
3160
}
3261

0 commit comments

Comments
 (0)