Show a sync-in-progress spinner in the header next to the feed filter

activeSyncCount/isSyncing() in useFeeds.js already refcounted both boot
reload (fetchData) and manual sync() but wasn't reactive. Make it a ref
+ computed and expose it so AppNav can render a small spinner next to
the feed filter whenever a sync is in flight.

The spinner sits outside the filter's own v-if so it also shows during
a manual sync from pages other than /feeds, and its box is always
reserved (visibility toggle, not v-if) so the one-time --app-nav-height
measurement stays correct.
This commit is contained in:
mathias committed 2026-09-14 18:05:24 +02:00
1 parent 4d9e899519
commit 9c042411fb
4 files changed
+171 -13

No files matched your search

+86 -2
View File
@@ -12,7 +12,7 @@ class FakeIntersectionObserver {
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver)
describe('useFeeds', () => {
const { feeds, allItems, feedFilter, feedTitles, feedUnreadCounts, unreadCount, displayedFeedUnreadCounts, refreshUnreadDisplay, setFeedFilter, showMessage, message, viewMode, currentIndex, fetchData, sync, getReadable, setInitialLoad, handleIntersection, markAllRead, markRead, markCurrentArticleRead, setupIntersectionObserver } = useFeeds()
const { feeds, allItems, feedFilter, feedTitles, feedUnreadCounts, unreadCount, displayedFeedUnreadCounts, refreshUnreadDisplay, setFeedFilter, showMessage, message, viewMode, currentIndex, fetchData, sync, getReadable, setInitialLoad, handleIntersection, markAllRead, markRead, markCurrentArticleRead, setupIntersectionObserver, isSyncing } = useFeeds()
beforeEach(() => {
localStorage.setItem('user-token', 'test-token')
@@ -289,7 +289,7 @@ describe('useFeeds', () => {
axios.get.mockReturnValueOnce(new Promise(resolve => { resolveGet = resolve }))
const fetchPromise = fetchData()
markCurrentArticleRead() // queued: isSyncing() is true
markCurrentArticleRead() // queued: isSyncing is true
// The user backs out to list view before the reload finishes —
// leaveArticleView()'s dropReadArticles() runs here, but this article
// isn't flagged read yet (it's only queued), so it survives that pass.
@@ -366,6 +366,90 @@ describe('useFeeds', () => {
})
})
describe('isSyncing', () => {
// Lets a just-resolved deferred promise's `.then` continuations (e.g.
// sync()'s `await fetchData()`) actually run before the next assertion,
// without pulling in fake timers (see the CLAUDE.md Vitest gotcha).
async function flushMicrotasks() {
for (let i = 0; i < 5; i++) await Promise.resolve()
}
it('is false initially, true while a fetchData() call is in flight, and false again once it resolves', async () => {
expect(isSyncing.value).toBe(false)
let resolveGet
axios.get.mockReturnValueOnce(new Promise(resolve => { resolveGet = resolve }))
const fetchPromise = fetchData()
expect(isSyncing.value).toBe(true)
resolveGet({ data: { feeds: [] } })
await fetchPromise
expect(isSyncing.value).toBe(false)
})
it('stays true for the whole duration of sync(), including its trailing fetchData(), and only clears once sync() fully settles', async () => {
let resolvePost
axios.post.mockReturnValueOnce(new Promise(resolve => { resolvePost = resolve }))
let resolveGet
axios.get.mockReturnValueOnce(new Promise(resolve => { resolveGet = resolve }))
const syncPromise = sync(true)
expect(isSyncing.value).toBe(true)
// The sync POST settles, handing off into sync()'s own trailing
// fetchData() — isSyncing must not flicker false in between.
resolvePost({ status: 200 })
await flushMicrotasks()
expect(axios.get).toHaveBeenCalled()
expect(isSyncing.value).toBe(true)
resolveGet({ data: { feeds: [] } })
await syncPromise
expect(isSyncing.value).toBe(false)
})
it('leaves isSyncing true while an independent fetchData() completes during a still in-flight sync(), clearing only once both finish', async () => {
let resolvePost
axios.post.mockReturnValueOnce(new Promise(resolve => { resolvePost = resolve }))
const syncPromise = sync(true)
expect(isSyncing.value).toBe(true)
// An independent fetchData() call runs to completion while sync()'s
// POST is still pending.
axios.get.mockResolvedValueOnce({ data: { feeds: [] } })
await fetchData()
// sync() itself hasn't finished yet.
expect(isSyncing.value).toBe(true)
axios.get.mockResolvedValueOnce({ data: { feeds: [] } })
resolvePost({ status: 200 })
await syncPromise
expect(isSyncing.value).toBe(false)
})
it('clears on a rejected fetchData()', async () => {
axios.get.mockRejectedValueOnce(new Error('network'))
await fetchData() // caught internally — resolves rather than rejecting
expect(isSyncing.value).toBe(false)
})
it('clears on a rejected sync()', async () => {
axios.post.mockRejectedValueOnce(new Error('network'))
await sync(true) // caught internally — resolves rather than rejecting
expect(isSyncing.value).toBe(false)
})
})
describe('markRead resilience', () => {
// Mirrors useFeeds.js's MARK_READ_RETRY_DELAYS_MS (not exported). Kept in
// sync via this comment: if that backoff changes, update this too — too