Skip to content

Commit

Permalink
Load more pagination type implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cain committed May 14, 2018
1 parent 1a2030a commit a97a669
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
18 changes: 17 additions & 1 deletion assets/app.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions assets/app.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions liveblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ public static function enqueue_scripts() {
'is_liveblog_editable' => self::is_liveblog_editable(),
'current_user' => self::get_current_user(),
'socketio_enabled' => WPCOM_Liveblog_Socketio_Loader::is_enabled(),
'paginationType' => 'page',

'key' => self::KEY,
'nonce_key' => self::NONCE_KEY,
Expand Down
3 changes: 2 additions & 1 deletion src/react/actions/apiActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export const getEntriesPaginated = (page, scrollTo) => ({
scrollTo,
});

export const getEntriesSuccess = (payload, renderNewEntries) => ({
export const getEntriesSuccess = (payload, renderNewEntries, paginationType) => ({
type: types.GET_ENTRIES_SUCCESS,
payload,
renderNewEntries,
paginationType,
});

export const getEntriesFailed = () => ({
Expand Down
8 changes: 4 additions & 4 deletions src/react/containers/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class AppContainer extends Component {

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

return (
<div style={{ position: 'relative' }}>
{(page === 1 && canEdit) && <EditorContainer isEditing={false} />}
{(page === 1 || paginationTypeLoadMore) && canEdit && <EditorContainer isEditing={false} />}
<UpdateButton polling={polling} click={() => mergePolling()} />
<PaginationContainer />
{!paginationTypeLoadMore && <PaginationContainer /> }
<Entries loading={loading} entries={entries} />
<PaginationContainer />
{this.eventsContainer && <EventsContainer container={this.eventsContainer} />}
Expand All @@ -61,8 +62,7 @@ const mapStateToProps = state => ({
page: state.pagination.page,
loading: state.api.loading,
entries: Object.keys(state.api.entries)
.map(key => state.api.entries[key])
.slice(0, state.config.entries_per_page),
.map(key => state.api.entries[key]),
polling: Object.keys(state.polling.entries),
config: state.config,
});
Expand Down
17 changes: 16 additions & 1 deletion src/react/containers/PaginationContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import * as userActions from '../actions/userActions';

class PaginationContainer extends Component {
render() {
const { page, pages, getEntriesPaginated } = this.props;
const { page, pages, getEntriesPaginated, paginationType } = this.props;

if (paginationType === 'loadMore') {
return (
<div className="liveblog-pagination">
{page !== pages &&
<button
className="liveblog-btn liveblog-pagination-btn liveblog-pagination-next"
onClick={() => getEntriesPaginated(page + 1)}
>
Load More
</button>}
</div>
);
}
return (
<div className="liveblog-pagination">
<div>
Expand Down Expand Up @@ -53,11 +66,13 @@ PaginationContainer.propTypes = {
page: PropTypes.number,
pages: PropTypes.number,
getEntriesPaginated: PropTypes.func,
paginationType: PropTypes.string,
};

const mapStateToProps = state => ({
page: state.pagination.page,
pages: state.pagination.pages,
paginationType: state.config.paginationType,
});

const mapDispatchToProps = dispatch =>
Expand Down
1 change: 1 addition & 0 deletions src/react/epics/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const getPaginatedEntriesEpic = (action$, store) =>
store.getState().api.entries,
store.getState().polling.entries,
),
store.getState().config.paginationType,
)),
of(scrollToEntry(getScrollToId(res.response.entries, scrollTo))),
),
Expand Down
2 changes: 1 addition & 1 deletion src/react/epics/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const mergePollingEpic = (action$, store) =>
const entries = Object.keys(polling.entries).map(key => polling.entries[key]);
const pages = Math.max(pagination.pages, polling.pages);

if (pagination.page === 1) {
if (pagination.page === 1 || config.paginationType === 'loadMore') {
return concat(
of(mergePollingIntoEntries(entries, pages)),
of(scrollToEntry(`id_${entries[entries.length - 1].id}`)),
Expand Down
5 changes: 4 additions & 1 deletion src/react/reducers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const api = (state = initialState, action) => {
...state,
error: false,
loading: false,
entries: applyUpdate({}, action.payload.entries),
entries: applyUpdate(
action.paginationType === 'loadMore' ? state.entries : {},
action.payload.entries,
),
newestEntry: getNewestEntry(
state.newestEntry,
action.payload.entries[0],
Expand Down

0 comments on commit a97a669

Please sign in to comment.