From 6546dfcc1c1ff4184e4c2677cf1d56a6226eaf9a Mon Sep 17 00:00:00 2001 From: Aamil13 Date: Fri, 26 Jul 2024 16:36:49 +0530 Subject: [PATCH] removed query destructuring and following/follower slice, moved sec-Navbar to layout --- src/app/[id]/page.tsx | 2 - src/app/community/[id]/connections/page.tsx | 2 - src/app/community/[id]/page.tsx | 6 +-- src/app/community/page.tsx | 2 - src/app/layout.tsx | 2 + src/app/post/[id]/page.tsx | 10 ++-- src/app/timeline/page.tsx | 6 +-- src/components/Navbar/Navbar.tsx | 3 +- src/components/Timeline/Navbar.tsx | 5 ++ src/hooks/useCookie.ts | 1 + src/services/auth.ts | 2 - src/services/community-university.ts | 52 +++++++++---------- src/services/connection.ts | 24 ++++----- src/services/notification.ts | 8 +-- src/services/university-community.ts | 8 +-- src/services/user.ts | 8 +-- src/services/userProfile.ts | 8 +-- src/store/store.ts | 2 - src/store/storeType.ts | 4 +- .../userFollowingSlice/userFollowingSlice.ts | 26 ---------- .../userFollowingSlice/userFollowingType.ts | 4 -- src/types/constants.ts | 5 ++ 22 files changed, 79 insertions(+), 111 deletions(-) delete mode 100644 src/store/userFollowingSlice/userFollowingSlice.ts delete mode 100644 src/store/userFollowingSlice/userFollowingType.ts diff --git a/src/app/[id]/page.tsx b/src/app/[id]/page.tsx index e04a602..ac1dd07 100644 --- a/src/app/[id]/page.tsx +++ b/src/app/[id]/page.tsx @@ -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' @@ -30,7 +29,6 @@ const Profile = () => { setIsModalOpen(false)}> {modalContentType && modalContent(modalContentType)} -
{ return (
-
{ return communityGroupPost?.communityPosts.map((item: communityPostType) => (
{ setIsModalOpen(false)}> {modalContentType && modalContent(modalContentType)} -
diff --git a/src/app/community/page.tsx b/src/app/community/page.tsx index 7d707fc..08cc8fc 100644 --- a/src/app/community/page.tsx +++ b/src/app/community/page.tsx @@ -1,6 +1,5 @@ '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' @@ -21,7 +20,6 @@ const Page = () => { return ( <> -

Joined Communities

{SubscribedData?.community?.length ? ( diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b242327..c5e95c7 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -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 } @@ -38,6 +39,7 @@ export default function RootLayout({ children }: { children: React.ReactNode }) + {children} diff --git a/src/app/post/[id]/page.tsx b/src/app/post/[id]/page.tsx index ba4a595..8fb52a3 100644 --- a/src/app/post/[id]/page.tsx +++ b/src/app/post/[id]/page.tsx @@ -8,7 +8,7 @@ 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' @@ -19,7 +19,7 @@ const UserPost = () => { const Type = searchParams.get('isType') const [isModalOpen, setIsModalOpen] = useState(false) const [modalContentType, setModalContentType] = useState() - const { data, isFetching } = useGetPost(id, Type) + const { data, isFetching, isPending } = useGetPost(id, Type) const item = data?.post const [cookieValue] = useCookie('uni_user_token') const { userProfileData } = useUniStore() @@ -35,12 +35,13 @@ const UserPost = () => { } const PostHolder = () => { - if (!cookieValue) { + if (!cookieValue && !isPending) { return
Login to view Post.
} - if (isFetching) { + if (isFetching || isPending) { return } + return ( { setIsModalOpen(false)}> {modalContentType && modalContent(modalContentType)} -
diff --git a/src/app/timeline/page.tsx b/src/app/timeline/page.tsx index a16a5e0..2714d68 100644 --- a/src/app/timeline/page.tsx +++ b/src/app/timeline/page.tsx @@ -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' @@ -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' @@ -117,7 +116,7 @@ const Timeline = () => { setIsModalOpen={setIsModalOpen} postID={post._id} type={PostType.Timeline} - isType={'communityId' in post ? 'CommunityPost' : 'userPost'} + isType={'communityId' in post ? singlePostEnum.CommunityPost : singlePostEnum.userPost} /> ) }) @@ -128,7 +127,6 @@ const Timeline = () => { setIsModalOpen(false)}> {modalContentType && modalContent(modalContentType)} -
{ const [hover, setHover] = useState(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() @@ -62,7 +62,6 @@ const Navbar: React.FC = () => { deleteCookie() resetUserData() resetUserProfileData() - resetUserFollowingData() setIsLogin(false) router.push('/login') } diff --git a/src/components/Timeline/Navbar.tsx b/src/components/Timeline/Navbar.tsx index dc293d7..7619615 100644 --- a/src/components/Timeline/Navbar.tsx +++ b/src/components/Timeline/Navbar.tsx @@ -3,6 +3,7 @@ import React from 'react' import { CommunityNavbarLinks } from '@/types/constants' import { useRouter, usePathname } from 'next/navigation' import { useUniStore } from '@/store/store' +import useCookie from '@/hooks/useCookie' const Navbar: React.FC = () => { // const tabs = ['Timeline', 'Profile', 'Notifications', 'Messages', 'Connections', 'University Community', 'Chatbot'] @@ -11,7 +12,11 @@ const Navbar: React.FC = () => { const id = userData?.id const path = usePathname() const activeTab = path.split('/').pop() + const [cookieValue] = useCookie('uni_user_token') + if (!cookieValue) { + return + } return (