From 7ed3b371b3f066e621445229575faeff7b1a3881 Mon Sep 17 00:00:00 2001 From: Dmitry Patsura Date: Sat, 24 Feb 2018 12:35:00 +0900 Subject: [PATCH] Feature: AccountNotifications - improve sync --- actions/account-notifications.js | 12 ++---------- constants/index.js | 2 +- reducers/account-notifications.js | 3 +++ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/actions/account-notifications.js b/actions/account-notifications.js index f6881a8..94d7042 100644 --- a/actions/account-notifications.js +++ b/actions/account-notifications.js @@ -14,13 +14,7 @@ import Realm from 'utils/realm'; import { paginateBySlice } from 'utils/paginate'; export function trySyncNotifications(): ThunkAction { - return (dispatch: Dispatch, getState: GetState) => { - const state = getState(); - - if (state.accountNotifications && state.accountNotifications.sync) { - return; - } - + return (dispatch: Dispatch) => { dispatch(syncNotifications()); }; } @@ -49,9 +43,7 @@ export function syncNotifications(): ThunkAction { function (result, page) { dispatch({ type: ACCOUNT_NOTIFICATIONS_SYNC_PROGRESS, - payload: { - page - } + payload: page }); Realm.write( diff --git a/constants/index.js b/constants/index.js index 77aa60e..6d91d5c 100644 --- a/constants/index.js +++ b/constants/index.js @@ -81,7 +81,7 @@ export const NAVIGATION_SET_TITLE = 'NAVIGATION_SET_TITLE'; export const NAVIGATION_HOME = 'NAVIGATION_HOME'; export const NAVIGATION_LOGIN = 'NAVIGATION_LOGIN'; -export const ACCOUNT_NOTIFICATIONS_LIMIT = 30; +export const ACCOUNT_NOTIFICATIONS_LIMIT = 50; export const ACCOUNT_ISSUES_LIMIT = 30; export const ACCOUNT_FEED_LIMIT = 30; export const ACCOUNT_PULL_REQUESTS_LIMIT = 30; diff --git a/reducers/account-notifications.js b/reducers/account-notifications.js index ed4e278..03c8aa4 100644 --- a/reducers/account-notifications.js +++ b/reducers/account-notifications.js @@ -10,12 +10,14 @@ import { export type AccountNotificationsState = { // first list fetch loading: boolean, + page: number, sync: boolean, error: Object|string|null, } const initialState: AccountNotificationsState = { loading: false, + page: 0, error: null, }; @@ -32,6 +34,7 @@ export default (state: AccountNotificationsState = initialState, action: Object) case ACCOUNT_NOTIFICATIONS_SYNC_PROGRESS: { return { ...state, + page: action.payload, sync: true, loading: false, };