From a6a189ba59b2bf71d05616bec532c28f1c09d8f6 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 15 Nov 2022 16:56:11 +0100 Subject: [PATCH] feat: following and followers routes (#4) --- components/account/AccountCard.vue | 18 ++++++++ components/account/AccountHeader.vue | 12 ++++-- .../account/AccountPaginator.client.vue | 22 ++++++++++ .../timeline/TimelinePaginator.client.vue | 37 +---------------- composables/paginator.ts | 41 +++++++++++++++++++ pages/@[user]/followers.vue | 18 ++++++++ pages/@[user]/following.vue | 18 ++++++++ 7 files changed, 127 insertions(+), 39 deletions(-) create mode 100644 components/account/AccountCard.vue create mode 100644 components/account/AccountPaginator.client.vue create mode 100644 composables/paginator.ts create mode 100644 pages/@[user]/followers.vue create mode 100644 pages/@[user]/following.vue diff --git a/components/account/AccountCard.vue b/components/account/AccountCard.vue new file mode 100644 index 00000000..199d587a --- /dev/null +++ b/components/account/AccountCard.vue @@ -0,0 +1,18 @@ + + + diff --git a/components/account/AccountHeader.vue b/components/account/AccountHeader.vue index 49cdf0e0..580c5fb6 100644 --- a/components/account/AccountHeader.vue +++ b/components/account/AccountHeader.vue @@ -71,9 +71,15 @@ const createdAt = $computed(() => {
-
{{ account.statusesCount }} Posts
-
{{ account.followingCount }} Following
-
{{ account.followersCount }} Followers
+ + {{ account.statusesCount }} Posts + + + {{ account.followingCount }} Following + + + {{ account.followersCount }} Followers +
diff --git a/components/account/AccountPaginator.client.vue b/components/account/AccountPaginator.client.vue new file mode 100644 index 00000000..e82fc1ee --- /dev/null +++ b/components/account/AccountPaginator.client.vue @@ -0,0 +1,22 @@ + + + diff --git a/components/timeline/TimelinePaginator.client.vue b/components/timeline/TimelinePaginator.client.vue index 4e1512dc..61fdaef4 100644 --- a/components/timeline/TimelinePaginator.client.vue +++ b/components/timeline/TimelinePaginator.client.vue @@ -5,42 +5,7 @@ const { paginator } = defineProps<{ paginator: Paginator }>() -let isLoading = $ref(false) -let isDone = $ref(false) -const statuses = $ref([]) - -const endAnchor = ref() -const bound = reactive(useElementBounding(endAnchor)) -const isInScreen = $computed(() => bound.top < window.innerHeight * 2) - -async function loadNext() { - if (isLoading || isDone) - return - - // console.log('REQUEST') - isLoading = true - const result = await paginator.next() - if (result.done) - isDone = true - if (result.value?.length) - statuses.push(...result.value) - isLoading = false - await nextTick() - bound.update() -} - -useIntervalFn(() => { - bound.update() -}, 1000) - -watch( - () => isInScreen, - () => { - if (isInScreen && !isLoading) - loadNext() - }, - { immediate: true }, -) +const { items: statuses, isLoading, isDone, endAnchor } = usePaginator(paginator)