Skip to content

Commit 37191e1

Browse files
committed
Add supported change page in home page
1 parent 9897ff0 commit 37191e1

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

apps/php/guru-include/private/pages/index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
'typeIds' => getStore('guru_selected_types'),
1111
'str' => $searchStr,
1212
'per-page' => $config['perPage'],
13+
'page' => $page,
1314
]);
15+
1416
$cities = getApi('/cities');
1517
$types = getApi('/performance/types');
18+
$pagination = isset($events->pagination) ? $events->pagination : [];
1619

1720
// STORE
1821
$selectedTypesStore = explode(',', getStore('guru_selected_types'));
@@ -108,6 +111,11 @@
108111
</div>
109112
<? } ?>
110113
</div>
114+
<? if(!empty($pagination) && $pagination->pageCount > 1 && $pagination->currentPage < $pagination->pageCount) { ?>
115+
<div class="col-12 text-center">
116+
<a class="btn btn-outline-primary js-load-next-page" data-current="<?= $pagination->currentPage ?>" href="?page=<?= $pagination->currentPage+1 ?>&searchStr=<?= $str ?>">Еще...</a>
117+
</div>
118+
<? } ?>
111119
<div id="js-event-poster-template" style="display: none;">
112120
<div class="event-poster">
113121
<a href="?event=">

apps/php/guru-include/public/js/app.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Инициализируем переменные
33
*/
44
let currentPage = 1;
5+
let lastPage = 1;
56
let currentObjectId = 0;
67
let currentDate = 0;
78

@@ -30,6 +31,7 @@ $(document).ready(function(){
3031
date.setSeconds(0);
3132

3233
currentDate = parseInt(date.getTime()/1000);
34+
currentPage = 1;
3335
loadData();
3436
}
3537
});
@@ -41,6 +43,7 @@ $(document).ready(function(){
4143
// Устанавливаем текст выбранного города
4244
loadCity();
4345
// Перезагружаем данные
46+
currentPage = 1;
4447
loadData();
4548
});
4649

@@ -75,6 +78,7 @@ $(document).ready(function(){
7578
});
7679

7780
setCookie('guru_selected_types', types.join(','));
81+
currentPage = 1;
7882
loadData();
7983
});
8084

@@ -109,28 +113,50 @@ $(document).ready(function(){
109113
loadSessions();
110114
});
111115

116+
/**
117+
* Метод загрузки данных при смене страницы
118+
*/
119+
$('.js-load-next-page').on('click', function(e) {
120+
e.preventDefault();
121+
122+
currentPage += 1;
123+
loadData(true);
124+
});
112125
});
113126

114127
/**
115128
* Метод загрузки данных при событии
116129
*/
117-
function loadData() {
130+
function loadData(isSave) {
118131
$.ajax({
119132
url: $config.server + $config.prefix + "/sellers/performance/distibution",
120133
data: {
121134
lang: $config.language,
122135
cityId: getCookie('guru_selected_city_id'),
123136
typeIds: getCookie('guru_selected_types'),
124137
date: currentDate,
138+
page: currentPage,
125139
'per-page': $config.perPage
126140
},
127141
success: function(data) {
128142
// Чистим блок с карточками мероприятий
129-
$('.events-block').html('');
143+
if (!isSave) {
144+
$('.events-block').html('');
145+
}
130146

131147
if (data && data.data && data.data.length) {
132148
$('.js-no-result').addClass('d-none');
133149

150+
if (data.pagination) {
151+
lastPage = data.pagination.pageCount;
152+
153+
if (lastPage > currentPage) {
154+
$('.js-load-next-page').show();
155+
} else {
156+
$('.js-load-next-page').hide();
157+
}
158+
}
159+
134160
data.data.forEach(function (event) {
135161
let el = $('#js-event-poster-template .event-poster').clone();
136162

apps/php/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$config = require('config.php');
1818
$eventId = (int)$_GET['event'];
1919
$searchStr = $_GET['str'];
20+
$page = (int)$_GET['page'] ? : 1;
2021

2122
?>
2223

0 commit comments

Comments
 (0)