Add loader to local timeline and thread page

This commit is contained in:
silverpill 2022-11-29 23:32:37 +00:00
parent 05982a10fc
commit accc6fffbe
2 changed files with 21 additions and 2 deletions

View file

@ -15,6 +15,7 @@
@comment-created="onCommentCreated(index, $event)"
@post-deleted="onPostDeleted(index)"
></post>
<loader v-if="isLoading"></loader>
</template>
</sidebar-layout>
</template>
@ -25,6 +26,7 @@ import { $, $ref } from "vue/macros"
import { useRoute } from "vue-router"
import { Post as PostObject, getPostContext } from "@/api/posts"
import Loader from "@/components/Loader.vue"
import Post from "@/components/Post.vue"
import SidebarLayout from "@/components/SidebarLayout.vue"
import { useCurrentUser } from "@/store/user"
@ -36,11 +38,11 @@ let selectedId = $ref(route.params.postId as string)
let highlightedId = $ref<string | null>(null)
let thread = $ref<PostObject[]>([])
let isLoading = $ref(true)
const loader = $ref(getPostContext(authToken, selectedId))
const loaded = $ref(getPostContext(authToken, selectedId))
onMounted(async () => {
try {
thread = await loader
thread = await loaded
} catch (error: any) {
if (error.message === "post not found") {
// Show "not found" text
@ -118,4 +120,8 @@ function onPostDeleted(postIndex: number) {
.post {
margin: 0 0 $block-outer-padding;
}
.loader {
margin: $block-outer-padding auto;
}
</style>

View file

@ -2,6 +2,7 @@
<sidebar-layout>
<template #content>
<post-list :posts="posts" @load-next-page="loadNextPage"></post-list>
<loader v-if="isLoading"></loader>
</template>
</sidebar-layout>
</template>
@ -11,16 +12,20 @@ import { onMounted } from "vue"
import { $ref } from "vue/macros"
import { Post, getPublicTimeline } from "@/api/posts"
import Loader from "@/components/Loader.vue"
import PostList from "@/components/PostList.vue"
import SidebarLayout from "@/components/SidebarLayout.vue"
import { useCurrentUser } from "@/store/user"
const { ensureAuthToken } = useCurrentUser()
let posts = $ref<Post[]>([])
let isLoading = $ref(false)
onMounted(async () => {
const authToken = ensureAuthToken()
isLoading = true
posts = await getPublicTimeline(authToken)
isLoading = false
})
async function loadNextPage(maxId: string) {
@ -29,3 +34,11 @@ async function loadNextPage(maxId: string) {
posts.push(...nextPage)
}
</script>
<style scoped lang="scss">
@import "../styles/layout";
.loader {
margin: $block-outer-padding auto;
}
</style>