diff --git a/src/components/forum/forumSubjects.js b/src/components/forum/forumSubjects.js
index 36e85ec..c86a138 100644
--- a/src/components/forum/forumSubjects.js
+++ b/src/components/forum/forumSubjects.js
@@ -128,9 +128,9 @@ const ForumSubjects = ({
@@ -24,18 +57,63 @@ const IndexForum = ({ user, threads, getAllThreads, getThreadSubjects }) => {
@@ -64,8 +142,10 @@ const mapStateToProps = state => ({
})
const mapDispatchToProps = dispatch => ({
+ addThread: threads => dispatch( addThread(threads) ),
+ deleteThread: threads => dispatch( deleteThread(threads) ),
getAllThreads: () => dispatch( getAllThreads() ),
- getThreadSubjects: thread => dispatch( getThreadSubjects(thread) )
+ getThreadSubjects: threads => dispatch( getThreadSubjects(threads) )
})
export default connect(mapStateToProps, mapDispatchToProps)(IndexForum)
diff --git a/src/components/forum/indexForumUpdate.js b/src/components/forum/indexForumUpdate.js
new file mode 100644
index 0000000..b6d3b08
--- /dev/null
+++ b/src/components/forum/indexForumUpdate.js
@@ -0,0 +1,95 @@
+import React, { useState } from 'react'
+import { connect } from 'react-redux'
+
+import { updateThread } from '../../stores/threads/duck/operations'
+
+import '../../styles/indexForum.scss'
+
+const IndexForumUpdate = ({
+ user,
+ threads, getAllThreads, getThreadSubjects, updateThread,
+ thread, thisThread }) => {
+
+ const updateThreadTitle = React.createRef()
+ const [threadTitleText, setThreadTitleText] = useState(0)
+
+ const [selectThreadModeratorID, setSelectThreadModeratorID] = useState(-1)
+
+ const updateOldThread = (event) => {
+ event.preventDefault()
+ if ( updateThreadTitle.current.value !== '' && selectThreadModeratorID === -1 && user.privilige >= 2) {
+ let putThread = {
+ id: thread.id,
+ name: updateThreadTitle.current.value,
+ user_id: thread.user_id,
+ token: user.token
+ }
+ updateThread(putThread)
+ updateThreadTitle.current.value = ''
+ } else if ( updateThreadTitle.current.value !== '' && user.privilige === 3 ) {
+ let putThread = {
+ id: thread.id,
+ name: updateThreadTitle.current.value,
+ user_id: selectThreadModeratorID === -1 ? thread.user_id : selectThreadModeratorID,
+ token: user.token
+ }
+ updateThread(putThread)
+ updateThreadTitle.current.value = ''
+ }
+ }
+
+ if ( thisThread.isActive === true && thisThread.thread_id === thread.id ) {
+ return (
+
+ )
+ } else {
+ return (
+
+
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ user: state.user,
+ threads: state.threads
+})
+
+const mapDispatchToProps = dispatch => ({
+ updateThread: threads => dispatch( updateThread(threads) )
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(IndexForumUpdate)
diff --git a/src/stores/threads/duck/operations.js b/src/stores/threads/duck/operations.js
index cd882a5..4138c0c 100644
--- a/src/stores/threads/duck/operations.js
+++ b/src/stores/threads/duck/operations.js
@@ -22,6 +22,43 @@ const fetchGetSubjects = async (threadID) => {
return response.json()
}
+const fetchAddThread = async (data) => {
+ const response = await
+ fetch(
+ 'http://localhost:8001/index/thread', {
+ method: 'POST',
+ credential: 'same-origin',
+ body: JSON.stringify(data)
+ }
+ )
+ return response.json()
+}
+
+const fetchUpdateThread = async (data) => {
+ const response = await
+ fetch(
+ 'http://localhost:8001/index/thread/' + data.id, {
+ method: 'PUT',
+ credential: 'same-origin',
+ body: JSON.stringify(data)
+ }
+ )
+ return response.json()
+}
+
+const fetchDeleteThread = async (data) => {
+ const response = await
+ fetch(
+ 'http://localhost:8001/index/thread/' + data.thread_id, {
+ method: 'DELETE',
+ credential: 'same-origin',
+ body: JSON.stringify(data)
+ }
+ )
+ return response.json()
+}
+
+
export const getAllThreads = () =>
async (dispatch) => {
const allThreads = await fetchGetAll()
@@ -41,3 +78,18 @@ export const getThreadSubjects = (data) =>
dispatch( actions.activate(data) )
dispatch( actions.getThreadSubjects(subjects) )
}
+
+export const addThread = (data) =>
+ async (dispatch) => {
+ const subjects = await fetchAddThread(data)
+ }
+
+export const updateThread = (data) =>
+ async (dispatch) => {
+ const subjects = await fetchUpdateThread(data)
+ }
+
+export const deleteThread = (data) =>
+ async (dispatch) => {
+ const subjects = await fetchDeleteThread(data)
+ }
diff --git a/src/styles/general.scss b/src/styles/general.scss
index b5fe1a1..5c13fce 100644
--- a/src/styles/general.scss
+++ b/src/styles/general.scss
@@ -2,7 +2,11 @@
body {
margin: 0 auto;
+ overflow-y: hidden;
+ ::-webkit-scrollbar {
+ display: none;
+ }
input {
@include inputStyle
}