use new types

This commit is contained in:
2023-02-21 13:48:27 +10:00
parent 8e4044dffb
commit 3018048140

View File

@@ -1,27 +1,29 @@
<template> <template>
<SMPage class="news-list"> <SMPage class="news-list">
<SMMessage <template #container>
v-if="formMessage.message" <SMMessage
:icon="formMessage.icon" v-if="message"
:type="formMessage.type" icon="alert-circle-outline"
:message="formMessage.message" type="error"
class="mt-5" /> :message="message"
<SMPanelList class="mt-5" />
:loading="loading" <SMPanelList
:not-found="posts.value?.length == 0" :loading="loading"
not-found-text="No news found"> :not-found="posts?.length == 0"
<SMPanel not-found-text="No news found">
v-for="post in posts.value" <SMPanel
:key="post.id" v-for="post in posts"
:image="post.hero" :key="post.id"
:to="{ name: 'post-view', params: { slug: post.slug } }" :image="post.hero"
:title="post.title" :to="{ name: 'post-view', params: { slug: post.slug } }"
:date="post.publish_at" :title="post.title"
:content="post.content" :date="post.publish_at"
:show-date="false" :content="post.content"
button="Read More" :show-date="false"
button-type="outline" /> button="Read More"
</SMPanelList> button-type="outline" />
</SMPanelList>
</template>
</SMPage> </SMPage>
</template> </template>
@@ -33,41 +35,36 @@ import SMPanelList from "../components/SMPanelList.vue";
import SMPanel from "../components/SMPanel.vue"; import SMPanel from "../components/SMPanel.vue";
import SMPage from "../components/SMPage.vue"; import SMPage from "../components/SMPage.vue";
import { SMDate } from "../helpers/datetime"; import { SMDate } from "../helpers/datetime";
import { PostCollection, Post } from "../helpers/api.types";
const formMessage = reactive({ const message = ref("");
icon: "",
type: "",
message: "",
});
const loading = ref(true); const loading = ref(true);
const posts = reactive([]); let posts: Array<Post> = reactive([]);
const handleLoad = async () => { const handleLoad = async () => {
formMessage.type = "error"; message.value = "";
formMessage.icon = "fa-solid fa-circle-exclamation";
formMessage.message = "";
try { api.get({
let result = await api.get({ url: "/posts",
url: "/posts", params: {
params: { limit: 5,
limit: 5, },
}, })
}); .then((result) => {
posts.value = result.json.posts; const data = result.data as PostCollection;
posts.value.forEach((post) => { posts = data.posts;
post.publish_at = new SMDate(post.publish_at, { posts.forEach((post) => {
format: "ymd", post.publish_at = new SMDate(post.publish_at, {
utc: true, format: "ymd",
}).format("yyyy/MM/dd HH:mm:ss"); utc: true,
}).format("yyyy/MM/dd HH:mm:ss");
});
})
.catch((error) => {
message.value =
error.data?.message || "The server is currently not available";
}); });
} catch (error) {
formMessage.message =
error.response?.data?.message ||
"The server is currently not available";
}
loading.value = false; loading.value = false;
}; };