Skip to content

Commit

Permalink
Merge pull request #64 from Rituraj67/master
Browse files Browse the repository at this point in the history
bugs
  • Loading branch information
imdeveshshukla authored Sep 7, 2024
2 parents dbc1a5a + 78795b8 commit 473ec32
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 152 deletions.
3 changes: 1 addition & 2 deletions frontend/src/components/AddMemBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
144 changes: 65 additions & 79 deletions frontend/src/components/Notification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
<div className=' rounded-2xl shadow-md shadow-current absolute top-20 right-2 xxs:right-5 xs:right-20 w-[96vw] xxs:w-[90vw] xs:w-[75vw] sm:w-[55vw] 2_sm:w-[50vw] md:w-[46vw] 1_5md:w-[43vw] 2_md:w-[40vw] lg:w-[37vw] 1_5lg:w-[33vw] xl:w-[30vw] bg-[#c2c7b3] '>

<span className=' absolute right-4 top-1 text-white text-xl'>{isLoading?<SmoothLoader/>:<FiRefreshCcw className=' cursor-pointer' onClick={()=>handleRefresh()}/>}</span>
<span className=' absolute right-4 top-1 text-white text-xl'>{isLoading ? <SmoothLoader /> : <FiRefreshCcw className=' cursor-pointer' onClick={() => handleRefresh()} />}</span>

<div className=' bg-[#6f742b] text-white rounded-t-2xl text-center p-1'>Notifications</div>
{notifications.length==0 && <div className=' p-4 text-red-950 text-center font-semibold'>You're all caught up! No new notifications.</div>}
{notifications.length == 0 && <div className=' p-4 text-red-950 text-center font-semibold'>You're all caught up! No new notifications.</div>}
<div className=' max-h-[70vh] sm:max-h-[60vh] overflow-auto scrollable-box'>
{notifications?.map(item =><>
<div key={`${uuidv4()}${item.id}`} onClick={()=>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'>
<div className=' flex items-center justify-between'><span className='text-md '><span className='font-semibold'>{item.user2.username} </span>{item.title}</span><span className=' text-xs text-slate-600'>{getTime(item.createdAt)} ago</span></div>
{item.body?<div className='whitespace-pre-wrap break-words text-sm line-clamp-3 bg-[#9eb840] overflow-clip px-3 text-white m-1 py-1 rounded-lg'>{item.body}</div>:<></>}
</div>
</>
)}
{notifications?.map(item => (
<div key={`${uuidv4()}${item.id}`} onClick={() => 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'>
<div className=' flex items-center justify-between'><span className='text-md '><span className='font-semibold'>{item.user2.username} </span>{item.title}</span><span className=' text-xs text-slate-600'>{getTime(item.createdAt)} ago</span></div>
{item.body ? <div className='whitespace-pre-wrap break-words text-sm line-clamp-3 bg-[#9eb840] overflow-clip px-3 text-white m-1 py-1 rounded-lg'>{item.body}</div> : <></>}
</div>
)
)}
</div>


Expand All @@ -181,14 +175,6 @@ const Notification = ({setIsNfnOpen}) => {
}
export default Notification

export const Message = ({ }) => {
return (<>



</>
)
}



Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/Polls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ const deletePoll=async(id)=>{
return;
}
Navigate(`/poll/${id}`)
console.log("click");

};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/Posts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pages/CreatePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,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,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/HotTopicPosts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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
Expand Down
Loading

0 comments on commit 473ec32

Please sign in to comment.