diff --git a/diskuy/src/Threads/Post.js b/diskuy/src/Threads/Post.js index ca76d9a5d5882e98ea875a03f58817c4e0961a94..832d8e43ba4dd81fe385b5b7dc49a308caf4aac2 100644 --- a/diskuy/src/Threads/Post.js +++ b/diskuy/src/Threads/Post.js @@ -9,13 +9,12 @@ export default function Post(props){ const deletePost = async (event) => { try { - if(event.type == "thread") { - console.log("aaaa") - await axios.delete(`${LINK}api/threads/${event.id}` + if(props.type === "thread") { + await axios.delete(`${LINK}api/threads/${props.id}` ,{headers: authHeader()}); - props.history.push(`/`); + props.redirect() } else { - await axios.delete(`${LINK}api/post/${event.id}` + await axios.delete(`${LINK}api/post/${props.id}` ,{headers: authHeader()}); window.location.reload(); } @@ -32,7 +31,7 @@ export default function Post(props){ { AuthService.getCurrentUser().id == props.user_id && ( <div id="headerButton"> - <button type="button" className="btn btn-outline-danger deleteButton" onClick={() => deletePost(props)}>Delete</button> + <button type="button" className="btn btn-outline-danger deleteButton" onClick={deletePost}>Delete</button> </div> )} </div> diff --git a/diskuy/src/Threads/Thread.js b/diskuy/src/Threads/Thread.js index 78a7a848b904f85d3459ff014da0cc803bd1e01b..7b25af1058651200b0e173ef9a818e2f3b0eee7a 100644 --- a/diskuy/src/Threads/Thread.js +++ b/diskuy/src/Threads/Thread.js @@ -10,6 +10,10 @@ import authHeader from '../services/auth-header' const LINK = 'http://localhost:4000/'; export default function Thread(props){ + const redirect = () => { + props.history.push(`/${topicParm}`) + } + const [thread, setThread] = useState({ content : "", id:"", @@ -96,7 +100,9 @@ export default function Thread(props){ user_id={thread.user_id} thread_id={thread.thread_id} topic_id={thread.topic_id} - time={thread.updated_at}/> + time={thread.updated_at} + redirect={redirect} + /> </div> <button type="button" className="btn btn-primary btn_cancel scrollButton" onClick={scrollBottom}>Add New Comment</button>