Skip to content

Commit 9e0f566

Browse files
committed
fix: endpoint in sync with parameters
'followers' endpoint has been changed to 'user_followers'
1 parent 05b9990 commit 9e0f566

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

database.rules.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"users": {
1111
".read": true,
1212
"$user_id": {
13-
"followers": { ".write": "auth!=null" },
13+
"user_followers": { ".write": "auth!=null" },
1414
".write": "$user_id === auth.uid"
1515
}
1616
}

src/components/users/UserCard.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* HERE's how you create self contained components that also house render states */
12
import { useEffect, useState } from 'react'
23
import useGlobalStore from './../state/GlobalState'
34
import Skeleton from 'react-loading-skeleton'
@@ -13,22 +14,23 @@ export default function UserCard({
1314
}: Tuser) {
1415
const [isFollowing, setIsFollowing] = useState(false)
1516
const auth = useGlobalStore((state) => state.auth)
16-
const { uid, user_following: currentUser_following } = useGlobalStore(
17-
(state) => state.user,
18-
)
17+
const { user_id: currentUser_id, user_following: currentUser_following } =
18+
useGlobalStore((state) => state.user)
19+
1920
useEffect(() => {
21+
// set the cards as isFollowing true first thing the component loads
22+
// re-render when new data comes in or during follow/unfollow
2023
const exists =
2124
currentUser_following.find((x) => x === user_id) == undefined
2225
? false
2326
: true
24-
// if(exists)
25-
console.log(exists)
27+
if (auth && exists) setIsFollowing(true)
28+
}, [currentUser_following, user_id])
29+
// IMPORTANT: Dont forget to re-render the components when the new data takes over the mock data
2630

27-
// set the cards as isFollowing true first thing the component loads
28-
}, [currentUser_following])
2931
const handleClick = () => {
3032
// send to db
31-
setIsFollowing(true)
33+
// setIsFollowing(true)
3234
}
3335
return (
3436
<article className='card mt-8'>
@@ -88,7 +90,7 @@ export default function UserCard({
8890
) : (
8991
<div className='group relative ms-auto'>
9092
<button
91-
disabled={auth && user_id == uid}
93+
disabled={auth && user_id == currentUser_id}
9294
onClick={handleClick}
9395
className='inline-flex items-center gap-2 gap-x-1.5 rounded-full bg-accent-pink-500 px-3 py-2 text-xs font-medium text-white transition-all hover:bg-accent-pink-600 disabled:pointer-events-none disabled:opacity-50 dark:bg-accent-pink-900 sm:mt-1.5'
9496
>

0 commit comments

Comments
 (0)