Skip to content

Commit

Permalink
Merge pull request #10256 from kodadot/followers-exclude
Browse files Browse the repository at this point in the history
Followers-exclude
  • Loading branch information
prury committed May 16, 2024
2 parents d13865a + 7f99edb commit 16edcb9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
12 changes: 8 additions & 4 deletions components/profile/ProfileDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,17 @@ const { data: isFollowingThisAccount, refresh: refreshFollowingStatus } =
)
const { data: followers, refresh: refreshFollowers } = useAsyncData(
'followers',
() => fetchFollowersOf(route.params.id as string, 3),
`followersof${route.params.id}`,
() =>
fetchFollowersOf(route.params.id as string, {
limit: 3,
exclude: [accountId.value],
}),
)
const { data: following, refresh: refreshFollowing } = useAsyncData(
'following',
() => fetchFollowing(route.params.id as string, 1),
`following${route.params.id}`,
() => fetchFollowing(route.params.id as string, { limit: 1 }),
)
const refresh = () => {
Expand Down
16 changes: 8 additions & 8 deletions components/profile/follow/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const props = defineProps<{
}>()
const vList = useVModel(props, 'userList')
const { accountId } = useAuth()
const offset = computed(() => vList.value.length)
const limit = 10
const el = ref<HTMLElement | null>(null)
Expand All @@ -42,18 +43,17 @@ const fetchNextPage = async () => {
isLoading.value = true
}
if (props.type === 'following') {
const { following } = await fetchFollowing(
route.params.id as string,
const { following } = await fetchFollowing(route.params.id as string, {
limit,
offset.value,
)
offset: offset.value,
})
vList.value.push(...following)
} else {
const { followers } = await fetchFollowersOf(
route.params.id as string,
const { followers } = await fetchFollowersOf(route.params.id as string, {
limit,
offset.value,
)
offset: offset.value,
exclude: [accountId.value],
})
vList.value.push(...followers)
}
Expand Down
5 changes: 4 additions & 1 deletion components/profile/follow/UserRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ const showFollowing = ref(false)
const { urlPrefix } = usePrefix()
const { data: followersCount, refresh: refreshCount } = useAsyncData(
`followerCountOf/${props.user.address}`,
() => fetchFollowersOf(props.user.address, 0).then((res) => res.totalCount),
() =>
fetchFollowersOf(props.user.address, { limit: 0 }).then(
(res) => res.totalCount,
),
)
const { data: isFollowed, refresh: refreshFollowStatus } = useAsyncData(
Expand Down
14 changes: 8 additions & 6 deletions services/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,29 @@ export const fetchProfileByAddress = (address: string) =>

export const fetchFollowersOf = (
address: string,
limit?: number,
offset?: number,
options?: { limit?: number; offset?: number; exclude?: string[] },
) =>
api<{ followers: Follower[]; totalCount: number }>(
`/follow/${toSubstrateAddress(address)}/followers`,
{
method: 'GET',
query: { limit, offset },
query: {
limit: options?.limit,
offset: options?.offset,
exclude: options?.exclude?.map(toSubstrateAddress).join(','),
},
},
)

export const fetchFollowing = (
address: string,
limit?: number,
offset?: number,
options?: { limit?: number; offset?: number },
) =>
api<{ following: Follower[]; totalCount: number }>(
`/follow/${toSubstrateAddress(address)}/following`,
{
method: 'GET',
query: { limit, offset },
query: { limit: options?.limit, offset: options?.offset },
},
)

Expand Down

0 comments on commit 16edcb9

Please sign in to comment.