redux-saga/effects#getContext JavaScript Examples

The following examples show how to use redux-saga/effects#getContext. 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: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetFollowedUsersWithStoriesRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getFollowedUsersWithStories, req.payload))
    const selector = path(['data', 'getFollowedUsersWithStories', 'items'])

    yield put(actions.usersGetFollowedUsersWithStoriesSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetFollowedUsersWithStoriesFailure({ message: error.message }))
  }
}
Example #2
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
function* handlePostsCreateRequest(payload) {
  const AwsAPI = yield getContext('AwsAPI')
  
  function* createPost() {
    try {
      return yield AwsAPI.graphql(graphqlOperation(queries.getPost, req.payload))
    } catch (error) {
      return yield AwsAPI.graphql(graphqlOperation(queries.addPost, payload))
    }
  }

  const data = yield createPost()

  const currentIndex = 0
  const selector = path(['data', 'addPost', 'mediaObjects', currentIndex, 'uploadUrl'])
  const imageSelector = path(['images', currentIndex])

  return {
    imageUrl: selector(data),
    image: imageSelector(payload),
  }
}
Example #3
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsOnymouslyLikeRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.onymouslyLikePost, req.payload))
    const selector = path(['data', 'onymouslyLikePost'])

    yield put(actions.postsOnymouslyLikeSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsOnymouslyLikeFailure({ message: error.message, payload: req.payload }))
  }
}
Example #4
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsAnonymouslyLikeRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.anonymouslyLikePost, req.payload))
    const selector = path(['data', 'anonymouslyLikePost'])

    yield put(actions.postsAnonymouslyLikeSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsAnonymouslyLikeFailure({ message: error.message, payload: req.payload }))
  }
}
Example #5
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsDislikeRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.dislikePost, req.payload))
    const selector = path(['data', 'dislikePost'])

    yield put(actions.postsDislikeSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsDislikeFailure({ message: error.message, payload: req.payload, }))
  }
}
Example #6
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsReportPostViewsRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.reportPostViews, req.payload))
    const selector = path(['data', 'reportPostViews'])

    yield put(actions.postsReportPostViewsSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsReportPostViewsFailure({ message: error.message, payload: req.payload }))
  }
}
Example #7
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsGetTrendingPostsRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.trendingPosts, req.payload))
    const selector = path(['data', 'trendingPosts', 'items'])

    yield put(actions.postsGetTrendingPostsSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsGetTrendingPostsFailure({ message: error.message, payload: req.payload }))
  }
}
Example #8
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
function* postsGetTrendingPostsMoreRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.trendingPosts, req.payload))
    const selector = path(['data', 'trendingPosts', 'items'])

    yield put(actions.postsGetTrendingPostsMoreSuccess({ data: selector(data), payload: req.payload, meta: data }))
  } catch (error) {
    yield put(actions.postsGetTrendingPostsMoreFailure({ message: error.message, payload: req.payload }))
  }
}
Example #9
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersSearchRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.searchUsers, req.payload))
    const selector = path(['data', 'searchUsers', 'items'])

    yield put(actions.usersSearchSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersSearchFailure({ message: error.message }))
  }
}
Example #10
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersStoriesGetRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getStories, req.payload))
    const selector = path(['data', 'getStories', 'items'])

    yield put(actions.usersStoriesGetSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersStoriesGetFailure({ message: error.message }))
  }
}
Example #11
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetFollowerUsersRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getFollowerUsers, req.payload))
    const selector = path(['data', 'user', 'followerUsers', 'items'])

    yield put(actions.usersGetFollowerUsersSuccess({ payload: req.payload, data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetFollowerUsersFailure({ payload: req.payload, message: error.message }))
  }
}
Example #12
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetFollowedUsersRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getFollowedUsers, req.payload))
    const selector = path(['data', 'user', 'followedUsers', 'items'])

    yield put(actions.usersGetFollowedUsersSuccess({ payload: req.payload, data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetFollowedUsersFailure({ payload: req.payload, message: error.message }))
  }
}
Example #13
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* postsSingleGetRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getPost, req.payload))
    const selector = path(['data', 'getPost'])

    yield put(actions.postsSingleGetSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.postsSingleGetFailure({ message: error.message }))
  }
}
Example #14
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersAcceptFollowerUserRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.acceptFollowerUser, req.payload)))
    const selector = path(['data', 'acceptFollowerUser'])

    yield put(actions.usersAcceptFollowerUserSuccess({ data: selector(data) }))
  } catch (error) {
    yield put(actions.usersAcceptFollowerUserFailure({ message: error.message }))
  }
}
Example #15
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersDeclineFollowerUserRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.denyFollowerUser, req.payload)))
    const selector = path(['data', 'denyFollowerUser'])

    yield put(actions.usersDeclineFollowerUserSuccess({ data: selector(data) }))
  } catch (error) {
    yield put(actions.usersDeclineFollowerUserFailure({ message: error.message }))
  }
}
Example #16
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetProfileRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.user, req.payload))
    const selector = path(['data', 'user'])

    yield put(actions.usersGetProfileSuccess({ payload: req.payload, data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetProfileFailure({ payload: req.payload, message: error.message }))
  }
}
Example #17
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetProfileSelfRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.self))
    const selector = path(['data', 'self'])

    yield put(actions.usersGetProfileSelfSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetProfileSelfFailure({ message: error.message }))
  }
}
Example #18
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersEditProfileRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.setUserDetails, req.payload))
    const selector = path(['data', 'setUserDetails'])

    yield put(actions.usersEditProfileSuccess({ data: selector(data) }))
    yield put(actions.globalAuthUserTrigger({ data: selector(data) }))
  } catch (error) {
    yield put(actions.usersEditProfileFailure({ message: error.message }))
  }
}
Example #19
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersFollowRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.followUser, req.payload)))
    const selector = path(['data', 'followUser'])

    yield put(actions.usersFollowSuccess({ payload: req.payload, data: selector(data) }))
  } catch (error) {
    yield put(actions.usersFollowFailure({ payload: req.payload, message: error.message }))
  }
}
Example #20
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersUnfollowRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.unfollowUser, req.payload)))
    const selector = path(['data', 'unfollowUser'])

    yield put(actions.usersUnfollowSuccess({ payload: req.payload, data: selector(data) }))
  } catch (error) {
    yield put(actions.usersUnfollowFailure({ payload: req.payload, message: error.message }))
  }
}
Example #21
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersBlockRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.blockUser, req.payload)))
    const selector = path(['data', 'blockUser'])

    yield put(actions.usersBlockSuccess({ payload: req.payload, data: selector(data) }))
  } catch (error) {
    yield put(actions.usersBlockFailure({ payload: req.payload, message: error.message }))
  }
}
Example #22
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersUnblockRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')
  try {
    const data = yield call(() => AwsAPI.graphql(graphqlOperation(queries.unblockUser, req.payload)))
    const selector = path(['data', 'unblockUser'])

    yield put(actions.usersUnblockSuccess({ payload: req.payload, data: selector(data) }))
  } catch (error) {
    yield put(actions.usersUnblockFailure({ payload: req.payload, message: error.message }))
  }
}
Example #23
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersMediaObjectsGetRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.getMediaObjects, req.payload))
    const selector = path(['data', 'getMediaObjects', 'items'])

    yield put(actions.usersMediaObjectsGetSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersMediaObjectsGetFailure({ message: error.message }))
  }
}
Example #24
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* usersGetTrendingUsersRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    const data = yield AwsAPI.graphql(graphqlOperation(queries.trendingUsers, req.payload))
    const selector = path(['data', 'trendingUsers', 'items'])

    yield put(actions.usersGetTrendingUsersSuccess({ data: selector(data), meta: data }))
  } catch (error) {
    yield put(actions.usersGetTrendingUsersFailure({ message: error.message }))
  }
}
Example #25
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
function* handleAuthSignoutRequest(payload) {
  const AwsAuth = yield getContext('AwsAuth')
  const AwsCache = yield getContext('AwsCache')
  const AwsCredentials = yield getContext('AwsCredentials')

  yield AwsAuth.signOut({ global: true })
  yield AwsCredentials.clear()
  yield AwsCache.clear()
}
Example #26
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
function* authOnboardRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    yield handleAuthOnboardRequest(req.payload)

    const data = yield AwsAPI.graphql(graphqlOperation(queries.self, req.payload))
    const selector = path(['data', 'self'])

    yield put(actions.globalAuthUserTrigger({
      data: selector(data),
    }))

    yield put(actions.authOnboardSuccess({
      message: errors.getMessagePayload(constants.AUTH_ONBOARD_SUCCESS, 'GENERIC'),
      data: selector(data),
      nextRoute: 'Main',
    }))
  } catch (error) {
    if (path(['errors', '0', 'path', '0'])(error) === 'createCognitoOnlyUser') {
      yield put(actions.authOnboardFailure({
        message: errors.getMessagePayload(constants.AUTH_ONBOARD_FAILURE, 'USER_EXISTS', error.message),
        nextRoute: 'Auth',
      }))
    } else {
      yield put(actions.authOnboardFailure({
        message: errors.getMessagePayload(constants.AUTH_ONBOARD_FAILURE, 'GENERIC', error.message),
        nextRoute: 'AuthOnboard',
      }))
    }
  }
}
Example #27
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 * AwsAuth.currentAuthenticatedUser method is used to check if a user is logged in.
 * It will throw an error if there is no user logged in.
 */
