import { call, takeLatest, select } from 'redux-saga/effects';
import { TOGGLE_NOTIFICATION } from 'common/actionTypes/userSettings';
import { ENABLE_VOTING } from 'common/actionTypes/voting';
import { notify, notifyPermission } from '../../utils/notification';
import { getIssueText } from '../issue/selectors';
import { notificationIsEnabled } from '../userSettings/selectors';

function* openIssue() {
  const notificationEnabled = yield select(notificationIsEnabled);
  const { description } = yield select(getIssueText);
  if (notificationEnabled) {
    yield call(notify, description);
  }
}

function* toggleNotification() {
  const notificationEnabled = yield select(notificationIsEnabled);
  if (notificationEnabled) {
    yield call(notifyPermission);
  }
}

export default function* issueSaga() {
  yield takeLatest(ENABLE_VOTING, openIssue);
  yield takeLatest(TOGGLE_NOTIFICATION, toggleNotification);
}

import { call, takeLatest, select } from 'redux-saga/effects';
import { TOGGLE_NOTIFICATION } from 'common/actionTypes/userSettings';
import { ENABLE_VOTING } from 'common/actionTypes/voting';
import { notify, notifyPermission } from '../../utils/notification';
import { getIssueText } from '../issue/selectors';
import { notificationIsEnabled } from '../userSettings/selectors';

function* openIssue() {
  const notificationEnabled = yield select(notificationIsEnabled);
  const description = yield select(getIssueText);
  if (notificationEnabled) {
    yield call(notify, description);
  }
}

function* toggleNotification() {
  const notificationEnabled = yield select(notificationIsEnabled);
  if (notificationEnabled) {
    yield call(notifyPermission);
  }
}

export default function* issueSaga() {
  yield takeLatest(ENABLE_VOTING, openIssue);
  yield takeLatest(TOGGLE_NOTIFICATION, toggleNotification);
}

Fix voting notification returning undefined
Fix voting notification returning undefined

getIssueText returns issue text not object.
