Skip to content

Commit

Permalink
Fix Notify
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Jul 8, 2017
1 parent 9625989 commit 42a5e23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/containers/ColumnSearch/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions app/containers/ColumnSearch/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -108,28 +109,31 @@ 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} イラスト`,
id: illustId,
})
}
}

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) {
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions app/containers/ColumnSearch/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 42a5e23

Please sign in to comment.