From d3045cab066b1d5d8e2c757e0e7bdd646ec40a6e Mon Sep 17 00:00:00 2001 From: FadhilP <fadhilpradipta0@gmail.com> Date: Fri, 8 Jan 2021 22:07:40 +0700 Subject: [PATCH] fix redirect after deleting a thread --- diskuy/src/Threads/Post.js | 11 +++++------ diskuy/src/Threads/Thread.js | 8 +++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/diskuy/src/Threads/Post.js b/diskuy/src/Threads/Post.js index ca76d9a..832d8e4 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 78a7a84..7b25af1 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> -- GitLab