diff --git a/src/components/forum/forumSubjectUpdate.js b/src/components/forum/forumSubjectUpdate.js new file mode 100644 index 0000000..1d20122 --- /dev/null +++ b/src/components/forum/forumSubjectUpdate.js @@ -0,0 +1,102 @@ +import React, { useState } from 'react' +import { connect } from 'react-redux' + +import { refreshThreadSubjects } from '../../stores/threads/duck/operations' +import { getSubjectComments, updateSubject } from '../../stores/subjects/duck/operations' + +import '../../styles/indexForum.scss' + +const ForumSubjectUpdate = ({ + user, + threads, deactivate, + subjects, updateSubject, getSubjectComments, + subject, thisSubject }) => { + + const [formDiv, setFormDiv] = useState(false) + + const updateSubjectTitle = React.createRef() + const updateSubjectAuthor = React.createRef() + + const updateOldSubject = (event) => { + event.preventDefault() + if ( updateSubjectTitle.current.value !== '') { + let putSubject = { + id: subject.id, + name: updateSubjectTitle.current.value, + user_id: user.id, + thread_id: threads.actualThreadID, + token: user.token + } + updateSubject(putSubject) + updateSubjectTitle.current.value = '' + } + } + + const [subjectTitleText, setSubjectTitleText] = useState(0) + const [titleText, setTitleText] = useState(0) + + if ( thisSubject.isActive === true && thisSubject.subject_id === subject.id) { + return ( +
+
+ setSubjectTitleText( e.target.value.length ) }> + + { (user.privilige >= 2) ? ( +
+ + +
+ ) : ( +
+ ) + } +

{subjectTitleText}/30

+ +
+
+ ) + } else { + return ( +
+
+ ) + } +} + +const mapStateToProps = state => ({ + user: state.user, + threads: state.threads, + subjects: state.subjects, + comments: state.comments +}) + +const mapDispatchToProps = dispatch => ({ + refreshThreadSubjects: threads => dispatch( refreshThreadSubjects(threads) ), + getSubjectComments: subjects => dispatch( getSubjectComments(subjects) ), + updateSubject: subjects => dispatch( updateSubject(subjects) ) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(ForumSubjectUpdate)