function* handleAuthCheckRequest() {
  const AwsAuth = yield getContext('AwsAuth')

  return yield AwsAuth.currentAuthenticatedUser({
    bypassCache: false,
  })
}
Example #28
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if user is logged in, not authenticated users will be redirected to Auth page.
 * Authenticated users with empty `self graphql query` return will be redirected to Onboard page,
 * meaning that user authenticated in Cognito pool but didn't create an entry in database on backend.
 */
function* authCheckRequest(req) {
  const AwsAPI = yield getContext('AwsAPI')

  try {
    yield handleAuthCheckRequest(req.payload)

    const data = yield AwsAPI.graphql(graphqlOperation(queries.self, req.payload))
    const selector = path(['data', 'self'])

    yield put(actions.authCheckSuccess({
      message: errors.getMessagePayload(constants.AUTH_CHECK_SUCCESS, 'GENERIC'),
      data: selector(data),
      nextRoute: 'Main',
    }))
  } catch (error) {
    if (path(['errors', '0', 'path', '0'])(error) === 'self') {
      yield put(actions.authCheckFailure({
        message: errors.getMessagePayload(constants.AUTH_CHECK_FAILURE, 'USER_JUST_CREATED'),
        nextRoute: 'AuthOnboard',
      }))
    } else {
      yield put(actions.authCheckFailure({
        message: errors.getMessagePayload(constants.AUTH_CHECK_FAILURE, 'GENERIC', error.message),
        nextRoute: 'Auth',
      }))
    }
  }
}
Example #29
Source File: saga.js    From real-frontend with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Signin user. Currently supports email and password or phone number and password methods
 */
function* handleAuthSigninRequest(payload) {
  const AwsAuth = yield getContext('AwsAuth')
  
  /**
   * getSignupStage will return identityId if user is not linked during confirmSignup action
   * if user was linked during confirmSignup identity will return null.
   * User migh not get linked because he used confirmSignup with deep link which
   * doesnt has password field. Once identites are linked we should clear identity from async
   * storage meaning that user successfully confirmed.
   */
  const identity = yield getSignupStage({ username: payload.username })
  if (identity && payload.password) {
    yield linkUserIdentities({
      username: identity,
      password: payload.password,
    })
    yield clearSignupStage({ username: payload.username })
  }

  yield AwsAuth.signIn(payload.username, payload.password)
}