diff --git a/frontend/src/components/Notification.jsx b/frontend/src/components/Notification.jsx index f2ef079..69a07c6 100644 --- a/frontend/src/components/Notification.jsx +++ b/frontend/src/components/Notification.jsx @@ -9,8 +9,10 @@ import SmallLoader from './SmallLoader'; import Loader from './Loader'; import baseAddress from '../utils/localhost'; import { addNewRoom } from '../redux/userRooms'; + import { setRoomDetail } from '../redux/roomSlice'; import toast from 'react-hot-toast'; +import { v4 as uuidv4 } from 'uuid'; @@ -117,7 +119,7 @@ const Notification = ({setIsNfnOpen}) => { {notifications.length==0 &&
You're all caught up! No new notifications.
}
{notifications?.map(item =><> -
handleClick(item, item.id)} className=' cursor-pointer hover:bg-[#acb499] shadow-sm shadow-lime-800 px-2 py-1 xxs:px-4 xxs:py-2'> +
handleClick(item, item.id)} className=' cursor-pointer hover:bg-[#acb499] shadow-sm shadow-lime-800 px-2 py-1 xxs:px-4 xxs:py-2'>
{item.user2.username} {item.title}{getTime(item.createdAt)} ago
{item.body?
{item.body}
:<>}
diff --git a/frontend/src/components/Posts.jsx b/frontend/src/components/Posts.jsx index 38cee22..b2bfaf3 100644 --- a/frontend/src/components/Posts.jsx +++ b/frontend/src/components/Posts.jsx @@ -14,7 +14,7 @@ import Linkify from 'react-linkify'; -const Posts = ({ id, post, title, body, media, countComment, inRoom, room, createdAt, user, upvotes,joined,postDetails }) => { +const Posts = ({ id, post, title,topic, body, media, countComment, inRoom, room, createdAt, user, upvotes,joined,postDetails }) => { const userInfo = useSelector(state => state.user.userInfo); const isLogin = useSelector(state => state.login.value); const posts = useSelector(state => state.post.posts); @@ -153,7 +153,8 @@ const Posts = ({ id, post, title, body, media, countComment, inRoom, room, creat
Navigate(`/u/${user?.username}`)} src={user && user.dp ? user.dp : dp} alt="Profile" className="w-8 h-8 rounded-full cursor-pointer bg-white" />
- Navigate(`/u/${user?.username}`)} className='font-semibold cursor-pointer hover:text-green-900'>u/{user?.username}•{inRoom && <>q/{room.title} }{`${getTime(createdAt)} ago`} + Navigate(`/u/${user?.username}`)} className='font-semibold cursor-pointer hover:text-green-900'>u/{user?.username}•{(inRoom && <> Navigate(`/room/${user.userID}/${room.title}`)} className=' cursor-pointer hover:text-rose-900 text-sm font-semibold'>q/{room.title} ) + || (topic && <> Navigate(`/q/${topic}`)} className=' cursor-pointer hover:text-rose-900 text-sm font-semibold'>q/{topic} )}{`${getTime(createdAt)} ago`}
diff --git a/frontend/src/pages/HotTopicPosts.jsx b/frontend/src/pages/HotTopicPosts.jsx index a4782fb..c878797 100644 --- a/frontend/src/pages/HotTopicPosts.jsx +++ b/frontend/src/pages/HotTopicPosts.jsx @@ -9,117 +9,133 @@ import Postskelton from '../components/Postskelton'; import { setSkeltonLoader } from '../redux/skelton'; import { clearHotPostsInfo, setHotPost } from '../redux/Hotposts'; import Posts from '../components/Posts'; +import { GrRefresh } from 'react-icons/gr'; +import SmallLoader from '../components/SmallLoader'; -const HotTopicPosts = ({title,topic,dp,bg}) => { +const HotTopicPosts = ({ title, topic, dp, bg }) => { - - - const isSkelton = useSelector((state) => state.skelton.value); - const hotposts = useSelector((state) => state.hotpost.hotposts); - const dispatch = useDispatch(); - const [page, setPage] = useState(1); - const [hasMore, setHasMore] = useState(true); + const [isLoading, setisLoading] = useState(false) + const isSkelton = useSelector((state) => state.skelton.value); + const hotposts = useSelector((state) => state.hotpost.hotposts); + const dispatch = useDispatch(); + const [page, setPage] = useState(1); + const [hasMore, setHasMore] = useState(true); - const getPost = async () => { - dispatch(setSkeltonLoader()) - if(page==1){ - dispatch(clearHotPostsInfo()) - } - try { - const res = await axios.get(`${baseAddress}posts/q/hottopic`, { - params: { - page, - limit: 10, - topic - }, - }); - - if (res.status === 200) { - const fetchedPosts = res.data.posts; - - if (fetchedPosts.length < 10) { - setHasMore(false); - } - - dispatch(setHotPost(fetchedPosts)); - } - } catch (error) { - console.log(error); - setHasMore(false); // Stop fetching if there's an error + + const getPost = async (reset = false) => { + dispatch(setSkeltonLoader()) + setisLoading(true) + try { + if (reset) { + dispatch(clearHotPostsInfo()); + setPage(1); + setHasMore(true); + } + const currentPage = reset ? 1 : page; + const res = await axios.get(`${baseAddress}posts/q/hottopic`, { + params: { + page: currentPage, + limit: 10, + topic + }, + }); + + if (res.status === 200) { + const fetchedPosts = res.data.posts; + + if (fetchedPosts.length < 10) { + setHasMore(false); } - dispatch(setSkeltonLoader()) - }; - useEffect(() => { - setPage(1); // Reset page when topic changes - setHasMore(true); // Reset hasMore when topic changes - getPost(); // Fetch posts for the new topic - dispatch(clearHotPostsInfo()) - }, [topic]); + dispatch(setHotPost(fetchedPosts)); + } + } catch (error) { + console.log(error); + setHasMore(false); // Stop fetching if there's an error + } + dispatch(setSkeltonLoader()) + setisLoading(false) + + }; + + + useEffect(() => { + + getPost(true); // Fetch posts for the new topic + }, [topic]); - - useEffect(() => { - getPost(); - }, [page]); + useEffect(() => { + if (page > 1) + getPost(); + }, [page]); - const fetchMoreData = () => { - setPage((prevPage) => prevPage + 1); - }; + const fetchMoreData = () => { + if (isLoading || !hasMore) return; + setPage(currentPage=> currentPage+1) + }; - return ( -
- + + +
+ + } - endMessage={hotposts.length>0?

You've reached the end of the page!

:

No posts available to display!

} + loader={
} + endMessage={

{`${hotposts.length === 0 ? "It looks like there aren't any posts yet." : "You've reached the end of the page!"}`}

} > - +
+ getPost(true)} className=' bg-[#eff1d3] rounded-full p-1'> + {isLoading ? : } + +
-
- { (!hotposts)||(page==1 && isSkelton) ? ( + {(isSkelton && hotposts.length == 0) ? ( ) : ( hotposts.map((post) => ( - - ) + + ) ) )}
-
+
- - ) + + + ) } export default HotTopicPosts diff --git a/frontend/src/pages/Overview.jsx b/frontend/src/pages/Overview.jsx index c17fb82..ec62220 100644 --- a/frontend/src/pages/Overview.jsx +++ b/frontend/src/pages/Overview.jsx @@ -114,6 +114,7 @@ const Overview = () => { key={`post-${e.id}-${uuidv4()}`} inRoom={e.subCommunity} room={e.room} + topic={e.topic} id={e.id} title={e.title} body={e.body} diff --git a/frontend/src/pages/ProfileComments.jsx b/frontend/src/pages/ProfileComments.jsx index 3ee39f8..45d9db4 100644 --- a/frontend/src/pages/ProfileComments.jsx +++ b/frontend/src/pages/ProfileComments.jsx @@ -260,7 +260,7 @@ export const UserComment = ({ comment }) => {
-

{data.dp ? 'u' : 'q'}/{data.username ? data.username : data?.title} • 

+

Navigate(`/u/${data.username}`) } className=" exclude-click hover:text-green-900 text-sm font-medium overflow-clip">{data.dp ? 'u' : 'q'}/{data.username ? data.username : data?.title} • 

{comment.post.title} @@ -273,7 +273,7 @@ export const UserComment = ({ comment }) => {
{comment?.user.username} {comment.parentId ? ` replied to ` : ' commented '} - {comment.parent?.user.username} + Navigate(`/u/${comment.parent?.user.username}`)} className=' exclude-click hover:text-green-900 text-sm font-mono font-semibold'>{comment.parent?.user.username} {getTime(comment.createdAt)} ago
diff --git a/frontend/src/pages/ProfilePosts.jsx b/frontend/src/pages/ProfilePosts.jsx index 66a37c8..b94bf81 100644 --- a/frontend/src/pages/ProfilePosts.jsx +++ b/frontend/src/pages/ProfilePosts.jsx @@ -95,7 +95,7 @@ const ProfilePosts = () => {
{(isSkelton && userPost.length === 0) ? : userPost.map(post => ( - + )) }