use new caching

This commit is contained in:
2023-08-28 23:16:12 +10:00
parent 04be7fdb3c
commit 0f34c7dfb9
2 changed files with 157 additions and 97 deletions

View File

@@ -108,44 +108,43 @@ const handleLoad = async () => {
let slug = useRoute().params.slug || ""; let slug = useRoute().params.slug || "";
pageLoading.value = true; pageLoading.value = true;
try { if (slug.length > 0) {
if (slug.length > 0) { let result = await api.get({
let result = await api.get({ url: "/articles",
url: "/articles", params: {
params: { slug: `=${slug}`,
slug: `=${slug}`, limit: 1,
limit: 1, },
}, callback: (result) => {
}); if (result.status < 300) {
const data = result.data as ArticleCollection;
const data = result.data as ArticleCollection; if (data && data.articles && data.total && data.total > 0) {
article.value = data.articles[0];
if (data && data.articles && data.total && data.total > 0) { article.value.publish_at = new SMDate(
article.value = data.articles[0]; article.value.publish_at,
{
format: "ymd",
utc: true,
},
).format("yyyy/MM/dd HH:mm:ss");
article.value.publish_at = new SMDate( backgroundImageUrl.value = mediaGetVariantUrl(
article.value.publish_at, article.value.hero,
{ "large",
format: "ymd", );
utc: true, applicationStore.setDynamicTitle(article.value.title);
}, } else {
).format("yyyy/MM/dd HH:mm:ss"); pageStatus.value = 404;
}
}
backgroundImageUrl.value = mediaGetVariantUrl( pageLoading.value = false;
article.value.hero, },
"large", });
); } else {
applicationStore.setDynamicTitle(article.value.title); pageStatus.value = 404;
} else {
pageStatus.value = 404;
}
} else {
pageStatus.value = 404;
}
} catch (error) {
/* empty */
} finally {
pageLoading.value = false;
} }
}; };

View File

@@ -221,74 +221,135 @@ const viewLoad = async () => {
articlesLoading.value = true; articlesLoading.value = true;
articlesError.value = ""; articlesError.value = "";
try { api.get({
await Promise.all([ url: "/events",
api params: {
.get({ limit: 10,
url: "/events", sort: "start_at",
params: { start_at: `>${new SMDate("now").format("yyyy-MM-dd hh:mm:ss")}`,
limit: 10, },
sort: "start_at", callback: (eventsResult) => {
start_at: `>${new SMDate("now").format( if (eventsResult.status < 300) {
"yyyy-MM-dd hh:mm:ss", const eventsData =
)}`, getApiResultData<EventCollection>(eventsResult);
},
})
.then((eventsResult) => {
const eventsData =
getApiResultData<EventCollection>(eventsResult);
if (eventsData && eventsData.events) { if (eventsData && eventsData.events) {
events.value = []; events.value = [];
for (const event of eventsData.events) { for (const event of eventsData.events) {
if ( if (
event.status === "open" || event.status === "open" ||
event.status === "soon" event.status === "soon"
) { ) {
events.value.push(event); events.value.push(event);
if (events.value.length === 4) break; if (events.value.length === 4) break;
}
} }
} }
}) }
.catch((error) => { } else {
if (error.status != 404) { if (eventsResult.status != 404) {
eventsError.value = eventsError.value =
"An error occured retrieving the events"; "An error occured retrieving the events";
} }
}) }
.finally(() => {
eventsLoading.value = false;
}),
api
.get({
url: "/articles",
params: {
limit: 4,
},
})
.then((articlesResult) => {
const articlesData =
getApiResultData<ArticleCollection>(articlesResult);
if (articlesData && articlesData.articles) { eventsLoading.value = false;
articles.value = articlesData.articles; },
} });
})
.catch((error) => { api.get({
if (error.status != 404) { url: "/articles",
articlesError.value = params: {
"An error occured retrieving the posts"; limit: 4,
} },
})
.finally(() => { callback: (articlesResult) => {
articlesLoading.value = false; if (articlesResult.status < 300) {
}), const articlesData =
]); getApiResultData<ArticleCollection>(articlesResult);
} catch {
/* empty */ if (articlesData && articlesData.articles) {
} articles.value = articlesData.articles;
}
} else {
if (articlesResult.status != 404) {
articlesError.value =
"An error occured retrieving the posts";
}
}
articlesLoading.value = false;
},
});
// try {
// await Promise.all([
// api
// .get({
// url: "/events",
// params: {
// limit: 10,
// sort: "start_at",
// start_at: `>${new SMDate("now").format(
// "yyyy-MM-dd hh:mm:ss",
// )}`,
// },
// })
// .then((eventsResult) => {
// const eventsData =
// getApiResultData<EventCollection>(eventsResult);
// if (eventsData && eventsData.events) {
// events.value = [];
// for (const event of eventsData.events) {
// if (
// event.status === "open" ||
// event.status === "soon"
// ) {
// events.value.push(event);
// if (events.value.length === 4) break;
// }
// }
// }
// })
// .catch((error) => {
// if (error.status != 404) {
// eventsError.value =
// "An error occured retrieving the events";
// }
// })
// .finally(() => {
// eventsLoading.value = false;
// }),
// api
// .get({
// url: "/articles",
// params: {
// limit: 4,
// },
// })
// .then((articlesResult) => {
// const articlesData =
// getApiResultData<ArticleCollection>(articlesResult);
// if (articlesData && articlesData.articles) {
// articles.value = articlesData.articles;
// }
// })
// .catch((error) => {
// if (error.status != 404) {
// articlesError.value =
// "An error occured retrieving the posts";
// }
// })
// .finally(() => {
// articlesLoading.value = false;
// }),
// ]);
// } catch {
// /* empty */
// }
}; };
viewLoad(); viewLoad();