Skip to content

Commit

Permalink
Adds toast!
Browse files Browse the repository at this point in the history
  • Loading branch information
cskartikey committed Jun 13, 2024
1 parent 3fa8176 commit c4906b4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions components/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Video from './video'
import Image from 'next/image'
import Reaction from './reaction'
import { useState, useEffect } from 'react'
import toast from 'react-hot-toast'
import EmojiPicker from 'emoji-picker-react'

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


const deletePost = async (id) => {
try {
const response = await fetch('/api/web/post/delete', {
toast.promise(
fetch('/api/web/post/delete', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id })
});
const responseText = await response.text()
if (responseText.includes("Post Deleted")) {
setIsVisible(false);
}).then(response => response.text()).then(responseText => {
if (responseText.includes("Post Deleted")) {
setIsVisible(false);
}
}),
{
loading: 'Deleting post...',
success: 'Post Deleted Successfully!',
error: 'Error deleting post.',
}
} catch (error) {
console.error('Error:', error);
}
);
};

if (!isVisible) {
Expand Down

0 comments on commit c4906b4

Please sign in to comment.