Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Followers-exclude #10256

Merged
merged 8 commits into from
May 16, 2024
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 } = await 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 } = await 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