diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index c5e95c7..1a89b61 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -6,7 +6,7 @@ import Navbar from '../components/Navbar/Navbar'
import { ReactQueryClientProvider } from '@/utils/Provider'
import ZustandSocketProvider from '@/utils/ZustandSocketProvider'
-import SecNavbar from '@/components/Timeline/Navbar'
+import SecondaryNavbar from '@/components/Timeline/Navbar'
type FontClassName = string
const inter = Inter({ subsets: ['latin'] }) as { className: FontClassName }
@@ -39,7 +39,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
-
+
{children}
diff --git a/src/components/Connections/FindPeople.tsx b/src/components/Connections/FindPeople.tsx
index 0196eb1..6de32bc 100644
--- a/src/components/Connections/FindPeople.tsx
+++ b/src/components/Connections/FindPeople.tsx
@@ -137,13 +137,13 @@ const FindPeople = ({ contentDivStyle }: { contentDivStyle?: string }) => {
>
- ) : content === 'Followers' && !userFollow?.profile?.length ? (
+ ) : content === 'Followers' && !userFollowers?.profile?.length ? (
You have 0 Followers
) : (
content === 'Followers' &&
userFollowers?.profile?.map((item: FollowingItemProps, index: number) => (
{
const [, , deleteCookie] = useCookie('uni_user_token')
const { userProfileData, userData, resetUserData, resetUserProfileData } = useUniStore()
const router = useRouter()
-
+ const { refetch: refetchNotification } = useGetNotification()
const { data: notificationData } = useGetNotification()
const [isNotificationOpen, setIsNotificationOpen] = useState(false)
@@ -54,6 +54,12 @@ const Navbar: React.FC = () => {
setIsLogin(!!userData?.id)
}, [userData, userData?.id])
+ useEffect(() => {
+ if (isLogin) {
+ refetchNotification()
+ }
+ }, [isLogin])
+
const handleClick = (item: string) => {
setActiveItem(item)
}
diff --git a/src/components/Timeline/Navbar.tsx b/src/components/Timeline/Navbar.tsx
index 7619615..ec689a7 100644
--- a/src/components/Timeline/Navbar.tsx
+++ b/src/components/Timeline/Navbar.tsx
@@ -1,20 +1,24 @@
'use client'
-import React from 'react'
+import React, { useEffect, useState } 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 SecondaryNavbar: React.FC = () => {
// const tabs = ['Timeline', 'Profile', 'Notifications', 'Messages', 'Connections', 'University Community', 'Chatbot']
const router = useRouter()
const { userData } = useUniStore()
const id = userData?.id
const path = usePathname()
const activeTab = path.split('/').pop()
- const [cookieValue] = useCookie('uni_user_token')
- if (!cookieValue) {
+ const [isLogin, setIsLogin] = useState(false)
+
+ useEffect(() => {
+ setIsLogin(!!userData?.id)
+ }, [userData, userData?.id])
+
+ if (!isLogin) {
return
}
return (
@@ -40,4 +44,4 @@ const Navbar: React.FC = () => {
)
}
-export default Navbar
+export default SecondaryNavbar
diff --git a/src/services/connection.ts b/src/services/connection.ts
index 5e45069..a40ac50 100644
--- a/src/services/connection.ts
+++ b/src/services/connection.ts
@@ -19,7 +19,7 @@ export async function getUsersWithProfile(token: string, Name: string) {
return response
}
export async function getUserFollow(token: string, Name: string) {
- const response: FollowingItemPropss = await client(`/userprofile?name=${Name}`, { headers: { Authorization: `Bearer ${token}` } })
+ const response: FollowingItemPropss = await client(`/userprofile/following?name=${Name}`, { headers: { Authorization: `Bearer ${token}` } })
return response
}
export async function getUserFollowers(token: string, Name: string) {
diff --git a/src/services/notification.ts b/src/services/notification.ts
index dc4a22a..e28baab 100644
--- a/src/services/notification.ts
+++ b/src/services/notification.ts
@@ -21,12 +21,17 @@ export async function UpdateCommunityGroup(data: { id: string }, token: string)
}
export function useGetNotification() {
- const [cookieValue] = useCookie('uni_user_token')
+ let finalCookie: any = null
+
+ if (typeof document !== 'undefined') {
+ const cookieValue = document.cookie.split('; ').find((row) => row.startsWith('uni_user_token='))
+ finalCookie = cookieValue ? cookieValue.split('=')[1] : null
+ }
const state = useQuery({
queryKey: ['notification'],
- queryFn: () => getUserNotification(cookieValue),
- enabled: !!cookieValue,
+ queryFn: () => getUserNotification(finalCookie),
+ enabled: !!finalCookie,
})
let errorMessage = null
diff --git a/src/store/socketSlice/socketSlice.ts b/src/store/socketSlice/socketSlice.ts
index 6a175c6..8d568e1 100644
--- a/src/store/socketSlice/socketSlice.ts
+++ b/src/store/socketSlice/socketSlice.ts
@@ -31,7 +31,7 @@ export const createSocketSlice: StateCreator = (set, get) => ({
...initialState,
initializeSocket: (userId, refetchUserData, refetchNotification, refetchUserProfileData) => {
- const newSocket = io('http://localhost:9000')
+ const newSocket = io('http://localhost:8000')
newSocket.on('connect', () => {
console.log('Connected to the server')
diff --git a/src/utils/ZustandSocketProvider.tsx b/src/utils/ZustandSocketProvider.tsx
index 23ca1eb..cd173ee 100644
--- a/src/utils/ZustandSocketProvider.tsx
+++ b/src/utils/ZustandSocketProvider.tsx
@@ -16,9 +16,13 @@ const ZustandSocketProvider: React.FC = ({ children
const disconnectSocket = useUniStore((state) => state.disconnectSocket)
const { userData, type, setUserUnVerifiedCommunities, setUserVerifiedCommunities, setUserFollowers, setIsRefetched } = useUniStore()
const { refetch: refetchNotification } = useGetNotification()
- const { refetch: refetchUserData, data: RefetcheduserData } = useGetUserData(type)
- const { refetch: refetchUserProfileData, data: RefetcheduserProfileData } = useGetUserProfileData(type)
-
+ const { refetch: refetchUserData, data: RefetcheduserData, isSuccess: refectUserDataIsSuccess, isFetching } = useGetUserData(type)
+ const {
+ refetch: refetchUserProfileData,
+ data: RefetcheduserProfileData,
+ isSuccess: refectUserProfileDataIsSuccess,
+ isFetching: userProfileRefething,
+ } = useGetUserProfileData(type)
useEffect(() => {
if (userData.id) {
initializeSocket(userData.id, refetchUserData, refetchNotification, refetchUserProfileData)
@@ -30,18 +34,20 @@ const ZustandSocketProvider: React.FC = ({ children
}, [userData.id, initializeSocket, disconnectSocket, refetchNotification])
useEffect(() => {
- switch (type) {
- case notificationRoleAccess.ASSIGN:
- setUserUnVerifiedCommunities(RefetcheduserData?.user?.userUnVerifiedCommunities)
- setUserVerifiedCommunities(RefetcheduserData?.user?.userVerifiedCommunities)
- setIsRefetched('')
- break
- case notificationRoleAccess.FOLLOW:
- setUserFollowers(RefetcheduserProfileData?.profile?.followers)
- setIsRefetched('')
- break
- default:
- break
+ if ((refectUserDataIsSuccess && !isFetching) || (refectUserProfileDataIsSuccess && !userProfileRefething)) {
+ switch (type) {
+ case notificationRoleAccess.ASSIGN:
+ setUserUnVerifiedCommunities(RefetcheduserData?.user?.userUnVerifiedCommunities)
+ setUserVerifiedCommunities(RefetcheduserData?.user?.userVerifiedCommunities)
+ setIsRefetched('')
+ break
+ case notificationRoleAccess.FOLLOW:
+ setUserFollowers(RefetcheduserProfileData?.profile?.followers)
+ setIsRefetched('')
+ break
+ default:
+ break
+ }
}
}, [RefetcheduserData, RefetcheduserProfileData])