From 39bc93872999d63331ade367e5803fb4cf7a043e Mon Sep 17 00:00:00 2001 From: "harun.dogdu" Date: Thu, 5 Sep 2024 15:49:38 +0300 Subject: [PATCH 1/8] feat: add userFollowingList to UserFollowers component --- components/follow/UserFollowers.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/follow/UserFollowers.tsx b/components/follow/UserFollowers.tsx index be9f499..933f648 100644 --- a/components/follow/UserFollowers.tsx +++ b/components/follow/UserFollowers.tsx @@ -21,13 +21,14 @@ const UserFollowers: FC = ({ username }) => { const router = useRouter(); const { data: userDetails } = useFollowingDetails(username); const { data: isLoggedIn } = useCurrentUser(); - const { isFollowing, toggleFollow } = useFollow(username); + const { userFollowingList, toggleFollow } = useFollow(username); return ( <> {userDetails?.followers.length > 0 ? ( userDetails.followers.map((user: any) => { const isCurrentUser = isLoggedIn.username === user.username; + const isFollowing = userFollowingList.includes(user.id); return (
Date: Thu, 5 Sep 2024 15:49:44 +0300 Subject: [PATCH 2/8] feat: optimize UserFollowing component with userFollowingList --- components/follow/UserFollowing.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/follow/UserFollowing.tsx b/components/follow/UserFollowing.tsx index ba21a30..7cecf83 100644 --- a/components/follow/UserFollowing.tsx +++ b/components/follow/UserFollowing.tsx @@ -21,13 +21,14 @@ const UserFollowing: FC = ({ username }) => { const router = useRouter(); const { data: userDetails } = useFollowingDetails(username); const { data: isLoggedIn } = useCurrentUser(); - const { isFollowing, toggleFollow } = useFollow(username); + const { toggleFollow, userFollowingList } = useFollow(username); return ( <> {userDetails?.following.length > 0 ? ( userDetails.following.map((user: any) => { const isCurrentUser = isLoggedIn?.username === user?.username; + const isFollowing = userFollowingList.includes(user.id); return (
Date: Thu, 5 Sep 2024 15:49:49 +0300 Subject: [PATCH 3/8] refactor: remove commented code in RegisterModal component --- components/modals/RegisterModal.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/modals/RegisterModal.tsx b/components/modals/RegisterModal.tsx index 1a12f28..1f23bba 100644 --- a/components/modals/RegisterModal.tsx +++ b/components/modals/RegisterModal.tsx @@ -144,13 +144,15 @@ const RegisterModal = () => { value={username} onChange={(e) => setUserName(e.target.value)} /> - {username.length > 0 ? ( + {/* + TODO: Api ile kontrol edilmeli + {username.length > 0 ? (

Username has to be different

) : ( "" - )} + )} */} { title="Create an account" body={bodyContent} footer={footerContent} - disabled={inputControl()} + disabled /> ); }; From 2becb24b2575f70279dc128499946174cfd02ad5 Mon Sep 17 00:00:00 2001 From: "harun.dogdu" Date: Thu, 5 Sep 2024 15:49:55 +0300 Subject: [PATCH 4/8] refactor: update UserInfo component to use userFollowingList for follow functionality --- components/users/UserInfo.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/users/UserInfo.tsx b/components/users/UserInfo.tsx index c745e49..abea9f6 100644 --- a/components/users/UserInfo.tsx +++ b/components/users/UserInfo.tsx @@ -21,7 +21,7 @@ interface IUserInfoProps { const UserInfo: FC = ({ username }) => { const { data: fetchedUser } = useUser(username); const { data: currentUser } = useCurrentUser(); - const { isFollowing, toggleFollow } = useFollow(username); + const { userFollowingList, toggleFollow } = useFollow(username); const router = useRouter(); const bioLink = fetchedUser?.bio ? controlLink(fetchedUser.bio) : ""; @@ -65,6 +65,10 @@ const UserInfo: FC = ({ username }) => { return format(new Date(fetchedUser?.birthday), "dd MMMM yyyy"); }, [fetchedUser?.birthday]); + const isFollowing = useMemo(() => { + return userFollowingList.includes(fetchedUser.id); + }, [userFollowingList, fetchedUser]); + return (
From a2e1f61aca6c7e6d9e7d9f12cd2053510752a677 Mon Sep 17 00:00:00 2001 From: "harun.dogdu" Date: Thu, 5 Sep 2024 15:50:00 +0300 Subject: [PATCH 5/8] refactor: update useFollow hook to use userFollowingList for follow functionality --- hooks/useFollow.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hooks/useFollow.ts b/hooks/useFollow.ts index 11bf67b..89a9a0e 100644 --- a/hooks/useFollow.ts +++ b/hooks/useFollow.ts @@ -13,10 +13,9 @@ const useFollow = (userName: string) => { const loginModal = useLoginModal(); - const isFollowing = useMemo(() => { - const list = currentUser?.followingIds || []; - return list.includes(fetchedUser?.id || ""); - }, [currentUser, fetchedUser]); + const userFollowingList = useMemo(() => { + return currentUser?.followingIds || []; + }, [currentUser?.followingIds]); const toggleFollow = useCallback(async () => { if (!currentUser) { @@ -27,7 +26,7 @@ const useFollow = (userName: string) => { try { let request; - if (isFollowing) { + if (userFollowingList) { request = () => axios.delete(`/api/follow`, { data: { @@ -52,14 +51,14 @@ const useFollow = (userName: string) => { }, [ currentUser, fetchedUser?.username, - isFollowing, + userFollowingList, loginModal, mutateCurrentUser, mutateFetchedUser, ]); return { - isFollowing, + userFollowingList, toggleFollow, }; }; From 8a5ae377f35b1373c4277cac0afceb58edc89591 Mon Sep 17 00:00:00 2001 From: "harun.dogdu" Date: Thu, 5 Sep 2024 15:50:06 +0300 Subject: [PATCH 6/8] refactor: update Connect component to use userFollowingList for follow functionality --- pages/connect.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pages/connect.tsx b/pages/connect.tsx index 037e7ff..2c1b0e0 100644 --- a/pages/connect.tsx +++ b/pages/connect.tsx @@ -1,4 +1,4 @@ -import { FC, useCallback } from "react"; +import { FC, useCallback, useMemo } from "react"; import { useRouter } from "next/router"; import { IUser } from "@/types/user.type"; @@ -20,8 +20,8 @@ interface IHeaderProps { const Connect: FC = ({ showBackArrow = false, username }) => { const { data: allUsers = [] } = useUsers(); + const { userFollowingList, toggleFollow } = useFollow(username); const router = useRouter(); - const { isFollowing, toggleFollow } = useFollow(username); const handleBackClick = useCallback(() => { const referrer = document.referrer; @@ -50,6 +50,8 @@ const Connect: FC = ({ showBackArrow = false, username }) => { Suggested for you {allUsers.map((user: IUser) => { + const isFollowing = userFollowingList.includes(user.id); + return (
Date: Thu, 5 Sep 2024 15:50:10 +0300 Subject: [PATCH 7/8] refactor: update Connect, UserInfo, and useFollow components to use userFollowingList for follow functionality --- pages/api/following.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/api/following.ts b/pages/api/following.ts index c216d9e..3e5d853 100644 --- a/pages/api/following.ts +++ b/pages/api/following.ts @@ -35,6 +35,7 @@ export default async function handler( }, }, select: { + id: true, name: true, username: true, bio: true, @@ -49,6 +50,7 @@ export default async function handler( }, }, select: { + id: true, name: true, username: true, bio: true, From b5be1468042b87e1d1eab8cfc5f23f2069226de6 Mon Sep 17 00:00:00 2001 From: "harun.dogdu" Date: Thu, 5 Sep 2024 15:50:15 +0300 Subject: [PATCH 8/8] refactor: update followers page to disable eslint for img element --- pages/users/[username]/followers.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/users/[username]/followers.tsx b/pages/users/[username]/followers.tsx index 3bd3218..8a172c3 100644 --- a/pages/users/[username]/followers.tsx +++ b/pages/users/[username]/followers.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ import React, { useEffect, useState } from "react"; import { useRouter } from "next/router";