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