From 65af42ed1ec1244706d48b0ce200c68b40f40797 Mon Sep 17 00:00:00 2001 From: Rituraj Singh <2300520140055@ietlucknow.ac.in> Date: Sun, 8 Sep 2024 02:15:41 +0530 Subject: [PATCH] devi --- frontend/src/components/AddMemBox.jsx | 3 +- frontend/src/components/Notification.jsx | 144 ++++++++++------------- frontend/src/components/Polls.jsx | 1 - frontend/src/components/Posts.jsx | 1 - frontend/src/pages/CreatePost.jsx | 1 - frontend/src/pages/HotTopicPosts.jsx | 2 +- frontend/src/pages/ProfilePosts.jsx | 133 +++++++++++---------- frontend/src/pages/Room.jsx | 13 +- 8 files changed, 144 insertions(+), 154 deletions(-) diff --git a/frontend/src/components/AddMemBox.jsx b/frontend/src/components/AddMemBox.jsx index 97903e1..163be8f 100644 --- a/frontend/src/components/AddMemBox.jsx +++ b/frontend/src/components/AddMemBox.jsx @@ -54,7 +54,6 @@ export default function AddMemBox({ setShow, id, update }) { setFetching(true) const res = await axios.get(baseAddress + "rooms/titleNameIsUnique?filter=" + title2); - console.log(res); if (res.data.msg == true) { setColor("green"); @@ -141,7 +140,7 @@ export default function AddMemBox({ setShow, id, update }) { const res = await axios.post(`${baseAddress}rooms/addUserinRoom/${title}`, { title: id }); - console.clear(); + // console.log(res); const msg = res?.data.msg; // console.log(msg); diff --git a/frontend/src/components/Notification.jsx b/frontend/src/components/Notification.jsx index 40517ba..6e73b49 100644 --- a/frontend/src/components/Notification.jsx +++ b/frontend/src/components/Notification.jsx @@ -22,63 +22,62 @@ import SmoothLoader from '../assets/SmoothLoader'; axios.defaults.withCredentials = true -const Notification = ({setIsNfnOpen}) => { +const Notification = ({ setIsNfnOpen }) => { const notifications = useSelector(state => state.notification.notifications); const dispatch = useDispatch(); - const Navigate =useNavigate(); + const Navigate = useNavigate(); const [isLoading, setIsLoading] = useState(false); - const [bigLoader,setBigLoader] = useState(false); - const [RoomPost,setRoomPost] = useState(null); + const [bigLoader, setBigLoader] = useState(false); + const [RoomPost, setRoomPost] = useState(null); const location = useLocation(); - const handleRefresh= async()=>{ + const handleRefresh = async () => { setIsLoading(true); getUserNotification() } - const getUserNotification = async()=>{ - + const getUserNotification = async () => { + try { - const res = await axios.get(baseAddress+"u/notification", { withCredentials: true }); - dispatch(setNotification(res.data.data)) - + const res = await axios.get(baseAddress + "u/notification", { withCredentials: true }); + dispatch(setNotification(res.data.data)) + } catch (error) { - console.log(error); + console.log(error); } setIsLoading(false) - } - const requestByUser = async(title,body,fromUser)=>{ + } + const requestByUser = async (title, body, fromUser) => { setBigLoader(true); - try{ - const res = await axios.post(`${baseAddress}rooms//addUserinRoom/${fromUser}`,{ - title + try { + const res = await axios.post(`${baseAddress}rooms//addUserinRoom/${fromUser}`, { + title }) toast.success(res.data.msg); - }catch(err){ + } catch (err) { toast.error(err.response.data.msg); console.log(err); } setBigLoader(false) } - const requestByOwner = async(title,fromUser)=>{ + const requestByOwner = async (title, fromUser) => { setBigLoader(true) try { - const res = await axios.post(`${baseAddress}rooms/acceptJoiningRequest`,{ + const res = await axios.post(`${baseAddress}rooms/acceptJoiningRequest`, { title, fromUser }) - - if(res.status == 200) - { + + if (res.status == 200) { const room = res?.data?.room; dispatch(addNewRoom(room)); const creatorId = room?.CreatorId; const title = room?.title; setBigLoader(false); - Navigate(`/room/${creatorId}/${title}`,{state:{joined:true}}); + Navigate(`/room/${creatorId}/${title}`, { state: { joined: true } }); toast.success(res.data.msg); } - else{ + else { toast.error(res.data.msg); } setBigLoader(false) @@ -87,89 +86,84 @@ const Notification = ({setIsNfnOpen}) => { toast.error(error?.response?.data.msg); } } - const getApost=async(id)=>{ + const getApost = async (id) => { try { - const res = await axios.get(baseAddress+"posts/getapost", { - params:{ - id, + const res = await axios.get(baseAddress + "posts/getapost", { + params: { + id, + } + }); + if (res.status == 200) { + + dispatch(setPostDetail(res.data.post)) + if (res.data.post.room) Navigate(`/post/${res.data.post.room.id}/${res.data.post.id}`) + else Navigate(`/post/${res.data.post.id}`); } - }); - console.clear(); - console.log(res.data.post); - if(res.status==200){ - - console.log(res.data.post.room); - dispatch(setPostDetail(res.data.post)) - if(res.data.post.room)Navigate(`/post/${res.data.post.room.id}/${res.data.post.id}`) - else Navigate(`/post/${res.data.post.id}`); - } } catch (error) { - console.log(error); + console.log(error); } - } - const handleClick=(item, nId)=>{ + } + const handleClick = (item, nId) => { setIsNfnOpen(false); markAsRead(nId); - if(item.postId) - { + if (item.postId) { dispatch(clearPostDetail()) getApost(item.postId); - + } - else - { - if(item.title === "Join My Room") - requestByOwner(item.body,item.fromUser); - else{ - requestByUser(item.title,item.body,item.fromUser); + else { + if (item.title === "Join My Room") + requestByOwner(item.body, item.fromUser); + else { + requestByUser(item.title, item.body, item.fromUser); } } } - const handleAllRead = async() => { + const handleAllRead = async () => { setIsNfnOpen(false) - if(notifications.length==0) return; + if (notifications.length == 0) return; try { - const res = await axios.post(baseAddress+"u/markallasread", { withCredentials: true }); - if(res.status==202){ + const res = await axios.post(baseAddress + "u/markallasread", { withCredentials: true }); + if (res.status == 202) { dispatch(clearNotification()); } } catch (error) { - console.log(error); + console.log(error); } - + } - const markAsRead=async(id)=>{ - + const markAsRead = async (id) => { + try { - const res = await axios.post(baseAddress+"u/markasread", { id }); - if(res.status==201){ + const res = await axios.post(baseAddress + "u/markasread", { id }); + if (res.status == 201) { dispatch(updateNotification(id)); } - + } catch (error) { console.log(error); - + } } return (
- {isLoading?:handleRefresh()}/>} + {isLoading ? : handleRefresh()} />}
Notifications
- {notifications.length==0 &&
You're all caught up! No new notifications.
} + {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'> -
{item.user2.username} {item.title}{getTime(item.createdAt)} ago
- {item.body?
{item.body}
:<>} -
- - )} + {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'> +
{item.user2.username} {item.title}{getTime(item.createdAt)} ago
+ {item.body ?
{item.body}
: <>} +
+ ) + )}
@@ -181,14 +175,6 @@ const Notification = ({setIsNfnOpen}) => { } export default Notification -export const Message = ({ }) => { - return (<> - - - - - ) -} diff --git a/frontend/src/components/Polls.jsx b/frontend/src/components/Polls.jsx index ab674c2..7ed9667 100644 --- a/frontend/src/components/Polls.jsx +++ b/frontend/src/components/Polls.jsx @@ -172,7 +172,6 @@ const deletePoll=async(id)=>{ return; } Navigate(`/poll/${id}`) - console.log("click"); }; diff --git a/frontend/src/components/Posts.jsx b/frontend/src/components/Posts.jsx index 5761afa..92b076a 100644 --- a/frontend/src/components/Posts.jsx +++ b/frontend/src/components/Posts.jsx @@ -250,7 +250,6 @@ const Posts = ({ id, post, title,topic, body, media, countComment, inRoom, room, }; const shareFunction = async(id,room)=>{ - console.log("Clicked Share Button") if(inRoom) { if(!joined){ diff --git a/frontend/src/pages/CreatePost.jsx b/frontend/src/pages/CreatePost.jsx index 509fd31..8397c20 100644 --- a/frontend/src/pages/CreatePost.jsx +++ b/frontend/src/pages/CreatePost.jsx @@ -340,7 +340,6 @@ export const CreatePoll = () => { title, options: options.filter(option => option.trim() !== ''), }; - console.log("Handle SUbmit",roomTitle); try { const res = await axios.post(`${baseAddress}poll/createpoll`, { title: poll.title, diff --git a/frontend/src/pages/HotTopicPosts.jsx b/frontend/src/pages/HotTopicPosts.jsx index 62c8362..44b9ced 100644 --- a/frontend/src/pages/HotTopicPosts.jsx +++ b/frontend/src/pages/HotTopicPosts.jsx @@ -83,7 +83,7 @@ const HotTopicPosts = ({ title, topic, dp, bg }) => { return () => clearTimeout(timeoutId); // Cleanup the timeout }, [topic, title]); - // Handle fetching more data (pagination) + useEffect(() => { if (page > 1) { getPost(false, page); // Fetch posts for the current page diff --git a/frontend/src/pages/ProfilePosts.jsx b/frontend/src/pages/ProfilePosts.jsx index 06c6dc3..13fd84b 100644 --- a/frontend/src/pages/ProfilePosts.jsx +++ b/frontend/src/pages/ProfilePosts.jsx @@ -4,7 +4,7 @@ import Postskelton, { PollSkelton } from '../components/Postskelton'; import { useSelector, useDispatch } from 'react-redux'; import InfiniteScroll from 'react-infinite-scroll-component'; import { setSkeltonLoader } from '../redux/skelton'; -import userposts, { clearUserPostsInfo, setPost } from '../redux/userposts'; +import userposts, { clearUserPostsInfo, setPost } from '../redux/userposts'; import axios from 'axios'; import { v4 as uuidv4 } from 'uuid'; import { useOutletContext, useParams } from 'react-router-dom'; @@ -31,7 +31,7 @@ const ProfilePosts = () => { const getUserPost = async (reset = false) => { - + setisLoading(true) try { if (reset) { @@ -51,8 +51,8 @@ const ProfilePosts = () => { }, withCredentials: true, }); - - + + if (res.status === 200) { if (res.data.posts.length < 10) { @@ -64,10 +64,10 @@ const ProfilePosts = () => { } catch (error) { console.log(error); } - + setisLoading(false) }; - + useEffect(() => { getUserPost(true); @@ -82,9 +82,9 @@ const ProfilePosts = () => { const fetchMoreData = () => { - if (isLoading || !hasMore) return; + if ( !hasMore) return; setPage(prevPage => prevPage + 1); - + }; @@ -111,7 +111,7 @@ const ProfilePosts = () => { export default ProfilePosts; -export const ProfilePoll= ()=>{ +export const ProfilePoll = () => { const userPoll = useSelector(state => state.userpoll.polls); const isSkelton = useSelector(state => state.skelton.value); const dispatch = useDispatch(); @@ -121,34 +121,36 @@ export const ProfilePoll= ()=>{ const { username } = useParams(); const [isLoading, setisLoading] = useState(false) - const getPoll =async(reset= false)=>{ + const getPoll = async (reset = false) => { + // if(isLoading) return setisLoading(true) dispatch(setSkeltonLoader()) - if(reset){ + if (reset) { dispatch(clearPollInfo()) setPage(1); setHasMore(true) } try { - const res= await axios.get(`${baseAddress}search/getuserpolls`, { - params:{ + const res = await axios.get(`${baseAddress}search/getuserpolls`, { + params: { userId: user.userID, page, - limit: 15, + limit: 10, } }) - console.log(res); - if(res.status==200){ + + if (res.status == 200) { dispatch(setPoll(res.data)) - if(res.data.length<10){ + if (res.data.length < 10) { setHasMore(false) } } - + } catch (error) { + console.log(error); } setisLoading(false) @@ -165,22 +167,27 @@ export const ProfilePoll= ()=>{ if (page > 1) { getPoll(); } - }, [page]); + }, [page, ]); const fetchMoreData = () => { - console.log("Inside Profile Polls ",isLoading) - if (isLoading || !hasMore) return; + + if ( !hasMore) return; setPage(prevPage => prevPage + 1); }; - + + + + + + return ( - { ) } -export const ProfilePostOrPoll= ()=>{ +export const ProfilePostOrPoll = () => { const [disVal, setdisVal] = useState("post") - return( + return (
- -
- setdisVal("post")} - checked={disVal === "post"} - type="radio" - value="post" - name="post_poll" - id="post" - /> - -
-
- setdisVal("poll")} - checked={disVal === "poll"} - type="radio" - value="poll" - name="post_poll" - id="poll" - /> - -
-
- - - {disVal==="post" && } - {disVal==="poll" && } + +
+ setdisVal("post")} + checked={disVal === "post"} + type="radio" + value="post" + name="post_poll" + id="post" + /> + +
+
+ setdisVal("poll")} + checked={disVal === "poll"} + type="radio" + value="poll" + name="post_poll" + id="poll" + /> + +
+
+ + + {disVal === "post" && } + {disVal === "poll" && }
diff --git a/frontend/src/pages/Room.jsx b/frontend/src/pages/Room.jsx index 22d691a..dcdff27 100644 --- a/frontend/src/pages/Room.jsx +++ b/frontend/src/pages/Room.jsx @@ -518,7 +518,7 @@ export const RoomPost = ({title,privateRoom,joined,data})=>{ const [cancelTokenSource, setCancelTokenSource] = useState(null); const getPost = async (initial) => { if (cancelTokenSource) { - // cancelTokenSource.cancel('Previous request canceled due to new topic.'); + cancelTokenSource.cancel('Previous request canceled due to new topic.'); } const source = axios.CancelToken.source(); @@ -534,8 +534,8 @@ export const RoomPost = ({title,privateRoom,joined,data})=>{ } else { if (page == 0 || initial) { - setPage(0); dispatch(clearHotPostsInfo()) + setPage(0); } try { // dispatch(setSkeltonLoader()) @@ -572,11 +572,11 @@ export const RoomPost = ({title,privateRoom,joined,data})=>{ useEffect(()=>{ // console.log("Inside useeffect") - setPage(0); dispatch(clearHotPostsInfo()); + setPage(0); setHasMore(true); setisLoading(true); - const timeID = setTimeout(getPost(true),500); + const timeID = setTimeout(getPost(true),1500); return ()=> clearTimeout(timeID); },[title,data,joined,privateRoom]) @@ -658,16 +658,17 @@ export const RoomPolls = ({title,privateRoom,joined,data})=>{ if(page>0)getRoomsPolls(joined,privateRoom,dispatch,setPoll,clearPollInfo,setisLoading,isLoading,setHasMore,page,title); } }, [page]) + const fetchMoreData = () => { console.log("InPolls ",page,isLoading,hasMore); - if (isLoading || !hasMore) return; + if (!hasMore) return; setPage((prevPage) => prevPage + 10); }; return
{privateRoom && !joined ? : { fetchMoreData }} + next={fetchMoreData } hasMore={hasMore} loader={} endMessage={hotposts.length > 0 ?

{"You've reached the end of the page!"}

:

No Polls available to display!

}