refactor(freshness): drop time-based stale-known status

The 2-minute timer + tick ref decayed verified to stale-known and rendered
a clock icon, but the user can always click the badge to re-check. Removing
the timer simplifies the hook and the badge has one fewer visual state.
This commit is contained in:
Julien Calixte
2026-05-04 23:53:48 +02:00
parent 84803c45dd
commit e425be5c96
2 changed files with 17 additions and 60 deletions

View File

@@ -13,9 +13,6 @@ defineEmits<{ (e: "click"): void }>()
const formatTime = (d: Date) =>
d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" })
const minutesAgo = (d: Date) =>
Math.max(1, Math.round((Date.now() - d.getTime()) / 60000))
const label = computed(() => {
switch (props.status) {
case "verified":
@@ -24,10 +21,6 @@ const label = computed(() => {
return "Checking…"
case "outdated":
return "Outdated"
case "stale-known":
return props.lastCheckedAt
? `Checked ${minutesAgo(props.lastCheckedAt)}m ago`
: "Not checked"
case "offline":
return "Cant reach GitHub"
case "unknown":
@@ -44,8 +37,6 @@ const tooltip = computed(() => {
: "Click to re-check."
case "outdated":
return "GitHub has a newer version. Click to pull latest."
case "stale-known":
return "Click to verify against GitHub."
case "offline":
return "Could not reach GitHub. Click to retry."
case "checking":
@@ -88,14 +79,9 @@ const isBusy = computed(() => props.status === "checking")
<path d="M15 19l2 2l4 -4" />
</svg>
<svg
v-else-if="status === 'unknown' || status === 'stale-known'"
v-else-if="status === 'unknown'"
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler"
:class="
status === 'stale-known'
? 'icon-tabler-clock'
: 'icon-tabler-cloud-question'
"
class="icon icon-tabler icon-tabler-cloud-question"
width="20"
height="20"
viewBox="0 0 24 24"
@@ -105,11 +91,6 @@ const isBusy = computed(() => props.status === "checking")
stroke-linecap="round"
stroke-linejoin="round"
>
<template v-if="status === 'stale-known'">
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
<path d="M12 7v5l3 3" />
</template>
<template v-else>
<path
d="M14.5 18.004h-7.843c-2.572 -.004 -4.657 -2.011 -4.657 -4.487c0 -2.475 2.085 -4.482 4.657 -4.482c.393 -1.762 1.794 -3.2 3.675 -3.773c1.88 -.572 3.956 -.193 5.444 1c1.488 1.19 2.162 3.007 1.77 4.769h.99"
/>
@@ -117,7 +98,6 @@ const isBusy = computed(() => props.status === "checking")
<path
d="M19 19a2.003 2.003 0 0 0 .914 -3.782a1.98 1.98 0 0 0 -2.414 .483"
/>
</template>
</svg>
<svg
v-else-if="status === 'outdated'"
@@ -212,7 +192,6 @@ const isBusy = computed(() => props.status === "checking")
}
.state-unknown,
.state-stale-known,
.state-checking {
color: var(--color-base-content);
opacity: 0.6;

View File

@@ -1,4 +1,4 @@
import { computed, Ref, ref } from "vue"
import { Ref, ref } from "vue"
import { useGitHubContent } from "@/hooks/useGitHubContent.hook"
import { markdownBuilder } from "@/hooks/useMarkdown.hook"
@@ -10,12 +10,9 @@ export type FreshnessStatus =
| "unknown"
| "checking"
| "verified"
| "stale-known"
| "outdated"
| "offline"
const STALE_AFTER_MS = 2 * 60 * 1000
export const useNoteFreshness = ({
user,
repo,
@@ -32,54 +29,36 @@ export const useNoteFreshness = ({
const store = useUserRepoStore()
const { fetchLatestSha } = useGitHubContent({ user, repo })
const rawStatus = ref<FreshnessStatus>("unknown")
const status = ref<FreshnessStatus>("unknown")
const lastCheckedAt = ref<Date | null>(null)
const latestSha = ref<string | null>(null)
const tick = ref(0)
let staleTimer: ReturnType<typeof setTimeout> | null = null
const status = computed<FreshnessStatus>(() => {
void tick.value
if (rawStatus.value !== "verified") return rawStatus.value
if (!lastCheckedAt.value) return rawStatus.value
const age = Date.now() - lastCheckedAt.value.getTime()
return age > STALE_AFTER_MS ? "stale-known" : "verified"
})
const armStaleTimer = () => {
if (staleTimer) clearTimeout(staleTimer)
staleTimer = setTimeout(() => {
tick.value++
}, STALE_AFTER_MS + 100)
}
const expectedSha = async () => (await getEditedSha()) ?? sha.value
const check = async () => {
if (!path.value) return
rawStatus.value = "checking"
status.value = "checking"
const remoteSha = await fetchLatestSha(path.value)
if (remoteSha === null) {
rawStatus.value = "offline"
status.value = "offline"
return
}
latestSha.value = remoteSha
lastCheckedAt.value = new Date()
const local = await expectedSha()
rawStatus.value = remoteSha === local ? "verified" : "outdated"
armStaleTimer()
status.value = remoteSha === local ? "verified" : "outdated"
}
const pullLatest = async (): Promise<string | null> => {
if (!path.value) return null
const remoteSha = latestSha.value ?? (await fetchLatestSha(path.value))
if (!remoteSha) {
rawStatus.value = "offline"
status.value = "offline"
return null
}
const fileContent = await queryFileContent(user, repo, remoteSha)
if (!fileContent) {
rawStatus.value = "offline"
status.value = "offline"
return null
}
const { saveCacheNote } = prepareNoteCache(sha.value, path.value)
@@ -90,8 +69,7 @@ export const useNoteFreshness = ({
store.addFile({ path: path.value, sha: remoteSha })
latestSha.value = remoteSha
lastCheckedAt.value = new Date()
rawStatus.value = "verified"
armStaleTimer()
status.value = "verified"
const { getRawContent } = markdownBuilder(sha.value)
return getRawContent(fileContent)
}