Skip to content
Snippets Groups Projects
Commit 110768c3 authored by Bereczki Sandor's avatar Bereczki Sandor
Browse files

Proper state updates for correction modals, key fixes

parent dbf9f685
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import { emptyMessage } from '../pages/Homework'; ...@@ -6,6 +6,7 @@ import { emptyMessage } from '../pages/Homework';
import './Forms.css'; import './Forms.css';
import { import {
getSolutions, getSolutions,
getDocuments,
} from '../../actions/homework'; } from '../../actions/homework';
class SolutionDetailsForm extends Component { class SolutionDetailsForm extends Component {
...@@ -25,7 +26,7 @@ class SolutionDetailsForm extends Component { ...@@ -25,7 +26,7 @@ class SolutionDetailsForm extends Component {
const noAcceptStudents = []; const noAcceptStudents = [];
const acceptedStudents = []; const acceptedStudents = [];
this.props.homeworks.profiles.forEach(profile => { this.props.homeworks.profiles.forEach((profile) => {
const profileSolutions = taskSolutions.filter(solution => const profileSolutions = taskSolutions.filter(solution =>
solution.created_by === profile.id); solution.created_by === profile.id);
...@@ -53,6 +54,7 @@ class SolutionDetailsForm extends Component { ...@@ -53,6 +54,7 @@ class SolutionDetailsForm extends Component {
onClick={() => { onClick={() => {
this.setState({ showModal: true }); this.setState({ showModal: true });
this.props.getSolutions(); this.props.getSolutions();
this.props.getDocuments();
}} }}
> >
<Icon name='external' /> <Icon name='external' />
...@@ -65,13 +67,13 @@ class SolutionDetailsForm extends Component { ...@@ -65,13 +67,13 @@ class SolutionDetailsForm extends Component {
</Modal.Header> </Modal.Header>
<Modal.Content> <Modal.Content>
<Header as='h3'>A feladat leírása:</Header> <Header as='h3'>A feladat leírása:</Header>
{this.props.taskdesc.split('\n').map(s => (<p>{s}</p>))} {this.props.taskdesc.split('\n').map(s => (<p key={Math.random()}>{s}</p>))}
<Divider /> <Divider />
<Header as='h3'>Nem érkezett még megoldás:</Header> <Header as='h3'>Nem érkezett még megoldás:</Header>
{noSubmitStudents.length === 0 ? {noSubmitStudents.length === 0 ?
emptyMessage(emptyStudentText) : emptyMessage(emptyStudentText) :
noSubmitStudents.map(student => ( noSubmitStudents.map(student => (
<Button color='blue' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button> <Button key={Math.random()} color='blue' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button>
)) ))
} }
<Divider /> <Divider />
...@@ -80,6 +82,7 @@ class SolutionDetailsForm extends Component { ...@@ -80,6 +82,7 @@ class SolutionDetailsForm extends Component {
emptyMessage(emptyStudentText) : emptyMessage(emptyStudentText) :
waitForCorrectionStudents.map(student => ( waitForCorrectionStudents.map(student => (
<CorrectSolutionForm <CorrectSolutionForm
key={Math.random()}
studentName={student.nick} studentName={student.nick}
studentFullName={student.full_name} studentFullName={student.full_name}
studentId={student.id} studentId={student.id}
...@@ -93,7 +96,7 @@ class SolutionDetailsForm extends Component { ...@@ -93,7 +96,7 @@ class SolutionDetailsForm extends Component {
{noAcceptStudents.length === 0 ? {noAcceptStudents.length === 0 ?
emptyMessage(emptyStudentText) : emptyMessage(emptyStudentText) :
noAcceptStudents.map(student => ( noAcceptStudents.map(student => (
<Button color='red' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button> <Button key={Math.random()} color='red' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button>
)) ))
} }
<Divider /> <Divider />
...@@ -101,7 +104,7 @@ class SolutionDetailsForm extends Component { ...@@ -101,7 +104,7 @@ class SolutionDetailsForm extends Component {
{acceptedStudents.length === 0 ? {acceptedStudents.length === 0 ?
emptyMessage(emptyStudentText) : emptyMessage(emptyStudentText) :
acceptedStudents.map(student => ( acceptedStudents.map(student => (
<Button color='green' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button> <Button key={Math.random()} color='green' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button>
)) ))
} }
</Modal.Content> </Modal.Content>
...@@ -124,5 +127,5 @@ class SolutionDetailsForm extends Component { ...@@ -124,5 +127,5 @@ class SolutionDetailsForm extends Component {
const mapStateToProps = ({ homeworks, user }) => ({ homeworks, user }); const mapStateToProps = ({ homeworks, user }) => ({ homeworks, user });
export default connect(mapStateToProps, { export default connect(mapStateToProps, {
getSolutions, getSolutions, getDocuments,
})(SolutionDetailsForm); })(SolutionDetailsForm);
...@@ -18,7 +18,6 @@ import { ...@@ -18,7 +18,6 @@ import {
deleteTask, deleteTask,
addDocument, addDocument,
getProfiles, getProfiles,
getDocuments,
} from '../../actions/homework'; } from '../../actions/homework';
import AddTaskForm from '../forms/AddTaskForm'; import AddTaskForm from '../forms/AddTaskForm';
import AddSolutionForm from '../forms/AddSolutionForm'; import AddSolutionForm from '../forms/AddSolutionForm';
...@@ -70,7 +69,6 @@ class Homework extends Component { ...@@ -70,7 +69,6 @@ class Homework extends Component {
this.props.getTasks(); this.props.getTasks();
this.props.getProfiles(); this.props.getProfiles();
this.props.getSolutions(this.props.user.id); this.props.getSolutions(this.props.user.id);
this.props.getDocuments();
} }
getTaskDisplayStyle(task) { getTaskDisplayStyle(task) {
...@@ -337,6 +335,5 @@ export default connect( ...@@ -337,6 +335,5 @@ export default connect(
deleteTask, deleteTask,
addDocument, addDocument,
getProfiles, getProfiles,
getDocuments,
}, },
)(Homework); )(Homework);
import { GET_TASKS, import { GET_TASKS,
GET_SOLUTIONS, GET_SOLUTIONS,
CORRECT_SOLUTION,
ADD_TASK, ADD_TASK,
DELETE_TASK, DELETE_TASK,
EDIT_TASK, EDIT_TASK,
...@@ -22,6 +23,11 @@ export default (state = INITIAL_STATE, action) => { ...@@ -22,6 +23,11 @@ export default (state = INITIAL_STATE, action) => {
return { ...state, tasks: action.payload }; return { ...state, tasks: action.payload };
case GET_SOLUTIONS: case GET_SOLUTIONS:
return { ...state, solutions: action.payload }; return { ...state, solutions: action.payload };
case CORRECT_SOLUTION:
const modifiedSolution = state.solutions.find(sol => sol.id === action.payload.id);
const modifiedSolutions = state.solutions.slice();
modifiedSolutions.splice(state.solutions.indexOf(modifiedSolution), 1, action.payload);
return { ...state, solutions: [...modifiedSolutions] };
case ADD_SOLUTION: case ADD_SOLUTION:
return { ...state, solutions: [action.payload, ...state.solutions], id: action.payload.id }; return { ...state, solutions: [action.payload, ...state.solutions], id: action.payload.id };
case ADD_TASK: case ADD_TASK:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment