Skip to content

images_action.js

Anoop Nair edited this page Nov 16, 2021 · 5 revisions

Introduction

This file contains all the redux actions for images.

There are three types of images in app :

  • CAMERA - These are the images taken from in app camera.
  • GALLERY - These are geotagged images imported from phone gallery.
  • WEB - These are images uploaded from OLM website but not yet tagged.

addImages

Action to add images to state.

Params

  • images - Array of image object.
  • type - CAMERA || GALLERY || WEB
  • pickedUp - {boolean} Default user setting if litter is picked up or still there.

addTagToImage

Action to add one tag to an image.

Params

  • payload - object with following shape.
    • tag
    • currentIndex
    • quantityChanged

checkForImagesOnWeb

Action to get images uploaded from website but not yet tagged. Called in HomeScreen.js

  • Makes a GET request to api endpoint /api/v2/photos/web/index
  • if success and untagged photos exist add it to state.
  • dispatch with type: ADD_IMAGES &
payload: {
   images: photos, // photos is array of untagged images from api response
   type: 'WEB',
   picked_up
}

Params

  • token - JWT token stored in redux state.
  • picked_up - default user setting if litter is picked_up or not

decrementSelected

Decrement the count of photos selected for deletion. Called in HomeScreen.js

  • dispatches DECREMENT_SELECTED

deleteImage

Action to delete image by id.

  • dispatches DELETE_IMAGE with payload id

Params

  • id - {number} the id of the image in state imagesArray

deselectAllImages

Change selected property to false on all the photos in state imagesArray

  • dispatches DESELECT_ALL_IMAGES

deleteWebImage

Delete WEB image based on the photoId

  • Makes a DELETE request on api endpoint /api/photos/delete and send params: { photoId }.
  • If success remove the image from state, dispatch DELETE_IMAGE with payload id

Params

  • token - JWT token stored in redux state.
  • photoId - image id in db
  • id - image id in state imagesArray
Action
Reducer
Clone this wiki locally