redux-saga/effects#call JavaScript Examples

The following examples show how to use redux-saga/effects#call. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ratings.js    From haven with MIT License 6 votes vote down vote up
export function* getRatingsAction(action) {
  const { username, password } = yield select(getUserCredentails);
  const { peerID, slug } = action.payload;
  try {
    const result = yield call(getRatings, username, password, slug, peerID);
    if (result.success !== false) {
      const { ratings = [], average = 0, count = 0 } = result;
      yield put({
        type: actions.setRatings,
        payload: {
          reference: `${peerID}/${slug}`,
          ratings: ratings.reverse(),
          avgRating: average,
          count,
        },
      });
    } else {
      yield put({ type: actions.fetchRatingsFailure });
    }
  } catch (err) {
    yield put({ type: actions.fetchRatingsFailure });
  }
}
Example #2
Source File: business-pages.sagas.js    From horondi_admin with MIT License 6 votes vote down vote up
export function* handleBusinessPageError(e) {
  if (
    e.message === AUTH_ERRORS.REFRESH_TOKEN_IS_NOT_VALID ||
    e.message === AUTH_ERRORS.USER_IS_BLOCKED
  ) {
    yield call(handleAdminLogout);
  } else {
    yield put(setLoading(false));
    yield put(setBusinessPagesError({ e }));
    yield call(handleErrorSnackbar, e.message);
  }
}
Example #3
Source File: github.js    From full-stack-fastapi-react-postgres-boilerplate with MIT License 6 votes vote down vote up
/**
 * Get Repos
 *
 * @param {Object} action
 *
 */
export function* getRepos({ payload }) {
  try {
    const response = yield call(
      request,
      `https://api.github.com/search/repositories?q=${payload.query}&sort=stars`,
    );
    yield put({
      type: ActionTypes.GITHUB_GET_REPOS_SUCCESS,
      payload: { data: response.items },
    });
  } catch (err) {
    /* istanbul ignore next */
    yield put({
      type: ActionTypes.GITHUB_GET_REPOS_FAILURE,
      payload: err,
    });
  }
}
Example #4
Source File: root.sagas.js    From react-redux-jsonplaceholder with MIT License 6 votes vote down vote up
export default function* rootSaga() {
  yield all([
    call(albumsSaga),
    call(commentsSaga),
    call(photosSaga),
    call(postsSaga),
    call(todosSaga),
    call(usersSaga),
  ]);
}
Example #5
Source File: sagas.js    From gobench with Apache License 2.0 6 votes vote down vote up
export function * LOGOUT () {
  const { authProvider } = yield select(state => state.settings)
  yield call(mapAuthProviders[authProvider].logout)
  yield put({
    type: 'user/SET_STATE',
    payload: {
      id: '',
      name: '',
      role: '',
      email: '',
      avatar: '',
      authorized: false,
      loading: false
    }
  })
}
Example #6
Source File: saga.js    From gedge-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Changes the left sidebar type
 * @param {*} param0
 */
function* changeLeftSidebarType({ payload: { sidebarType, isMobile } }) {
	try {
		switch (sidebarType) {
			case "compact":
				yield call(changeBodyAttribute, "data-sidebar-size", "small");
				yield call(manageBodyClass, "sidebar-enable", "remove");
				yield call(manageBodyClass, "vertical-collpsed", "remove");
				break;
			case "icon":
				yield call(changeBodyAttribute, "data-keep-enlarged", "true");
				yield call(manageBodyClass, "vertical-collpsed", "add");
				break;
			case "condensed":
				yield call(manageBodyClass, "sidebar-enable", "add");
				if (!isMobile) yield call(manageBodyClass, "vertical-collpsed", "add");
				break;
			default:
				yield call(changeBodyAttribute, "data-sidebar-size", "");
				yield call(manageBodyClass, "sidebar-enable", "remove");
				if (!isMobile) yield call(manageBodyClass, "vertical-collpsed", "remove");
				break;
		}
	} catch (error) { }
}
Example #7
Source File: reminder.js    From jc-calendar with MIT License 6 votes vote down vote up
export function* submitReminder(action) {
  const reminder = action.payload;
  let id = reminder.id;
  if (!id) {
    // It is a new reminder, create an id for it since we don't have a backend.
    id = yield call(generateUUID);
  }

  const reminderToSet = {
    id,
    description: reminder.description,
    color: reminder.color,
    dateTime: dateTimeStringsToMillis(reminder.date, reminder.time),
    city: reminder.city,
  };

  const dateReminder = { date: reminder.date, reminderId: reminderToSet.id };

  // TODO: Save do IDB (with dexie)

  yield put(setReminder(reminderToSet));
  yield put(setDateReminder(dateReminder));

  yield put(reminderUIActions.closeReminder());
}
Example #8
Source File: Profile.Saga.js    From react-native-hook-template with MIT License 6 votes vote down vote up
function* handleGetProfile(action) {
  const response = yield call(getProfile, action.payload);
  if (response.ok) {
    yield put(getProfileSuccess(response.data));
  } else {
    if (
      response.problem !== 'NETWORK_ERROR' &&
      response.problem !== 'TIMEOUT_ERROR' &&
      response.problem !== 'CONNECTION_ERROR'
    ) {
      yield put(getProfileFail(response.problem));
    } else {
      yield put(sendNetworkFail(response.problem));
      yield put(getProfileFail(response.problem));
    }
  }
}
Example #9
Source File: auth.saga.js    From React-Native-Boilerplate with MIT License 6 votes vote down vote up
function* signupSaga({ payload }) {
  try {
    const response = yield call(signUp, payload);
    if (response.success) {
      AsyncStorage.setItem('@token', response.success.token);
      const user = {
        ...response.success.user,
        token: response.success.token,
      };
      yield put(authActionsCreator.registerSuccess({ user }));
    }
  } catch (error) {
    yield put(
      authActionsCreator.registerError({
        error: error ? error : 'User Signup Failed',
      }),
    );
  }
}
Example #10
Source File: wallet.js    From haven with MIT License 6 votes vote down vote up
function* sendFunds(action) {
  const { data, nextAction } = action.payload;
  const result = yield call(sendBitcoins, data);
  if (hasIn(result, 'confirmedBalance')) {
    if (nextAction) {
      yield call(nextAction);
    }
    eventTracker.trackEvent('Wallet-PaymentSuccess');
    yield put({ type: actions.sendFundsSuccess });
    yield put({ type: actions.fetchWalletBalance });
    yield put({ type: actions.setTxid, payload: result.txid });
    yield put({ type: actions.fetchTransactions, payload: data.wallet });
  } else if (result.success === false) {
    const { reason } = result;
    eventTracker.trackEvent('Wallet-PaymentFailed', reason);
    yield put({ type: actions.sendFundsFailure, payload: getWalletFailureMessage(reason) });
  }
}
Example #11
Source File: saga.js    From QiskitFlow with Apache License 2.0 6 votes vote down vote up
export function* getRuns() {
  const page = yield select(makeSelectSharedRunsPage());
  const filter = yield select(makeSelectSharedFilter());
  const offset = 10 * (page - 1);
  const limit = 10;
  const requestUrl = `${getBaseUrl()}/api/v1/core/runs/public/?offset=${offset}&limit=${limit}`;

  try {
    const response = yield call(request, requestUrl);
    yield put(updateRunsAction({ ...response, page }));
  } catch (err) {
    if (err.response.status === 401) {
      yield put(logoutAction());
    } else {
      yield put(repoLoadingError(err));
    }
  }
}