Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/actions/experiences.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { call, put, takeLatest } from 'redux-saga/effects';
import {
EXPERIENCES_FETCH_FOR_USER,
EXPERIENCES_CREATE,
EXPERIENCES_EDIT
EXPERIENCES_EDIT,
EXPERIENCES_DELETE
} from '../constants';
import {
experiencesFetchForUser as getExperiencesForUser,
experiencesCreate as postExperiences,
experiencesEdit as patchExperiences
experiencesEdit as patchExperiences,
experiencesRemove as removeExperiences
} from '../lib/api';
import actionGenerator from '../lib/actionGenerator';

Expand Down Expand Up @@ -125,8 +127,37 @@ export function* experiencesEdit({
);
}

/**
* Deletes an existing experience.
*
* @param {object} payload - Payload for this saga action.
* @param {string} payload.id - Id of the experience to be removed
* @param {function} payload.successHandler
* Function to be executed if/when this action succeeds.
* @param {object} payload.user - Object containing user data.
* @param {object} payload.user.authentication - Object containing auth data.
* @param {string} payload.user.authentication.accessToken
* Access token for the current user.
* @param {string} payload.user.authentication.csrfToken
* CSRF token for the current user.
*/
export function* experiencesDelete({ user, id, successHandler = () => {} }) {
yield* actionGenerator(
EXPERIENCES_DELETE,
function* experienceRemoveHandler() {
yield call(removeExperiences, id, user);
yield put({
type: `${EXPERIENCES_DELETE}_SUCCESS`,
payload: { id }
});
},
successHandler
);
}

export function* watchExperiencesActions() {
yield takeLatest(EXPERIENCES_FETCH_FOR_USER, experiencesFetchForUser);
yield takeLatest(EXPERIENCES_CREATE, experiencesCreate);
yield takeLatest(EXPERIENCES_EDIT, experiencesEdit);
yield takeLatest(EXPERIENCES_DELETE, experiencesDelete);
}
42 changes: 42 additions & 0 deletions src/actions/openExperience.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
OPEN_EXPERIENCE_FETCH_FOR_USER,
OPEN_EXPERIENCE_SCENE_CREATE,
OPEN_EXPERIENCE_SCENE_EDIT,
OPEN_EXPERIENCE_SCENE_DELETE,
OPEN_EXPERIENCE_COMPONENT_CREATE,
OPEN_EXPERIENCE_COMPONENT_DELETE,
OPEN_EXPERIENCE_COMPONENT_EDIT,
Expand All @@ -21,6 +22,7 @@ import {
fileCreate,
sceneCreate,
sceneEdit,
sceneRemove,
componentEdit,
componentCreate,
componentRemove,
Expand Down Expand Up @@ -169,6 +171,45 @@ export function* openExperienceSceneEdit({
);
}

/**
* Dispatches an action that deletes a scene in the current openExperience.
*
* @param {object} payload
* Payload for this saga action.
* @param {string} payload.id
* ID of this scene.
* @param {string} payload.sceneSlug
* Slug of this scene.
* @param {object} payload.user
* Object containing user data.
* @param {object} payload.user.authentication
* Object containing auth data.
* @param {string} payload.user.authentication.accessToken
* Access token for the current user.
* @param {string} payload.user.authentication.csrfToken
* CSRF token for the current user.
* @param {function} payload.successHandler
* Function to be executed if/when this action succeeds.
*/
export function* openExperienceSceneDelete({
id,
sceneSlug,
user,
successHandler = () => {}
}) {
yield* actionGenerator(
OPEN_EXPERIENCE_SCENE_DELETE,
function* openExperienceSceneDeleteHandler() {
yield call(sceneRemove, id, user);
yield put({
type: `${OPEN_EXPERIENCE_SCENE_DELETE}_SUCCESS`,
payload: { sceneSlug }
});
},
successHandler
);
}

/**
* Dispatches an action that creates a new component.
*
Expand Down Expand Up @@ -347,6 +388,7 @@ export function* watchOpenExperienceActions() {
yield takeLatest(OPEN_EXPERIENCE_FETCH_FOR_USER, openExperienceFetchForUser);
yield takeLatest(OPEN_EXPERIENCE_SCENE_CREATE, openExperienceSceneCreate);
yield takeLatest(OPEN_EXPERIENCE_SCENE_EDIT, openExperienceSceneEdit);
yield takeLatest(OPEN_EXPERIENCE_SCENE_DELETE, openExperienceSceneDelete);
yield takeLatest(
OPEN_EXPERIENCE_COMPONENT_CREATE,
openExperienceComponentCreate
Expand Down
Loading