Skip to content

Commit

Permalink
Merge pull request #78 from BacPacNet/single-post
Browse files Browse the repository at this point in the history
added single-post page,loaders and spinners for request
  • Loading branch information
bacpactech authored Jul 26, 2024
2 parents f874e89 + 6546dfc commit 901d5f5
Show file tree
Hide file tree
Showing 31 changed files with 381 additions and 161 deletions.
2 changes: 0 additions & 2 deletions src/app/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'
import Footer from '@/components/Footer/Footer'
import Navbar from '@/components/Timeline/Navbar'
import Modal from '@/components/Timeline/Modal'
import EditProfileModal from '@/components/Timeline/Modals/EditProfileModal'
import ProfileCard from '@/components/Timeline/ProfileCard'
Expand Down Expand Up @@ -30,7 +29,6 @@ const Profile = () => {
<Modal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)}>
{modalContentType && modalContent(modalContentType)}
</Modal>
<Navbar />
<div className="flex justify-center w-full gap-6 mt-20 max-md:flex-col max-md:items-center pb-10 ">
<ProfileCard
userProfileData={userProfileData}
Expand Down
2 changes: 0 additions & 2 deletions src/app/community/[id]/connections/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import FindPeople from '@/components/Connections/FindPeople'
import Footer from '@/components/Footer/Footer'
import Navbar from '@/components/Timeline/Navbar'
import Recommendations from '@/components/Timeline/Recommendations'
import React from 'react'

