fix no posts found while loading

This commit is contained in:
2023-02-21 14:35:57 +10:00
parent b2ef15d45c
commit 1b68387865

View File

@@ -9,7 +9,7 @@
class="mt-5" /> class="mt-5" />
<SMPanelList <SMPanelList
:loading="loading" :loading="loading"
:not-found="posts?.length == 0" :not-found="!loading && posts.length == 0"
not-found-text="No news found"> not-found-text="No news found">
<SMPanel <SMPanel
v-for="post in posts" v-for="post in posts"
@@ -28,7 +28,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref } from "vue"; import { Ref, ref } from "vue";
import { api } from "../helpers/api"; import { api } from "../helpers/api";
import SMMessage from "../components/SMMessage.vue"; import SMMessage from "../components/SMMessage.vue";
import SMPanelList from "../components/SMPanelList.vue"; import SMPanelList from "../components/SMPanelList.vue";
@@ -39,7 +39,7 @@ import { PostCollection, Post } from "../helpers/api.types";
const message = ref(""); const message = ref("");
const loading = ref(true); const loading = ref(true);
let posts: Array<Post> = reactive([]); const posts: Ref<Post[]> = ref([]);
const handleLoad = async () => { const handleLoad = async () => {
message.value = ""; message.value = "";
@@ -53,8 +53,8 @@ const handleLoad = async () => {
.then((result) => { .then((result) => {
const data = result.data as PostCollection; const data = result.data as PostCollection;
posts = data.posts; posts.value = data.posts;
posts.forEach((post) => { posts.value.forEach((post) => {
post.publish_at = new SMDate(post.publish_at, { post.publish_at = new SMDate(post.publish_at, {
format: "ymd", format: "ymd",
utc: true, utc: true,
@@ -64,9 +64,10 @@ const handleLoad = async () => {
.catch((error) => { .catch((error) => {
message.value = message.value =
error.data?.message || "The server is currently not available"; error.data?.message || "The server is currently not available";
})
.finally(() => {
loading.value = false;
}); });
loading.value = false;
}; };
handleLoad(); handleLoad();