feat(notes): banner when viewing an older shared version
All checks were successful
CI / verify (push) Successful in 1m3s

Cache the note path on each snapshot so an old shared sha can find its
current version, and show a calm "older shared version — View latest"
banner. The exact snapshot is shown as-is; the banner only offers a jump
to the latest, never swapping content.
This commit is contained in:
Julien Calixte
2026-06-29 01:04:51 +02:00
parent 2f8d3c24a4
commit 9d27aa024f
6 changed files with 106 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { computed, Ref, ref, toValue } from "vue"
import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
import { latestShaIfOlder } from "@/modules/note/snapshotStatus"
import { queryFileContent } from "@/modules/repo/services/repo"
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
@@ -14,6 +15,16 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
return file?.path
})
// Path recovered from the cached note doc — lets us locate the latest version
// even when this (old) sha is no longer in store.files.
const cachedNotePath = ref<string | undefined>()
// When viewing an older snapshot of a known note, the note's current sha
// (null when already viewing the latest).
const newerSha = computed(() =>
latestShaIfOlder(shaValue, path.value ?? cachedNotePath.value, store.files)
)
const {
render,
renderFromUTF8,
@@ -47,6 +58,8 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
fromCache.value = !!cachedNote
if (cachedNote) {
cachedNotePath.value = cachedNote.path ?? cachedNotePath.value
if (from === "path") {
queryFileContent(store.user, store.repo, shaValue).then(
(fileContent) => {
@@ -104,6 +117,7 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
return {
path,
newerSha,
content,
rawContent,
getRawContent,