diff --git a/src/actions/homework.js b/src/actions/homework.js index e10c0122d33b8dc83b672abb20666e40b081b996..206b40f93ba8c926500d6dfd95094c8f4d4c4c13 100644 --- a/src/actions/homework.js +++ b/src/actions/homework.js @@ -14,6 +14,7 @@ import { GET_TASKS, ADD_DOCUMENT, GET_DOCUMENTS, CORRECT_SOLUTION, + SELECT_SOLUTION, CHECK } from './types'; export const getTasks = () => ( @@ -262,8 +263,17 @@ export const correctSolution = (id, corrected, accepted, note) => ( } ); -export const check = () => ( +export const check = name => ( (dispatch) => { - dispatch({ type: CHECK }); + dispatch({ type: CHECK, target: name }); + } +); + +export const selectSolution = solution => ( + (dispatch) => { + dispatch({ + type: SELECT_SOLUTION, + payload: solution, + }); } ); diff --git a/src/actions/types.js b/src/actions/types.js index 9d9ffca6c57401bbf78d6a88ef2424c54fcd324c..d298902813c530d2731c32a493f51f6dba6eb547 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -25,6 +25,7 @@ export const ADD_SOLUTION = 'add_solution'; export const ADD_DOCUMENT = 'add_document'; export const GET_DOCUMENTS = 'get_documents'; export const CORRECT_SOLUTION = 'correct_solution'; +export const SELECT_SOLUTION = 'select_solution'; export const CHECK = 'check'; export const GET_EVENTS = 'get_events'; diff --git a/src/components/forms/CorrectSolutionForm.js b/src/components/forms/CorrectSolutionForm.js index b10efc6e97f3e1b70c69cc2f8c0e6c5099d03f98..a07399eee8e7bfef068487a216673551f2322d43 100644 --- a/src/components/forms/CorrectSolutionForm.js +++ b/src/components/forms/CorrectSolutionForm.js @@ -6,7 +6,8 @@ import { correctSolution, check, clearWrite, getSolutions, - getDocuments } from '../../actions/homework'; + getDocuments, + selectSolution } from '../../actions/homework'; class CorrectSolutionForm extends Component { constructor(props) { @@ -34,18 +35,23 @@ class CorrectSolutionForm extends Component { } else { fileLink = null; } - - - const { note } = this.props.correction; + const { + corrected, + accepted, + note, + } = this.props.correction; return ( <Modal open={this.state.showModal} trigger={ <Button inverted - color='orange' + color={this.props.color} style={{ marginRight: '1.5em', marginTop: '1.5em' }} - onClick={() => { this.setState({ showModal: true }); }} + onClick={() => { + this.setState({ showModal: true }); + this.props.selectSolution(relevantSolution); + }} > {studentFullName} </Button> @@ -65,13 +71,36 @@ class CorrectSolutionForm extends Component { {fileLink === null ? <p>Nincs fĂĄjl.</p> : <a href={fileLink}>FĂĄjl letĂśltĂŠse</a>} - <Header as='h5'>ElfogadĂĄs/ElutasĂtĂĄs:</Header> - <Button color={this.props.correction.accepted ? 'green' : 'red'} onClick={() => this.props.check()}> + <Header as='h5'>KijavĂtĂĄs ĂĄllapotĂĄnak vĂĄltoztatĂĄsa:</Header> + <Button + color='orange' + inverted={corrected} + onClick={() => this.props.check('corrected')} + > + <Checkbox + label='Nincs kijavĂtva' + checked={!corrected} + /> + </Button> + <Header as='h5'>ElfogadĂĄs/elutasĂtĂĄs:</Header> + <Button + color='green' + inverted={!accepted} + onClick={() => this.props.check('accepted')} + > + <Checkbox + label='ElfogadhatĂł' + checked={accepted} + /> + </Button> + <Button + color='red' + inverted={accepted} + onClick={() => this.props.check('accepted')} + > <Checkbox - label={this.props.correction.accepted - ? 'ElfogadhatĂł' - : 'Nem elfogadhatĂł'} - checked={this.props.correction.accepted} + label='Nem elfogadhatĂł' + checked={!accepted} /> </Button> <Header as='h5'>A feladat megoldĂĄsĂĄnak szĂśveges ĂŠrtĂŠkelĂŠse:</Header> @@ -102,9 +131,9 @@ class CorrectSolutionForm extends Component { onClick={() => { this.props.correctSolution( relevantSolution.id, - true, - this.props.correction.accepted, - this.props.correction.note, + corrected, + accepted, + note, ); this.setState({ showModal: false }); this.props.clearWrite(); @@ -127,4 +156,5 @@ export default connect(mapStateToProps, { clearWrite, getSolutions, getDocuments, + selectSolution, })(CorrectSolutionForm); diff --git a/src/components/forms/SolutionDetailsForm.js b/src/components/forms/SolutionDetailsForm.js index f503b6c2d0eff4478b264430ae5172598d9ac2ba..b15d1e54befbadcdb2d871d48a4d92e812738fb7 100644 --- a/src/components/forms/SolutionDetailsForm.js +++ b/src/components/forms/SolutionDetailsForm.js @@ -83,6 +83,7 @@ class SolutionDetailsForm extends Component { waitForCorrectionStudents.map(student => ( <CorrectSolutionForm key={Math.random()} + color='orange' studentName={student.nick} studentFullName={student.full_name} studentId={student.id} @@ -92,19 +93,35 @@ class SolutionDetailsForm extends Component { )) } <Divider /> - <Header as='h3'>A megoldĂĄs nem elfogadhatĂł:</Header> + <Header as='h3'>A megoldĂĄs nem elfogadhatĂł (A nĂŠvre kattintva mĂłdosĂthatĂł a javĂtĂĄs):</Header> {noAcceptStudents.length === 0 ? emptyMessage(emptyStudentText) : noAcceptStudents.map(student => ( - <Button key={Math.random()} color='red' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button> + <CorrectSolutionForm + key={Math.random()} + color='red' + studentName={student.nick} + studentFullName={student.full_name} + studentId={student.id} + taskTitle={this.props.tasktitle} + taskSolutions={taskSolutions} + /> )) } <Divider /> - <Header as='h3'>Elfogadva:</Header> + <Header as='h3'>Elfogadva (A nĂŠvre kattintva mĂłdosĂthatĂł a javĂtĂĄs):</Header> {acceptedStudents.length === 0 ? emptyMessage(emptyStudentText) : acceptedStudents.map(student => ( - <Button key={Math.random()} color='green' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{student.full_name}</Button> + <CorrectSolutionForm + key={Math.random()} + color='green' + studentName={student.nick} + studentFullName={student.full_name} + studentId={student.id} + taskTitle={this.props.tasktitle} + taskSolutions={taskSolutions} + /> )) } </Modal.Content> diff --git a/src/reducers/CorrectSolutionReducer.js b/src/reducers/CorrectSolutionReducer.js index aa118c5ff1a56e67ba16ec85d246387c64282446..b64bf26fbbf43b5ce10112b537acfaff91129d97 100644 --- a/src/reducers/CorrectSolutionReducer.js +++ b/src/reducers/CorrectSolutionReducer.js @@ -1,16 +1,26 @@ -import { WRITE_SOLUTION, CHECK, CLEAR_WRITE } from '../actions/types'; +import { WRITE_SOLUTION, CHECK, CLEAR_WRITE, SELECT_SOLUTION } from '../actions/types'; const INITIAL_STATE = { accepted: false, + corrected: false, note: '', }; export default (state = INITIAL_STATE, action) => { switch (action.type) { + case SELECT_SOLUTION: + return { + corrected: action.payload.corrected, + accepted: action.payload.accepted, + note: action.payload.note, + }; case WRITE_SOLUTION: return { ...state, [action.target]: action.payload }; case CHECK: - return { ...state, accepted: !state.accepted }; + return { + ...state, + [action.target]: !state[action.target], + }; case CLEAR_WRITE: return INITIAL_STATE; default: