-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yoginth
committed
Dec 4, 2024
1 parent
e0cc8f6
commit 1e8284f
Showing
6 changed files
with
114 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import AccountListShimmer from "@components/Shared/Shimmer/AccountListShimmer"; | ||
import SingleAccount from "@components/Shared/SingleAccount"; | ||
import { UsersIcon } from "@heroicons/react/24/outline"; | ||
import { AccountLinkSource } from "@hey/data/tracking"; | ||
import { | ||
type Account, | ||
type GroupMembersRequest, | ||
PageSize, | ||
useGroupMembersQuery | ||
} from "@hey/indexer"; | ||
import { EmptyState, ErrorMessage } from "@hey/ui"; | ||
import type { FC } from "react"; | ||
import { Virtuoso } from "react-virtuoso"; | ||
import { useAccountStore } from "src/store/persisted/useAccountStore"; | ||
|
||
interface MembersProps { | ||
address: string; | ||
slug: string; | ||
} | ||
|
||
const Members: FC<MembersProps> = ({ address, slug }) => { | ||
const { currentAccount } = useAccountStore(); | ||
|
||
const request: GroupMembersRequest = { | ||
pageSize: PageSize.Fifty, | ||
group: address | ||
}; | ||
|
||
const { data, loading, error, fetchMore } = useGroupMembersQuery({ | ||
skip: !address, | ||
variables: { request } | ||
}); | ||
|
||
const groupMembers = data?.groupMembers?.items; | ||
const pageInfo = data?.groupMembers?.pageInfo; | ||
const hasMore = pageInfo?.next; | ||
|
||
const onEndReached = async () => { | ||
if (hasMore) { | ||
await fetchMore({ | ||
variables: { request: { ...request, cursor: pageInfo?.next } } | ||
}); | ||
} | ||
}; | ||
|
||
if (loading) { | ||
return <AccountListShimmer />; | ||
} | ||
|
||
if (groupMembers?.length === 0) { | ||
return ( | ||
<EmptyState | ||
icon={<UsersIcon className="size-8" />} | ||
message={ | ||
<div> | ||
<b className="mr-1">/{slug}</b> | ||
<span>doesn't have any members.</span> | ||
</div> | ||
} | ||
hideCard | ||
/> | ||
); | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<ErrorMessage | ||
className="m-5" | ||
error={error} | ||
title="Failed to load members" | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Virtuoso | ||
className="virtual-account-list" | ||
computeItemKey={(index, member) => `${member.address}-${index}`} | ||
data={groupMembers} | ||
endReached={onEndReached} | ||
itemContent={(_, member) => ( | ||
<div className="p-5"> | ||
<SingleAccount | ||
hideFollowButton={currentAccount?.address === member.address} | ||
hideUnfollowButton={currentAccount?.address === member.address} | ||
account={member as Account} | ||
showBio | ||
showUserPreview={false} | ||
source={AccountLinkSource.Followers} | ||
/> | ||
</div> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default Members; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ query Groups($request: GroupsRequest!) { | |
items { | ||
...GroupFields | ||
} | ||
pageInfo { | ||
...PaginatedResultInfoFields | ||
} | ||
} | ||
} |
Oops, something went wrong.