From b64d6df3d202fb5e3981209b288d9f48ff267fa0 Mon Sep 17 00:00:00 2001 From: Aamil13 Date: Thu, 25 Jul 2024 11:16:57 +0530 Subject: [PATCH 1/4] added single-post page,loaders and spinners for request --- src/app/community/[id]/page.tsx | 71 ++++++++++------- src/app/community/loading.tsx | 11 ++- src/app/post/[id]/page.tsx | 76 +++++++++++++++++++ src/app/timeline/page.tsx | 1 + src/components/Timeline/Post.tsx | 43 ++++++++--- src/components/Timeline/PostInput.tsx | 17 ++++- .../CommunityProfileContainer.tsx | 8 ++ .../communityUniversity/CreateNewGroup.tsx | 20 ++++- src/components/spinner/Spinner.tsx | 10 +++ .../universityCommunityCart.tsx | 2 +- src/services/community-timeline.ts | 8 +- src/services/community-university.ts | 34 ++++++++- 12 files changed, 249 insertions(+), 52 deletions(-) create mode 100644 src/app/post/[id]/page.tsx create mode 100644 src/components/spinner/Spinner.tsx diff --git a/src/app/community/[id]/page.tsx b/src/app/community/[id]/page.tsx index fedf137..e7e1fd4 100644 --- a/src/app/community/[id]/page.tsx +++ b/src/app/community/[id]/page.tsx @@ -17,6 +17,7 @@ import { useParams } from 'next/navigation' import React, { useEffect, useState } from 'react' import { IoIosArrowDown } from 'react-icons/io' import Navbar from '@/components/Timeline/Navbar' +import PostSkeleton from '@/components/Timeline/PostSkeleton' const roberta = { avatarUrl: '/timeline/avatar2.png', @@ -37,7 +38,11 @@ const Page = () => { const { data: communityGroups } = useGetCommunityGroups(id, isJoined) const [currSelectedGroup, setCurrSelectedGroup] = useState(communityGroups?.groups[0]) const [isJoinedInGroup, setIsJoinedInGroup] = useState(false) - const { data: communityGroupPost } = useGetCommunityGroupPost(currSelectedGroup?._id, isJoinedInGroup) + const { + data: communityGroupPost, + isLoading: communityGroupPostLoading, + isError, + } = useGetCommunityGroupPost(currSelectedGroup?._id, isJoinedInGroup) const modalContent = (modalContentType: string) => { switch (modalContentType) { @@ -52,6 +57,10 @@ const Page = () => { } } + useEffect(() => { + setCurrSelectedGroup(communityGroups?.groups[0]) + }, [communityGroups && !!currSelectedGroup]) + useEffect(() => { const findGroupRole = (communities: any) => { return communities?.some((community: any) => { @@ -69,6 +78,7 @@ const Page = () => { findGroupRole(userData.userUnVerifiedCommunities) } }, [currSelectedGroup, userData]) + return ( <> setIsModalOpen(false)}> @@ -113,31 +123,40 @@ const Page = () => { '' )} - {communityGroupPost?.communityPosts.map((item: any) => ( - - - - ))} + {communityGroupPostLoading ? ( + + ) : isError ? ( + Something went wrong! + ) : !communityGroupPost?.communityPosts.length ? ( + No post Yet! + ) : ( + communityGroupPost?.communityPosts.map((item: any) => ( + + + + )) + )} )} diff --git a/src/app/community/loading.tsx b/src/app/community/loading.tsx index 2b019b0..b5d9a4f 100644 --- a/src/app/community/loading.tsx +++ b/src/app/community/loading.tsx @@ -1,4 +1,11 @@ export default function Loading() { - // You can add any UI inside Loading, including a Skeleton. - return dsdsdsdsdsd + return ( + + + + + + + + ) } diff --git a/src/app/post/[id]/page.tsx b/src/app/post/[id]/page.tsx new file mode 100644 index 0000000..6655cbe --- /dev/null +++ b/src/app/post/[id]/page.tsx @@ -0,0 +1,76 @@ +'use client' +import Post from '@/components/Timeline/Post' +import { useGetPost } from '@/services/community-university' +import { useParams, useSearchParams } from 'next/navigation' +import Modal from '@/components/Timeline/Modal' +import ConnectionsModal from '@/components/Timeline/Modals/ConnectionsModal' +import PollModal from '@/components/Timeline/Modals/PollModal' + +import React, { useState } from 'react' +import { ModalContentType } from '@/types/global' +import Navbar from '@/components/Timeline/Navbar' +import { PostType } from '@/types/constants' +import { useUniStore } from '@/store/store' +import PostSkeleton from '@/components/Timeline/PostSkeleton' +const UserPost = () => { + const { id } = useParams<{ id: string }>() + const searchParams = useSearchParams() + const Type = searchParams.get('isType') + const [isModalOpen, setIsModalOpen] = useState(false) + const [modalContentType, setModalContentType] = useState() + const { data, isLoading } = useGetPost(id, Type) + const item = data?.post + + const { userProfileData } = useUniStore() + const modalContent = (modalContentType: string) => { + switch (modalContentType) { + case 'ConnectionsModal': + return + case 'PollModal': + return + default: + return null + } + } + + return ( + + setIsModalOpen(false)}> + {modalContentType && modalContent(modalContentType)} + + + + + {isLoading ? ( + + ) : ( + + )} + + + ) +} + +export default UserPost diff --git a/src/app/timeline/page.tsx b/src/app/timeline/page.tsx index b484905..a16a5e0 100644 --- a/src/app/timeline/page.tsx +++ b/src/app/timeline/page.tsx @@ -117,6 +117,7 @@ const Timeline = () => { setIsModalOpen={setIsModalOpen} postID={post._id} type={PostType.Timeline} + isType={'communityId' in post ? 'CommunityPost' : 'userPost'} /> ) }) diff --git a/src/components/Timeline/Post.tsx b/src/components/Timeline/Post.tsx index 9caf759..851a520 100644 --- a/src/components/Timeline/Post.tsx +++ b/src/components/Timeline/Post.tsx @@ -9,6 +9,7 @@ import { FaBookmark } from 'react-icons/fa6' // import { MdOutlineImage } from 'react-icons/md' import { MdGifBox, MdOutlineBookmarkBorder } from 'react-icons/md' import { HiReply, HiOutlineBell, HiOutlineFlag } from 'react-icons/hi' +import { MdOutlineOpenInNew } from 'react-icons/md' import { BiRepost } from 'react-icons/bi' import { ModalContentType } from '@/types/global' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover' @@ -31,6 +32,8 @@ import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import { replaceImage } from '@/services/uploadImage' import { PostCommentData, PostType } from '@/types/constants' +import Link from 'next/link' +import { Spinner } from '../spinner/Spinner' dayjs.extend(relativeTime) @@ -57,13 +60,20 @@ interface PostProps { media?: [] saved?: boolean isUniversity?: boolean - postID?: string + postID: string profileDp?: string adminId: string type: PostType + isType: string + isSinglePost?: boolean } -const PostOptions = () => { +interface PostOptionType { + postID: string + isType: string +} + +const PostOptions = ({ postID, isType }: PostOptionType) => { return ( @@ -71,6 +81,12 @@ const PostOptions = () => { + + + + Open Post + + Save Post @@ -156,15 +172,18 @@ const Post: React.FC = ({ profileDp, adminId, type, + isType, + isSinglePost, }) => { const { mutate: LikeUnlikeGroupPost } = useLikeUnilikeGroupPost() const { mutate: LikeUnlikeTimelinePost } = useLikeUnlikeTimelinePost() - const { mutate: CreateGroupPostComment } = useCreateGroupPostComment() + const { mutate: CreateGroupPostComment, isPending: CreateGroupPostCommentLoading } = useCreateGroupPostComment(isSinglePost ? isSinglePost : false) const { mutate: likeGroupPostComment } = useLikeUnlikeGroupPostComment() - const { mutate: CreateUserPostComment } = useCreateUserPostComment() + const { mutate: CreateUserPostComment, isPending: CreateUserPostCommentLoading } = useCreateUserPostComment(isSinglePost ? isSinglePost : false) const { mutate: likeUserPostComment } = useLikeUnlikeUserPostComment() const [comment, setComment] = useState('') const [ImageValue, setImageValue] = useState(null) + const [isLoading, setIsLoading] = useState(false) const [showCommentSec, setShowCommentsec] = useState(false) const { userData } = useUniStore() @@ -174,6 +193,7 @@ const Post: React.FC = ({ if (comment.length <= 1) { return console.log('Please type something to comment!') } + setIsLoading(true) if (ImageValue) { const imagedata: any = await replaceImage(ImageValue, '') @@ -202,6 +222,9 @@ const Post: React.FC = ({ CreateGroupPostComment(data) } } + setIsLoading(false) + setImageValue(null) + setComment('') } const LikeUnlikeHandler = (postId: string) => { @@ -251,7 +274,7 @@ const Post: React.FC = ({ {saved && } - + {/* media div */} @@ -334,9 +357,9 @@ const Post: React.FC = ({ - {comment.length > 1 && ( + {comment?.length > 1 && ( handlePostComment()} className="text-white bg-primary px-3 my-[2px] sm:px-3 sm:py-2 rounded-full text-sm"> - Post + {CreateGroupPostCommentLoading || CreateUserPostCommentLoading || isLoading ? : Post} )} @@ -349,10 +372,10 @@ const Post: React.FC = ({
Open Post
Save Post
Post
Create Group
{address}