2017-06-21 23:31:59 +00:00
|
|
|
// @flow
|
2017-06-22 21:16:21 +00:00
|
|
|
import { takeEvery, put, call } from 'redux-saga/effects';
|
|
|
|
import { delay } from 'redux-saga';
|
2017-07-03 23:59:27 +00:00
|
|
|
import type { Effect } from 'redux-saga/effects';
|
2017-06-22 21:16:21 +00:00
|
|
|
import { closeNotification } from 'actions/notifications';
|
|
|
|
import type { ShowNotificationAction } from 'actions/notifications';
|
2017-06-21 23:31:59 +00:00
|
|
|
|
2017-07-03 23:59:27 +00:00
|
|
|
function* handleNotification(action?: ShowNotificationAction) {
|
2017-07-04 03:21:19 +00:00
|
|
|
if (!action) return;
|
|
|
|
const { duration } = action.payload;
|
|
|
|
// show forever
|
2017-07-31 23:14:30 +00:00
|
|
|
if (duration === 0 || duration === 'infinity') {
|
2017-07-04 03:21:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-06-21 23:31:59 +00:00
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
// FIXME
|
|
|
|
yield call(delay, duration || 5000);
|
|
|
|
yield put(closeNotification(action.payload));
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 23:59:27 +00:00
|
|
|
export default function* notificationsSaga(): Generator<Effect, void, any> {
|
2017-07-04 03:21:19 +00:00
|
|
|
yield takeEvery('SHOW_NOTIFICATION', handleNotification);
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|