-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implemented user liked and bookmarked tweets functionality in u…
…ser profile
- Loading branch information
1 parent
b56ee71
commit e17084d
Showing
10 changed files
with
268 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Spinner, TweetCard, useToast } from "@/components/Index"; | ||
import axios from "axios"; | ||
|
||
const BookmarkedTweets = () => { | ||
const { toast } = useToast(); | ||
const [loading, setLoading] = useState(false); | ||
const [tweets, setTweets] = useState([]); | ||
|
||
const bookmarkedTweets = async () => { | ||
setLoading(true); | ||
try { | ||
const response = await axios.get( | ||
`${import.meta.env.VITE_BACKEND_URL}/bookmarks`, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
// console.log(response.data.data[0].bookmarkedTweet) | ||
setTweets(response.data.data[0].bookmarkedTweet); | ||
setLoading(false); | ||
} catch (error) { | ||
console.log(error); | ||
toast({ | ||
variant: "destructive", | ||
title: "error", | ||
description: `${error.message}`, | ||
}); | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const removeFromBookmarks = (tweetId) => { | ||
setTweets((prevTweets) => | ||
prevTweets.filter((tweet) => tweet._id !== tweetId) | ||
); | ||
toast({ | ||
title: "Removed from your bookmarks", | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
bookmarkedTweets(); | ||
}, []); | ||
|
||
return loading ? ( | ||
<Spinner /> | ||
) : ( | ||
tweets.map((tweet) => ( | ||
<TweetCard | ||
key={tweet._id} | ||
tweet={tweet} | ||
setTweets={setTweets} | ||
removeFromBookmarks={removeFromBookmarks} | ||
/> | ||
)) | ||
); | ||
}; | ||
|
||
export default BookmarkedTweets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Spinner, TweetCard, useToast } from "@/components/Index"; | ||
import axios from "axios"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
const LikedTweets = () => { | ||
const { toast } = useToast(); | ||
const [loading, setLoading] = useState(false); | ||
const [tweets, setTweets] = useState([]); | ||
|
||
const userTweets = async () => { | ||
setLoading(true); | ||
try { | ||
const response = await axios.get( | ||
`${import.meta.env.VITE_BACKEND_URL}/like/tweets`, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
console.log(response); | ||
setTweets(response.data.data[0].likedTweets); | ||
setLoading(false); | ||
} catch (error) { | ||
console.log(error); | ||
toast({ | ||
variant: "destructive", | ||
title: "error", | ||
description: `${error.message}`, | ||
}); | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const removeFromLikes = (tweetId) => { | ||
setTweets((prevTweets) => | ||
prevTweets.filter((tweet) => tweet._id !== tweetId) | ||
); | ||
toast({ | ||
title: "Removed from your likes", | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
userTweets(); | ||
}, []); | ||
|
||
loading && <Spinner />; | ||
|
||
return tweets.map((tweet) => ( | ||
<TweetCard | ||
key={tweet._id} | ||
tweet={tweet} | ||
setTweets={setTweets} | ||
removeFromLikes={removeFromLikes} | ||
/> | ||
)); | ||
}; | ||
|
||
export default LikedTweets; |
Oops, something went wrong.