From 4d77c6cf8a08cd29a38736e033e6c412c9e610dc Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Thu, 6 Jun 2024 11:13:41 +0200 Subject: [PATCH] Better error handling and visual clue on errors --- src/App.vue | 68 ++++++++++++++++++++++++++++++++++--------- src/main.ts | 4 +-- src/sources.ts | 78 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 109 insertions(+), 41 deletions(-) diff --git a/src/App.vue b/src/App.vue index cc0e0c2..fde9898 100644 --- a/src/App.vue +++ b/src/App.vue @@ -10,6 +10,7 @@ import { fetchPosts } from '@/sources' import Card from './components/Card.vue'; import ConfigModal from './components/ConfigModal.vue'; import InfoBar from './components/InfoBar.vue'; +import { arrayUnique } from './utils'; const config = ref(); @@ -18,6 +19,9 @@ const pinned = ref>([]) const hidden = ref>([]) const updateInProgress = ref(false) +const statusText = ref("Initializing ...") +const statusIsError = ref(false) + var updateIntervalHandle: number; var lastUpdate = 0; @@ -127,10 +131,19 @@ async function updateWall() { updateInProgress.value = true try { - allPosts.value = await fetchPosts(cfg) + allPosts.value = await fetchPosts(cfg, progress => { + if (progress.errors.length) { + setStatus(progress.errors.slice(-1)[0].message, true) + } else if (progress.finished < progress.total) { + setStatus(`Updating [${progress.finished}/${progress.total}] ...`) + } else { + setStatus(false) + } + }) + console.debug("Update completed") } catch (e) { - console.warn("Update failed", e) + setStatus(`Update failed: ${e}`) } finally { lastUpdate = Date.now() updateInProgress.value = false; @@ -138,18 +151,29 @@ async function updateWall() { } + +function setStatus(text: string | false, isError?: boolean) { + if (text === false) { + statusText.value = undefined + statusIsError.value = false + } else { + statusText.value = text + statusIsError.value = isError === true + } +} + /** * Filter and order posts based on real-time criteria (e.g. pinned or hidden posts). * Most of filtering already happened earlier. */ const filteredPosts = computed(() => { // Copy to make sure those are detected as a reactive dependencies - var posts: Array = [... allPosts.value] + var posts: Array = [...allPosts.value] const pinnedLocal = [...pinned.value] const hiddenLocal = [...hidden.value] // Filter hidden posts, authors or domains - posts = posts.filter((p) => !hiddenLocal.some(hide => + posts = posts.filter((p) => !hiddenLocal.some(hide => p.id == hide || p.author?.profile.endsWith(hide) )) @@ -186,7 +210,8 @@ const hideAuthor = (profile: string) => { const hideDomain = (profile: string) => { var domain = profile.split("@").pop() - toggle(hidden.value, "@" + domain) + if (domain) + toggle(hidden.value, "@" + domain) } const toggleTheme = () => { @@ -204,8 +229,7 @@ const privacyLink = computed(() => {