Expand Down Expand Up @@ -46,7 +45,6 @@ const recommendations = [
const Connections = () => {
return (
<div>
<Navbar />
<div className="flex flex-col lg:flex-row my-12 gap-8 justify-center mx-4 md:mx-20 lg:mx-0">
<FindPeople contentDivStyle="max-h-[500px]" />
<Recommendations
Expand Down
101 changes: 72 additions & 29 deletions src/app/community/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import HeroSec from '@/components/communityUniversity/HeroSec'
import { useGetCommunity, useGetCommunityGroupPost, useGetCommunityGroups } from '@/services/community-university'
import { useUniStore } from '@/store/store'
import { ModalContentType } from '@/types/global'
import { PostInputType, PostType } from '@/types/constants'
import { PostInputType, PostType, singlePostEnum } from '@/types/constants'
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',
Expand All @@ -25,6 +25,27 @@ const roberta = {
comment: 'Sorry that was a strange thing to ask.',
replyingTo: 'Johnny Nitro and Kathryn Murphy',
}

interface communityPostType {
_id: string
user_id: {
firstName: string
lastName: string
_id: string
university_name: string
study_year: string
degree: string
profile_dp: {
imageUrl: string
}
}
content: string
createdAt: string
likeCount: []
comments: []
imageUrl: []
}

const Page = () => {
const [isModalOpen, setIsModalOpen] = useState(false)
const [modalContentType, setModalContentType] = useState<ModalContentType>()
Expand All @@ -37,7 +58,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,
isFetching: communityGroupPostLoading,
isError,
} = useGetCommunityGroupPost(currSelectedGroup?._id, isJoinedInGroup)

const modalContent = (modalContentType: string) => {
switch (modalContentType) {
Expand All @@ -52,6 +77,10 @@ const Page = () => {
}
}

useEffect(() => {
setCurrSelectedGroup(communityGroups?.groups[0])
}, [communityGroups && !!currSelectedGroup])

useEffect(() => {
const findGroupRole = (communities: any) => {
return communities?.some((community: any) => {
Expand All @@ -69,12 +98,50 @@ const Page = () => {
findGroupRole(userData.userUnVerifiedCommunities)
}
}, [currSelectedGroup, userData])

const PostContainer = () => {
if (communityGroupPostLoading) {
return <PostSkeleton />
}
if (isError) {
return <div>Something went wrong!</div>
}
if (!communityGroupPost?.communityPosts.length) {
return <div className="text-center font-bold mt-10">No post Yet!</div>
}
return communityGroupPost?.communityPosts.map((item: communityPostType) => (
<div key={item._id} className="border-2 border-neutral-300 rounded-md w-[73%] max-xl:w-10/12 mt-6">
<Post
isType={'communityId' in item ? singlePostEnum.CommunityPost : singlePostEnum.userPost}
user={item?.user_id?.firstName + ' ' + item?.user_id?.lastName}
adminId={item.user_id?._id}
university={item?.user_id?.university_name}
year={item?.user_id?.study_year + ' Yr. ' + ' ' + item?.user_id?.degree}
text={item.content}
date={item?.createdAt}
avatar={item?.user_id?.profile_dp?.imageUrl}
likes={item.likeCount}
comments={item.comments.length}
postID={item._id}
reposts={2}
shares={1}
userComments={item.comments}
setModalContentType={setModalContentType}
setIsModalOpen={setIsModalOpen}
isUniversity={true}
profileDp={userProfileData?.profile_dp?.imageUrl}
media={item?.imageUrl}
type={PostType.Community}
/>
</div>
))
}

return (
<>
<Modal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)}>
{modalContentType && modalContent(modalContentType)}
</Modal>
<Navbar />
<div className="flex flex-col items-center w-full gap-6 mt-10 pb-10">
<HeroSec data={data} isJoined={isJoined} setIsJoined={setIsJoined} />
<div className="flex justify-center w-11/12 max-sm:w-full max-md:w-11/12 max-xl:w-full max-md:flex-col px-16 max-sm:px-4">
Expand Down Expand Up @@ -113,31 +180,7 @@ const Page = () => {
''
)}
</div>
{communityGroupPost?.communityPosts.map((item: any) => (
<div key={item._id} className="border-2 border-neutral-300 rounded-md w-[73%] max-xl:w-10/12 mt-6">
<Post
user={item?.user_id?.firstName + ' ' + item?.user_id?.lastName}
adminId={item.user_id?._id}
university={item?.user_id?.university_name}
year={item?.user_id?.study_year + ' Yr. ' + ' ' + item?.user_id?.degree}
text={item.content}
date={item?.createdAt}
avatar={item?.user_id?.profile_dp?.imageUrl}
likes={item.likeCount}
comments={item.comments.length}
postID={item._id}
reposts={2}
shares={1}
userComments={item.comments}
setModalContentType={setModalContentType}
setIsModalOpen={setIsModalOpen}
isUniversity={true}
profileDp={userProfileData?.profile_dp?.imageUrl}
media={item?.imageUrl}
type={PostType.Community}
/>
</div>
))}
<PostContainer />
</div>
)}
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/app/community/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export default function Loading() {
// You can add any UI inside Loading, including a Skeleton.
return <div>dsdsdsdsdsd</div>
return (
<div className="h-screen flex items-center justify-center">
<div className="flex justify-center items-center">
<svg width={50} height={50} viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" className="animate-spin">
<circle cx="25" cy="25" r="20" fill="none" stroke="#6647FF" strokeWidth="5" strokeLinecap="round" strokeDasharray="80, 200" />
</svg>
</div>
</div>
)
}
16 changes: 11 additions & 5 deletions src/app/community/page.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
'use client'
import React from 'react'
import Navbar from '@/components/Timeline/Navbar'
import Footer from '@/components/Footer/Footer'
import UniversityCard from '@/components/universityCommunity/universityCommunityCart'
import { useGetUserSubscribedCommunityGroups } from '@/services/university-community'
import Loading from '../loading'

interface CommunityType {
_id: string
communityLogoUrl: {
imageUrl: string
}
name: string
collegeID: string
}
const Page = () => {
const { data: SubscribedData, isLoading } = useGetUserSubscribedCommunityGroups()
const { data: SubscribedData, isFetching } = useGetUserSubscribedCommunityGroups()

if (isLoading) return <Loading />
if (isFetching) return <Loading />

return (
<>
<Navbar />
<div className="flex flex-col min-h-[62vh] items-center ">
<h3 className="py-10 text-xl font-bold text-neutral-700">Joined Communities</h3>
{SubscribedData?.community?.length ? (
<div className="flex gap-10 flex-wrap justify-center">
{SubscribedData?.community?.map((item: any) => (
{SubscribedData?.community?.map((item: CommunityType) => (
<UniversityCard
key={item?._id}
universityLogo={item?.communityLogoUrl?.imageUrl}
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Navbar from '../components/Navbar/Navbar'
import { ReactQueryClientProvider } from '@/utils/Provider'
import ZustandSocketProvider from '@/utils/ZustandSocketProvider'

import SecNavbar from '@/components/Timeline/Navbar'
type FontClassName = string

const inter = Inter({ subsets: ['latin'] }) as { className: FontClassName }
Expand Down Expand Up @@ -38,6 +39,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<ReactQueryClientProvider>
<ZustandSocketProvider>
<Navbar />
<SecNavbar />
{children}
</ZustandSocketProvider>
</ReactQueryClientProvider>
Expand Down
85 changes: 85 additions & 0 deletions src/app/post/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'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 { PostType } from '@/types/constants'
import { useUniStore } from '@/store/store'
import PostSkeleton from '@/components/Timeline/PostSkeleton'
import useCookie from '@/hooks/useCookie'
const UserPost = () => {
const { id } = useParams<{ id: string }>()
const searchParams = useSearchParams()
const Type = searchParams.get('isType')
const [isModalOpen, setIsModalOpen] = useState(false)
const [modalContentType, setModalContentType] = useState<ModalContentType>()
const { data, isFetching, isPending } = useGetPost(id, Type)
const item = data?.post
const [cookieValue] = useCookie('uni_user_token')
const { userProfileData } = useUniStore()
const modalContent = (modalContentType: string) => {
switch (modalContentType) {
case 'ConnectionsModal':
return <ConnectionsModal />
case 'PollModal':
return <PollModal />
default:
return null
}
}

const PostHolder = () => {
if (!cookieValue && !isPending) {
return <div className="text-center">Login to view Post.</div>
}
if (isFetching || isPending) {
return <PostSkeleton />
}

return (
<Post
isType={String(Type)}
isSinglePost={true}
user={item?.user_id?.firstName + ' ' + item?.user_id?.lastName}
adminId={item?.user_id?._id}
university={item?.user_id?.university_name}
year={item?.user_id?.study_year + ' Yr. ' + ' ' + item?.user_id?.degree}
text={item?.content}
date={item?.createdAt}
avatar={item?.user_id?.profile_dp?.imageUrl}
likes={item?.likeCount}
comments={item?.comments.length}
postID={item?._id}
reposts={2}
shares={1}
userComments={item?.comments}
setModalContentType={setModalContentType}
setIsModalOpen={setIsModalOpen}
isUniversity={true}
profileDp={userProfileData?.profile_dp?.imageUrl}
media={item?.imageUrl}
type={String(Type) == 'userPost' ? PostType.Timeline : PostType.Community}
/>
)
}

return (
<div>
<Modal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)}>
{modalContentType && modalContent(modalContentType)}
</Modal>

<div className="border-2 border-neutral-300 rounded-md w-3/4 mx-auto mt-6">
<PostHolder />
</div>
</div>
)
}

export default UserPost
5 changes: 2 additions & 3 deletions src/app/timeline/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'
import React, { useState } from 'react'
import Navbar from '@/components/Timeline/Navbar'
import ProfileCard from '@/components/Timeline/ProfileCard'
import PostInput from '@/components/Timeline/PostInput'
import Dropdown from '@/components/Timeline/DropDown'
Expand All @@ -12,7 +11,7 @@ import PollModal from '@/components/Timeline/Modals/PollModal'
import EditProfileModal from '@/components/Timeline/Modals/EditProfileModal'
import ReplyModal from '@/components/Timeline/Modals/ReplyModal'
import { ModalContentType } from '@/types/global'
import { PostInputType, PostType } from '@/types/constants'
import { PostInputType, PostType, singlePostEnum } from '@/types/constants'
import Recommendations from '@/components/Timeline/Recommendations'
import { useUniStore } from '@/store/store'
import { useGetUserPosts } from '@/services/community-timeline'
Expand Down Expand Up @@ -117,6 +116,7 @@ const Timeline = () => {
setIsModalOpen={setIsModalOpen}
postID={post._id}
type={PostType.Timeline}
isType={'communityId' in post ? singlePostEnum.CommunityPost : singlePostEnum.userPost}
/>
)
})
Expand All @@ -127,7 +127,6 @@ const Timeline = () => {
<Modal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)}>
{modalContentType && modalContent(modalContentType)}
</Modal>
<Navbar />
<div className="flex justify-center items-center lg:items-start gap-7 mt-16 flex-col lg:flex-row xs:px-4 sm:px-0">
<div className="flex flex-col gap-6">
<ProfileCard
Expand Down
3 changes: 1 addition & 2 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Navbar: React.FC = () => {
const [hover, setHover] = useState<boolean>(false)
const [activeItem, setActiveItem] = useState('')
const [, , deleteCookie] = useCookie('uni_user_token')
const { userProfileData, userData, resetUserData, resetUserProfileData, resetUserFollowingData } = useUniStore()
const { userProfileData, userData, resetUserData, resetUserProfileData } = useUniStore()
const router = useRouter()

const { data: notificationData } = useGetNotification()
Expand All @@ -62,7 +62,6 @@ const Navbar: React.FC = () => {
deleteCookie()
resetUserData()
resetUserProfileData()
resetUserFollowingData()
setIsLogin(false)
router.push('/login')
}
Expand Down
Loading

0 comments on commit 901d5f5

Please sign in to comment.