Skip to content

Commit

Permalink
fix client error
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Aug 23, 2024
1 parent 006b90f commit 4108165
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/app/[locale]/(main)/community/[communityId]/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,33 @@ import { addFollow } from '@/utils/actions/community/addFollow'
import { removeFollow } from '@/utils/actions/community/removeFollow'
import { account } from '@/app/appwrite-client'

Check warning on line 7 in src/app/[locale]/(main)/community/[communityId]/page.client.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import { account } from '@/app/appwrite-client'
import { getIsFollowingCommunity } from '@/utils/server-api/community-followers/getIsFollowingCommunity'
import { getUser } from '@/utils/server-api/account/user'

Check warning on line 9 in src/app/[locale]/(main)/community/[communityId]/page.client.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import { getUser } from '@/utils/server-api/account/user'

export function FollowerButton({ displayName, communityId }) {
export function FollowerButton({ userSelf, displayName, communityId }) {
const { toast } = useToast()
const [isFollowingState, setIsFollowingState] = useState(false)
const [userId, setUserId] = useState(null)

const getUserId = async () => {
try {
const isFollowing = await getIsFollowingCommunity(
userSelf?.$id,
communityId
)
if (isFollowing.documents.length > 0) {
setIsFollowingState(true)
}
} catch (error) {
// Do nothing
}
}

useEffect(() => {
getUserId().then()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [communityId])

const handleFollow = async () => {
const data = await addFollow(userId, communityId)
const data = await addFollow(userSelf?.$id, communityId)
if (data.code === 401) {
return toast({
title: 'Error',
Expand All @@ -36,7 +55,7 @@ export function FollowerButton({ displayName, communityId }) {
}

const handleUnfollow = async () => {
const data = await removeFollow(userId, communityId)
const data = await removeFollow(userSelf?.$id, communityId)
if (data.code === 401) {
return toast({
title: 'Error',
Expand Down
8 changes: 8 additions & 0 deletions src/app/[locale]/(main)/community/[communityId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Separator } from '@/components/ui/separator'
import ContextMenuProfile from '@/components/user/contextMenuProfile'
import { FollowerButton } from '@/app/[locale]/(main)/community/[communityId]/page.client'
import { getCommunityFollowers } from '@/utils/server-api/community-followers/getCommunityFollowers'
import { getUser } from '@/utils/server-api/account/user'

export const runtime = 'edge'

Expand Down Expand Up @@ -51,6 +52,12 @@ export default async function Page({
}) {
const community = await getCommunity(communityId)
const followers = await getCommunityFollowers(communityId)
let userSelf = null
try {
userSelf = await getUser()
} catch (error) {
// Do nothing
}

return (
<PageLayout title={community.name || 'Community'}>
Expand Down Expand Up @@ -114,6 +121,7 @@ export default async function Page({
{community.name}
</CardTitle>
<FollowerButton
userSelf={userSelf}
displayName={community.name}
communityId={communityId}
/>
Expand Down

0 comments on commit 4108165

Please sign in to comment.