diff --git a/client/app/app/layout-content.jsx b/client/app/app/layout-content.jsx index 1a6d975..96a6432 100644 --- a/client/app/app/layout-content.jsx +++ b/client/app/app/layout-content.jsx @@ -10,6 +10,8 @@ export default function LayoutContent({ children }) { const pathname = usePathname(); const loading = useLoadingStore((state) => state.loading); + const isUsersPage = pathname.includes('/app/users'); + if (loading) return ; return ( @@ -19,7 +21,7 @@ export default function LayoutContent({ children }) {
state.user); const [user, setUser] = useState(null); const { toast } = useToast(); + const handleFollow = async (e, user) => { + e.preventDefault(); + + const response = await followUser(user.username); + if (!response) { + toast({ + title: 'hay aksi, bir şeyler ters gitti!', + description: + 'sunucudan yanıt alınamadı. lütfen daha sonra tekrar deneyin.', + duration: 3000 + }); + return; + } + + const followersList = user.followers || []; + + setUser({ + ...user, + followers: followersList.includes(me.id) + ? followersList.filter((id) => id !== me.id) + : [...followersList, me.id] + }); + }; + const fetchPosts = async (offset) => { return await getUserPosts(params.slug, 11, offset); }; @@ -39,7 +68,7 @@ export default function Page({ params }) { fetchUser(); }, // eslint-disable-next-line react-hooks/exhaustive-deps - [params] + [] ); return ( @@ -53,32 +82,53 @@ export default function Page({ params }) { {user ? ( <>
-
-
{user.name}
+
+
+
{user.name}
+
+ @{user.username} +
+
+ {me.id !== user.id && ( + + )}
-
@{user.username}
-
-
{user.about}
-
-
- - {new Date(user.created_at.T * 1000).toLocaleDateString( - 'tr-TR', - { year: 'numeric', month: 'long', day: 'numeric' } - )} -
- {' · '} -
- - - +
+
+
{user.about}
+
- -
{user.points} çöp puanı
+ + {new Date(user.created_at.T * 1000).toLocaleDateString( + 'tr-TR', + { year: 'numeric', month: 'long', day: 'numeric' } + )} +
+ {' · '} +
+ + + +
+ +
{user.points} çöp puanı
+
+
) : ( diff --git a/client/components/app/Post/List.jsx b/client/components/app/Post/List.jsx index 39b0f15..8aaf7b9 100644 --- a/client/components/app/Post/List.jsx +++ b/client/components/app/Post/List.jsx @@ -69,7 +69,9 @@ export default function PostList({ fetchPosts }) { }; fetchInitialPosts(); - }, [fetchPosts, toast]); + }, + // eslint-disable-next-line react-hooks/exhaustive-deps + []); return (
@@ -96,4 +98,4 @@ export default function PostList({ fetchPosts }) { )}
); -} \ No newline at end of file +} diff --git a/client/components/app/User/Follows.jsx b/client/components/app/User/Follows.jsx new file mode 100644 index 0000000..b5436fc --- /dev/null +++ b/client/components/app/User/Follows.jsx @@ -0,0 +1,19 @@ +export default function Follows({ user }) { + return ( +
+
+ + {user.followers ? user.followers.length : 0} + {' '} + takipçi +
+ {' · '} +
+ + {user.following ? user.following.length : 0} + {' '} + takip edilen +
+
+ ); +} diff --git a/client/components/app/User/Hover.jsx b/client/components/app/User/Hover.jsx index 58bf91b..0915ff9 100644 --- a/client/components/app/User/Hover.jsx +++ b/client/components/app/User/Hover.jsx @@ -12,7 +12,8 @@ export default function Hover({ user }) { {user.name} - + {/* TODO: set z-index to make the hover card appear on top */} +
diff --git a/client/lib/api/users/index.js b/client/lib/api/users/index.js index 2246056..78c0bfe 100644 --- a/client/lib/api/users/index.js +++ b/client/lib/api/users/index.js @@ -18,6 +18,15 @@ export async function getUsers(limit, offset) { } } +export async function followUser(slug) { + try { + const response = await api.post(`/users/${slug}/follows`); + return response; + } catch (error) { + return error.response; + } +} + export async function getUserPosts(slug, limit, offset) { try { const response = await api.get(`/users/${slug}/posts`, {