Skip to content

Commit 1bc7e9f

Browse files
committed
Load more pagination type implementation
1 parent 8485777 commit 1bc7e9f

File tree

9 files changed

+46
-13
lines changed

9 files changed

+46
-13
lines changed

assets/app.js

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

assets/app.js.map

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

liveblog.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ public static function enqueue_scripts() {
10011001
'is_liveblog_editable' => self::is_liveblog_editable(),
10021002
'current_user' => self::get_current_user(),
10031003
'socketio_enabled' => WPCOM_Liveblog_Socketio_Loader::is_enabled(),
1004+
'paginationType' => 'page',
10041005

10051006
'key' => self::KEY,
10061007
'nonce_key' => self::NONCE_KEY,

src/react/actions/apiActions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export const getEntriesPaginated = (page, scrollTo) => ({
1212
scrollTo,
1313
});
1414

15-
export const getEntriesSuccess = (payload, renderNewEntries) => ({
15+
export const getEntriesSuccess = (payload, renderNewEntries, paginationType) => ({
1616
type: types.GET_ENTRIES_SUCCESS,
1717
payload,
1818
renderNewEntries,
19+
paginationType,
1920
});
2021

2122
export const getEntriesFailed = () => ({

src/react/containers/AppContainer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ class AppContainer extends Component {
2828

2929
render() {
3030
const { page, loading, entries, polling, mergePolling, config } = this.props;
31+
const paginationTypeLoadMore = config.paginationType === 'loadMore';
3132
const canEdit = config.is_liveblog_editable === '1';
3233

3334
return (
3435
<div style={{ position: 'relative' }}>
35-
{(page === 1 && canEdit) && <EditorContainer isEditing={false} />}
36+
{(page === 1 || paginationTypeLoadMore) && canEdit && <EditorContainer isEditing={false} />}
3637
<UpdateButton polling={polling} click={() => mergePolling()} />
37-
<PaginationContainer />
38+
{!paginationTypeLoadMore && <PaginationContainer /> }
3839
<Entries loading={loading} entries={entries} />
3940
<PaginationContainer />
4041
{this.eventsContainer && <EventsContainer container={this.eventsContainer} />}
@@ -61,8 +62,7 @@ const mapStateToProps = state => ({
6162
page: state.pagination.page,
6263
loading: state.api.loading,
6364
entries: Object.keys(state.api.entries)
64-
.map(key => state.api.entries[key])
65-
.slice(0, state.config.entries_per_page),
65+
.map(key => state.api.entries[key]),
6666
polling: Object.keys(state.polling.entries),
6767
config: state.config,
6868
});

src/react/containers/PaginationContainer.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@ import * as userActions from '../actions/userActions';
77

88
class PaginationContainer extends Component {
99
render() {
10-
const { page, pages, getEntriesPaginated } = this.props;
10+
const { page, pages, getEntriesPaginated, paginationType } = this.props;
1111

12+
if (paginationType === 'loadMore') {
13+
return (
14+
<div className="liveblog-pagination">
15+
{page !== pages &&
16+
<button
17+
className="liveblog-btn liveblog-pagination-btn liveblog-pagination-next"
18+
onClick={() => getEntriesPaginated(page + 1)}
19+
>
20+
Load More
21+
</button>}
22+
</div>
23+
);
24+
}
1225
return (
1326
<div className="liveblog-pagination">
1427
<div>
@@ -53,11 +66,13 @@ PaginationContainer.propTypes = {
5366
page: PropTypes.number,
5467
pages: PropTypes.number,
5568
getEntriesPaginated: PropTypes.func,
69+
paginationType: PropTypes.string,
5670
};
5771

5872
const mapStateToProps = state => ({
5973
page: state.pagination.page,
6074
pages: state.pagination.pages,
75+
paginationType: state.config.paginationType,
6176
});
6277

6378
const mapDispatchToProps = dispatch =>

src/react/epics/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const getPaginatedEntriesEpic = (action$, store) =>
8080
store.getState().api.entries,
8181
store.getState().polling.entries,
8282
),
83+
store.getState().config.paginationType,
8384
)),
8485
of(scrollToEntry(getScrollToId(res.response.entries, scrollTo))),
8586
),

src/react/epics/polling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const mergePollingEpic = (action$, store) =>
5454
const entries = Object.keys(polling.entries).map(key => polling.entries[key]);
5555
const pages = Math.max(pagination.pages, polling.pages);
5656

57-
if (pagination.page === 1) {
57+
if (pagination.page === 1 || config.paginationType === 'loadMore') {
5858
return concat(
5959
of(mergePollingIntoEntries(entries, pages)),
6060
of(scrollToEntry(`id_${entries[entries.length - 1].id}`)),

src/react/reducers/api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export const api = (state = initialState, action) => {
2828
...state,
2929
error: false,
3030
loading: false,
31-
entries: applyUpdate({}, action.payload.entries),
31+
entries: applyUpdate(
32+
action.paginationType === 'loadMore' ? state.entries : {},
33+
action.payload.entries,
34+
),
3235
newestEntry: getNewestEntry(
3336
state.newestEntry,
3437
action.payload.entries[0],

0 commit comments

Comments
 (0)