From 42a5e23e2b3030a633021a602cf36332cd117544 Mon Sep 17 00:00:00 2001 From: akameco Date: Sat, 8 Jul 2017 23:08:28 +0900 Subject: [PATCH] Fix Notify --- app/containers/ColumnSearch/reducer.js | 2 +- app/containers/ColumnSearch/saga.js | 23 ++++++++++++++--------- app/containers/ColumnSearch/selectors.js | 3 +++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/containers/ColumnSearch/reducer.js b/app/containers/ColumnSearch/reducer.js index e158d1d4..2f7e4dac 100644 --- a/app/containers/ColumnSearch/reducer.js +++ b/app/containers/ColumnSearch/reducer.js @@ -26,7 +26,7 @@ export default function(state: State = initialState, action: Action): State { illustIds: [], nextUrl: null, minBookmarks: 0, - interval: ms('3m'), + interval: ms('1m'), }) case Actions.SET_NEXT_URL: diff --git a/app/containers/ColumnSearch/saga.js b/app/containers/ColumnSearch/saga.js index 07f258cc..7cd411ba 100644 --- a/app/containers/ColumnSearch/saga.js +++ b/app/containers/ColumnSearch/saga.js @@ -92,10 +92,11 @@ function* fetchUntilLimit(action: Action): Generator<*, void, *> { } } -function* fetchNew(action: Action): Generator<*, number, *> { +function* fetchNew(action: Action): Generator<*, void, *> { try { - const { illustIds, interval } = yield select( - selectors.makeSelectColumn(), + const { illustIds } = yield select(selectors.makeSelectColumn(), action) + const beforeIds = yield select( + selectors.makeLimitedSelectIllustsId(), action ) @@ -108,8 +109,13 @@ function* fetchNew(action: Action): Generator<*, number, *> { const nextIds = union(result.illusts, illustIds) yield put(actions.fetchNewSuccess(action.id, response, nextIds)) - if (illustIds.length > 0) { - const diffIllusts = difference(nextIds, illustIds) + const afterIds = yield select( + selectors.makeLimitedSelectIllustsId(), + action + ) + + const diffIllusts = difference(afterIds, beforeIds) + if (diffIllusts.length > 0) { for (const illustId of diffIllusts) { yield call(notifyWithIllust, { title: `検索新着 ${action.id} イラスト`, @@ -117,19 +123,17 @@ function* fetchNew(action: Action): Generator<*, number, *> { }) } } - - return interval } catch (err) { yield put(actions.fetchNewFailre(action.id, err)) } - return ms('5m') } // TODO キャンセル function* fetchNewWatch(action: Action) { try { while (true) { - const interval = yield call(fetchNew, action) + yield call(fetchNew, action) + const { interval } = yield select(selectors.makeSelectColumn(), action) yield delay(interval) } } catch (err) { @@ -143,6 +147,7 @@ export default function* root(): Generator<*, void, void> { yield takeEvery(Actions.FETCH, fetchUntilLimit) yield takeEvery(Actions.FETCH_NEXT, fetchUntilLimit) + yield takeEvery(Actions.SET_MIN_BOOKBOOK, fetchUntilLimit) yield takeEvery(Actions.FETCH_SUCCESS, fetchNewWatch) yield takeEvery(Actions.FETCH_NEW, fetchNewWatch) diff --git a/app/containers/ColumnSearch/selectors.js b/app/containers/ColumnSearch/selectors.js index 5c6edc48..4a441960 100644 --- a/app/containers/ColumnSearch/selectors.js +++ b/app/containers/ColumnSearch/selectors.js @@ -48,5 +48,8 @@ export const makeLimitedSelectIllusts = () => s.filter(s => s.totalBookmarks > limit) ) +export const makeLimitedSelectIllustsId = () => + createSelector(makeLimitedSelectIllusts(), s => s.map(v => v.id)) + export const makeIllustLength = () => createSelector(makeLimitedSelectIllusts(), s => s.length)