✨ (stacked note) cache visited note
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Octokit } from '@octokit/rest'
|
||||
import { RepoBase } from '@/modules/interfaces/RepoBase'
|
||||
import { RepoBase } from '@/modules/repo/interfaces/RepoBase'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user