(stacked note) cache visited note

This commit is contained in:
2021-03-20 12:24:27 +01:00
parent befbd7652b
commit 71f1642c45
12 changed files with 80 additions and 9 deletions

View File

@@ -1,11 +1,13 @@
import { ref } from 'vue'
import { request } from '@octokit/request'
import { useMarkdown } from '@/hooks/useMarkdown.hook'
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
import { Octokit } from '@octokit/rest'
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
export const useFile = (owner: string, repo: string, sha: string) => {
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
const { accessToken } = useGitHubLogin()
const fromCache = ref(false)
const octokit = new Octokit({
auth: accessToken.value
@@ -15,6 +17,15 @@ export const useFile = (owner: string, repo: string, sha: string) => {
const getContent = async () => {
const { render } = useMarkdown()
const cachedNote = await getCachedNote()
fromCache.value = !!cachedNote
if (cachedNote) {
content.value = render(cachedNote.content)
return
}
const file = await octokit.request(
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
{
@@ -27,12 +38,15 @@ export const useFile = (owner: string, repo: string, sha: string) => {
if (!file) {
return
}
saveCacheNote(file.data.content)
content.value = render(file.data.content)
}
getContent()
return {
content
content,
fromCache
}
}