PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / apps / js / admin / react / question / store / actions.js

actions.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.1, at assets/src/apps/js/admin/react/question/store/actions.js

106 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {dispatch, select, apiFetch} from '@learnpress/data-controls';
2 import {select as wpSelect} from '@wordpress/data';
3
4 const getEditorNonce = function getEditorNonce() {
5 return lp_question_editor.root.nonce;
6 }
7
8 /**
9 * Set user data for app.
10 * @param key
11 * @param data
12 * @return {{type: string, data: *}}
13 */
14 export function setData( data, key ) {
15 return {
16 type: 'SET_DATA',
17 data,
18 key
19 }
20 }
21
22 export function __addOption(id, option) {
23 return {
24 type: 'ADD_OPTION',
25 id,
26 option
27 }
28 }
29
30 /**
31 * Add new blank and send to rest
32 */
33 export function* addOption(questionId, option) {
34 const results = yield apiFetch({
35 path: 'lp/a/v1/question/' + questionId + '/add-option',
36 method: 'POST',
37 data: {
38 nonce: getEditorNonce(),
39 type: 'new-answer',
40 id: questionId,
41 option
42 }
43 });
44
45 yield dispatch('learnpress/question', '__addOption', questionId, results.result);
46 }
47
48 export function __removeOption(questionId, optionId) {
49 return {
50 type: 'REMOVE_OPTION',
51 id: questionId,
52 optionId
53 }
54 }
55
56 /**
57 * Send a rest request to remove answer option.
58 *
59 * @param questionId
60 * @param optionId
61 */
62 export function* removeOption(questionId, optionId) {
63 const results = yield apiFetch({
64 path: 'lp/a/v1/question/' + questionId + '/remove-option',
65 method: 'POST',
66 data: {
67 nonce: getEditorNonce(),
68 type: 'delete-answer',
69 id: questionId,
70 answer_id: optionId
71 }
72 });
73
74 yield dispatch('learnpress/question', '__removeOption', questionId, optionId);
75 }
76
77 export function __updateOption(option, optionId, questionId) {
78 return {
79 type: 'UPDATE_OPTION',
80 id: questionId,
81 optionId,
82 option
83 }
84 }
85
86 export function* updateOption(option, optionId, questionId) {
87
88 const results = yield apiFetch({
89 path: 'lp/a/v1/question/' + questionId + '/update-option',
90 method: 'POST',
91 data: {
92 type: 'update-answer-title',
93 answer: {
94 ...option,
95 question_answer_id: optionId
96 },
97 id:questionId,
98 nonce: getEditorNonce()
99 }
100 });
101
102 yield dispatch('learnpress/question', '__updateOption', option);
103
104 //yield dispatch('learnpress/quiz', '__requestStartQuizSuccess', quiz);
105 }
106