diff --git a/app/redux/FetchDataSaga.js b/app/redux/FetchDataSaga.js index d21fe74c8c..e5a15276fe 100644 --- a/app/redux/FetchDataSaga.js +++ b/app/redux/FetchDataSaga.js @@ -1,6 +1,6 @@ import {takeLatest, takeEvery} from 'redux-saga'; import {call, put, select, fork} from 'redux-saga/effects'; -import {loadFollowers} from 'app/redux/FollowSaga'; +import {loadFollows} from 'app/redux/FollowSaga'; import Apis from 'shared/api_client/ApiInstances'; import GlobalReducer from './GlobalReducer'; import constants from './constants'; @@ -16,7 +16,7 @@ export function* fetchState(location_change_action) { const {pathname, /*search*/} = location_change_action.payload; if(/@[a-z0-9\.-]+$/.test(pathname)) { const username = pathname.substring(2) - yield fork(loadFollowers, username, 'blog') + yield fork(loadFollows, "get_followers", username, 'blog') } const server_location = yield select(state => state.offchain.get('server_location')); if (pathname === server_location) return; diff --git a/app/redux/FollowSaga.js b/app/redux/FollowSaga.js index 96aaa343ba..116f3e70f7 100644 --- a/app/redux/FollowSaga.js +++ b/app/redux/FollowSaga.js @@ -3,20 +3,22 @@ import {call, put} from 'redux-saga/effects'; import {Apis} from 'shared/api_client'; // Test limit with 2 (not 1, infinate looping) -export function* loadFollowing(follower, type, start = '', limit = 100) { - const res = fromJS(yield Apis.follow('get_following', follower, start, type, limit)) +export function* loadFollows(method, follower, type, start = '', limit = 100) { + const res = fromJS(yield Apis.follow(method, follower, start, type, limit)) // console.log('res.toJS()', res.toJS()) let cnt = 0 let lastFollowing = null + const key = method === "get_following" ? "following" : "follower"; + yield put({type: 'global/UPDATE', payload: { - key: ['follow', 'get_following', follower], + key: ['follow', method, follower], notSet: Map(), updater: m => { m = m.update('result', Map(), m2 => { res.forEach(value => { cnt++ const what = value.get('what') - const following = lastFollowing = value.get('following') + const following = lastFollowing = value.get(key) m2 = m2.set(following, what) }) return m2 @@ -25,43 +27,11 @@ export function* loadFollowing(follower, type, start = '', limit = 100) { } }}) if(cnt === limit) { - yield call(loadFollowing, follower, type, lastFollowing) + yield call(loadFollows, method, follower, type, lastFollowing) } else { yield put({type: 'global/UPDATE', payload: { - key: ['follow', 'get_following', follower], + key: ['follow', method, follower], updater: m => m.merge({loading: false, error: null}) }}) } } - -// Test limit with 2 (not 1, infinate looping) -export function* loadFollowers(following, type, start = '', limit = 100) { - const res = fromJS(yield Apis.follow('get_followers', following, start, type, limit)) - // console.log('res.toJS()', res.toJS()) - let cnt = 0 - let last = null - yield put({type: 'global/UPDATE', payload: { - key: ['follow', 'get_followers', following], - notSet: Map(), - updater: m => { - m = m.update('result', Map(), m2 => { - res.forEach(value => { - cnt++ - const what = value.get('what') - const follower = last = value.get('follower') - m2 = m2.set(follower, what) - }) - return m2 - }) - return m.merge({loading: true, error: null}) - } - }}) - if(cnt === limit) { - yield call(loadFollowers, following, type, last) - } else { - yield put({type: 'global/UPDATE', payload: { - key: ['follow', 'get_following', following], - updater: m => m.merge({loading: false, error: null}) - }}) - } -} \ No newline at end of file diff --git a/app/redux/UserSaga.js b/app/redux/UserSaga.js index b4f280a898..e34e99ca0f 100644 --- a/app/redux/UserSaga.js +++ b/app/redux/UserSaga.js @@ -9,7 +9,7 @@ import {browserHistory} from 'react-router' import {serverApiLogin, serverApiLogout, /*serverApiRecordEvent*/} from 'app/utils/ServerApiClient'; import {Apis} from 'shared/api_client'; import {serverApiRecordEvent} from 'app/utils/ServerApiClient'; -import {loadFollowing} from 'app/redux/FollowSaga' +import {loadFollows} from 'app/redux/FollowSaga' export const userWatches = [ watchRemoveHighSecurityKeys, // keep first to remove keys early when a page change happens @@ -60,8 +60,8 @@ function* usernamePasswordLogin(action) { const current = yield select(state => state.user.get('current')) if(current) { const username = current.get('username') - yield fork(loadFollowing, username, 'blog') - yield fork(loadFollowing, username, 'ignore') + yield fork(loadFollows, "get_following", username, 'blog') + yield fork(loadFollows, "get_following", username, 'ignore') } }