store has a first copy of readme from cache is no waiting

This commit is contained in:
Julien Calixte
2023-08-13 21:07:17 +02:00
parent a741c7e1eb
commit 656e4b14a9
4 changed files with 33 additions and 17 deletions

View File

@@ -37,6 +37,22 @@ export const getFiles = async (
return treeResponse?.data.tree.filter((t) => t.type === 'blob') ?? []
}
export const getCachedMainReadme = async (owner: string, repo: string) => {
if (!owner || !repo) {
return null
}
const { render } = useMarkdown()
const { getCachedNote } = useNoteCache(`${owner}-${repo}-README`)
const cachedReadme = await getCachedNote()
if (!cachedReadme) {
return null
}
return render(cachedReadme.content)
}
export const getMainReadme = async (owner: string, repo: string) => {
if (!owner || !repo) {
return null
@@ -47,8 +63,6 @@ export const getMainReadme = async (owner: string, repo: string) => {
`${owner}-${repo}-README`
)
const cachedReadme = await getCachedNote()
try {
const octokit = await getOctokit()
@@ -63,6 +77,8 @@ export const getMainReadme = async (owner: string, repo: string) => {
}
} catch (error) {
console.warn(error)
const cachedReadme = await getCachedNote()
if (cachedReadme) {
return render(cachedReadme.content)
}