From 54c52feebaae2fc3c91a76f8732ee65e037dcb6e Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Mon, 25 May 2026 21:25:54 +0200 Subject: [PATCH] refactor(notes): return failure status from pullLatest Callers had to read back the side-effected status ref to know why a pull failed, which also broke TS narrowing on the freshness badge handler. Return { raw, failureStatus } so the reason flows through the return value. --- src/components/StackedNote.vue | 18 +++++++++--------- src/hooks/useNoteFreshness.hook.ts | 13 ++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/components/StackedNote.vue b/src/components/StackedNote.vue index eac69dd..f892c08 100644 --- a/src/components/StackedNote.vue +++ b/src/components/StackedNote.vue @@ -236,10 +236,10 @@ watch(mode, async (newMode) => { }) const onConflictDiscard = async () => { - const newRaw = await pullLatest() - if (newRaw !== null) { - rawContent.value = newRaw - initialRawContent.value = newRaw + const { raw } = await pullLatest() + if (raw !== null) { + rawContent.value = raw + initialRawContent.value = raw } } @@ -269,13 +269,13 @@ const onBadgeClick = async () => { return } - const newRaw = await pullLatest() - if (newRaw !== null) { - rawContent.value = newRaw - initialRawContent.value = newRaw + const { raw, failureStatus } = await pullLatest() + if (raw !== null) { + rawContent.value = raw + initialRawContent.value = raw return } - if (freshnessStatus.value === "unauthorized") { + if (failureStatus === "unauthorized") { errorMessage("🔐 GitHub auth expired — please sign in again") } } catch (error) { diff --git a/src/hooks/useNoteFreshness.hook.ts b/src/hooks/useNoteFreshness.hook.ts index 81a955b..129e543 100644 --- a/src/hooks/useNoteFreshness.hook.ts +++ b/src/hooks/useNoteFreshness.hook.ts @@ -77,14 +77,17 @@ export const useNoteFreshness = ({ return { sha: result.sha, failureStatus: null } } - const pullLatest = async (): Promise => { - if (!path.value) return null + const pullLatest = async (): Promise<{ + raw: string | null + failureStatus: FreshnessStatus | null + }> => { + if (!path.value) return { raw: null, failureStatus: null } const usedCachedSha = latestSha.value !== null const { sha: remoteSha, failureStatus } = await resolveRemoteSha(path.value) if (!remoteSha) { console.warn("pullLatest: could not resolve remote sha", { path: path.value }) if (failureStatus) status.value = failureStatus - return null + return { raw: null, failureStatus } } const fileContent = await queryFileContent(user, repo, remoteSha) if (!fileContent) { @@ -96,7 +99,7 @@ export const useNoteFreshness = ({ // Cached SHA may be stale — clear so the next click re-resolves it. if (usedCachedSha) latestSha.value = null status.value = "offline" - return null + return { raw: null, failureStatus: "offline" } } const { saveCacheNote } = prepareNoteCache(sha.value, path.value) await saveCacheNote(fileContent, { @@ -108,7 +111,7 @@ export const useNoteFreshness = ({ lastCheckedAt.value = new Date() status.value = "verified" const { getRawContent } = markdownBuilder(sha.value) - return getRawContent(fileContent) + return { raw: getRawContent(fileContent), failureStatus: null } } return {