Newer
Older
import { GET_TASKS,
GET_SOLUTIONS,
ADD_TASK,
WRITE_TASK,
CLEAR_WRITE,
ADD_SOLUTION,
WRITE_SOLUTION,
WRITE_SOLUTION_FILE,
ADD_DOCUMENT,
GET_DOCUMENTS,
CORRECT_SOLUTION,
CHECK } from './types';
async (dispatch) => {
try {
const response = await axios.get('/api/v1/homework/tasks/');
dispatch({
payload: response.data,
});
} catch (e) {
console.log(e);
}
}
);
export const getSolutions = id => (
const response = await axios.get('/api/v1/homework/solutions/', { params: { profileID: id } });
dispatch({
type: GET_SOLUTIONS,
payload: response.data,
});
} catch (e) {
console.log(e);
}
}
);
export const addTask = ({ title, text, deadline }) => (
async (dispatch) => {
try {
const response = await axios.post('/api/v1/homework/tasks/', {
title,
text,
deadline,
});
if (response.data.id) {
dispatch({
type: ADD_TASK,
payload: response.data,
});
}
} catch (e) {
console.log(e);
}
}
);
export const deleteTask = task => (
async (dispatch) => {
try {
const response = await axios.delete(`/api/v1/homework/tasks/${task.id}/`);
if (!response.data.id) {
dispatch({
type: DELETE_TASK,
payload: task,
});
}
} catch (e) {
console.log(e);
}
});
export const addDocument = ({
name, description, file, solution,
const formData = new FormData();
formData.append('name', name);
formData.append('description', description);
formData.append('file', file);
formData.append('solution', solution);
const config = {
headers: {
'content-type': 'multipart/form-data',
},
};
const response = await axios.post('/api/v1/documents/', formData, config);
type: ADD_DOCUMENT,
payload: response.data,
});
}
} catch (e) {
console.log(e);
}
}
);
export const addSolution = ({
task, accepted, corrected, note, name, description, file,
const response = await axios.post('/api/v1/homework/solutions/', {
task,
accepted,
corrected,
note,
});
if (response.data.id) {
console.log(response.data.id)
dispatch({
type: ADD_SOLUTION,
payload: response.data,
});
}
const solution = response.data.id;
console.log(solution);
const formData = new FormData();
formData.append('name', name);
formData.append('description', description);
formData.append('file', file);
formData.append('solution', solution);
const config = {
headers: {
'content-type': 'multipart/form-data',
},
};
const responsedoc = await axios.post('/api/v1/documents/', formData, config);
if (responsedoc.data.id) {
payload: responsedoc.data,
});
}
} catch (e) {
console.log(e);
}
}
);
export const getDocuments = (id, solution) => (
async (dispatch) => {
try {
const response =
await axios.get('/api/v1/documents', { params: { profileID: id, solutionID: solution } });
dispatch({
type: GET_DOCUMENTS,
payload: response.data,
});
} catch (e) {
console.log(e);
}
}
);
export const writeSolution = ({ target: { name, value } }) => (
(dispatch) => {
dispatch({ type: WRITE_SOLUTION, payload: value, target: name });
}
);
export const writeSolutionFile = ({ target: { files } }) => (
(dispatch) => {
dispatch({ type: WRITE_SOLUTION_FILE, payload: files[0], target: 'file' });
}
);
export const writeTask = ({ target: { name, value } }) => (
(dispatch) => {
dispatch({ type: WRITE_TASK, payload: value, target: name });
}
);
export const writeTaskDeadline = ({ name, value }) => (
(dispatch) => {
dispatch({ type: WRITE_TASK, payload: value, target: name });
}
);
export const clearWrite = () => (
(dispatch) => {
dispatch({ type: CLEAR_WRITE });
}
);
export const getProfiles = () => (
async (dispatch) => {
try {
const response = await axios.get('/api/v1/profiles/');
dispatch({
type: GET_PROFILES,
payload: response.data,
});
} catch (e) {
console.log(e);
}
}
);
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
export const correctSolution = (id, corrected, accepted, note) => (
async (dispatch) => {
try {
const response = await axios.patch(`/api/v1/homework/solutions/${id}/`, {
corrected,
accepted,
note,
});
if (response.data.id) {
alert('Sikeres mentés!');
dispatch({
type: CORRECT_SOLUTION,
payload: response.data,
});
} else {
alert('Mentés nem sikerült!');
}
} catch (e) {
console.log(e);
}
}
);
export const check = () => (
(dispatch) => {
dispatch({ type: CHECK });
}
);