Skip to content

Commit c4906b4

Browse files
committed
Adds toast!
1 parent 3fa8176 commit c4906b4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

components/post.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Video from './video'
88
import Image from 'next/image'
99
import Reaction from './reaction'
1010
import { useState, useEffect } from 'react'
11+
import toast from 'react-hot-toast'
1112
import EmojiPicker from 'emoji-picker-react'
1213

1314
const imageFileTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp']
@@ -62,21 +63,24 @@ const Post = ({
6263

6364

6465
const deletePost = async (id) => {
65-
try {
66-
const response = await fetch('/api/web/post/delete', {
66+
toast.promise(
67+
fetch('/api/web/post/delete', {
6768
method: 'DELETE',
6869
headers: {
6970
'Content-Type': 'application/json',
7071
},
7172
body: JSON.stringify({ id })
72-
});
73-
const responseText = await response.text()
74-
if (responseText.includes("Post Deleted")) {
75-
setIsVisible(false);
73+
}).then(response => response.text()).then(responseText => {
74+
if (responseText.includes("Post Deleted")) {
75+
setIsVisible(false);
76+
}
77+
}),
78+
{
79+
loading: 'Deleting post...',
80+
success: 'Post Deleted Successfully!',
81+
error: 'Error deleting post.',
7682
}
77-
} catch (error) {
78-
console.error('Error:', error);
79-
}
83+
);
8084
};
8185

8286
if (!isVisible) {

0 commit comments

Comments
 (0)