diff --git a/components/dashboard/links/Index.vue b/components/dashboard/links/Index.vue index 6b69fa9..cebaad8 100644 --- a/components/dashboard/links/Index.vue +++ b/components/dashboard/links/Index.vue @@ -6,23 +6,37 @@ const links = ref([]) const limit = 24 let cursor = '' let listComplete = false +let listError = false async function getLinks() { - const data = await useAPI('/api/link/list', { - query: { - limit, - cursor, - }, - }) - links.value = links.value.concat(data.links).filter(Boolean) // Sometimes cloudflare will return null, filter out - cursor = data.cursor - listComplete = data.list_complete + try { + const data = await useAPI('/api/link/list', { + query: { + limit, + cursor, + }, + }) + links.value = links.value.concat(data.links).filter(Boolean) // Sometimes cloudflare will return null, filter out + cursor = data.cursor + listComplete = data.list_complete + listError = false + } + catch (error) { + console.error(error) + listError = true + } } const { isLoading } = useInfiniteScroll( document, getLinks, - { distance: 150, interval: 1000, canLoadMore: () => !listComplete }, + { + distance: 150, + interval: 1000, + canLoadMore: () => { + return !listError && !listComplete + }, + }, ) function updateLinkList(link, type) { @@ -68,5 +82,14 @@ function updateLinkList(link, type) { > No more +
+ Loading links failed, + +
diff --git a/components/dashboard/links/Search.vue b/components/dashboard/links/Search.vue index 25bda60..bbcb0e6 100644 --- a/components/dashboard/links/Search.vue +++ b/components/dashboard/links/Search.vue @@ -8,7 +8,7 @@ const isOpen = ref(false) const searchTerm = ref('') const selectedLink = ref(null) -const links = await useAPI('/api/link/search') +const links = ref([]) const { results: filteredLinks } = useFuse(searchTerm, links, { fuseOptions: { @@ -37,6 +37,14 @@ function selectLink(link) { query: { slug: link.slug }, }) } + +async function getLinks() { + links.value = await useAPI('/api/link/search') +} + +onMounted(() => { + getLinks() +})