@@ -8,6 +8,7 @@ import Video from './video'
88import Image from 'next/image'
99import Reaction from './reaction'
1010import { useState , useEffect } from 'react'
11+ import toast from 'react-hot-toast'
1112import EmojiPicker from 'emoji-picker-react'
1213
1314const 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