Enable pagination on profile timeline
This commit is contained in:
parent
112cf150ba
commit
d1ac840e4a
2 changed files with 22 additions and 23 deletions
|
@ -75,12 +75,18 @@ export async function getTagTimeline(
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPostsByAuthor(
|
export async function getProfileTimeline(
|
||||||
authToken: string | null,
|
authToken: string | null,
|
||||||
authorId: string,
|
authorId: string,
|
||||||
|
maxId?: string,
|
||||||
): Promise<Post[]> {
|
): Promise<Post[]> {
|
||||||
const url = `${BACKEND_URL}/api/v1/accounts/${authorId}/statuses`
|
const url = `${BACKEND_URL}/api/v1/accounts/${authorId}/statuses`
|
||||||
const response = await http(url, { authToken })
|
const queryParams = { max_id: maxId, limit: PAGE_SIZE }
|
||||||
|
const response = await http(url, {
|
||||||
|
method: "GET",
|
||||||
|
queryParams,
|
||||||
|
authToken,
|
||||||
|
})
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,10 @@
|
||||||
<dt>{{ profile.followers_count }}</dt><dd>followers</dd>
|
<dt>{{ profile.followers_count }}</dt><dd>followers</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<post-or-repost
|
<post-list
|
||||||
v-for="post in posts"
|
:posts="posts"
|
||||||
:post="post"
|
@load-next-page="loadNextPage"
|
||||||
:key="post.id"
|
></post-list>
|
||||||
@post-deleted="onPostDeleted($event)"
|
|
||||||
></post-or-repost>
|
|
||||||
</div>
|
</div>
|
||||||
<sidebar></sidebar>
|
<sidebar></sidebar>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,7 +46,7 @@
|
||||||
import { Options, Vue, setup } from "vue-class-component"
|
import { Options, Vue, setup } from "vue-class-component"
|
||||||
|
|
||||||
import { Profile, getProfile } from "@/api/users"
|
import { Profile, getProfile } from "@/api/users"
|
||||||
import { Post, getPostsByAuthor } from "@/api/posts"
|
import { Post, getProfileTimeline } from "@/api/posts"
|
||||||
import {
|
import {
|
||||||
follow,
|
follow,
|
||||||
unfollow,
|
unfollow,
|
||||||
|
@ -56,14 +54,14 @@ import {
|
||||||
getRelationship,
|
getRelationship,
|
||||||
} from "@/api/relationships"
|
} from "@/api/relationships"
|
||||||
import Avatar from "@/components/Avatar.vue"
|
import Avatar from "@/components/Avatar.vue"
|
||||||
import PostOrRepost from "@/components/PostOrRepost.vue"
|
import PostList from "@/components/PostList.vue"
|
||||||
import Sidebar from "@/components/Sidebar.vue"
|
import Sidebar from "@/components/Sidebar.vue"
|
||||||
import { useCurrentUser } from "@/store/user"
|
import { useCurrentUser } from "@/store/user"
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {
|
components: {
|
||||||
Avatar,
|
Avatar,
|
||||||
PostOrRepost,
|
PostList,
|
||||||
Sidebar,
|
Sidebar,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -89,7 +87,7 @@ export default class ProfileView extends Vue {
|
||||||
this.profile.id,
|
this.profile.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
this.posts = await getPostsByAuthor(
|
this.posts = await getProfileTimeline(
|
||||||
this.store.authToken,
|
this.store.authToken,
|
||||||
this.profile.id,
|
this.profile.id,
|
||||||
)
|
)
|
||||||
|
@ -143,9 +141,12 @@ export default class ProfileView extends Vue {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onPostDeleted(postId: string) {
|
async loadNextPage(maxId: string) {
|
||||||
const postIndex = this.posts.findIndex((post) => post.id === postId)
|
if (!this.profile) {
|
||||||
this.posts.splice(postIndex, 1)
|
return
|
||||||
|
}
|
||||||
|
const posts = await getProfileTimeline(this.store.authToken, this.profile.id, maxId)
|
||||||
|
this.posts.push(...posts)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -260,12 +261,4 @@ $avatar-size: 170px;
|
||||||
margin-right: 30px;
|
margin-right: 30px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.action {
|
|
||||||
@include post-action;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.post) {
|
|
||||||
margin-bottom: $block-outer-padding;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue