♻️ (store) use a store to store readme and files

This commit is contained in:
2021-03-24 21:23:23 +01:00
parent 165cfb96e7
commit e199c68d68
18 changed files with 202 additions and 229 deletions

View File

@@ -1,19 +1,15 @@
import { useFile } from '@/hooks/useFile.hook'
import { useRepo } from '@/hooks/useRepo.hook'
import { resolvePath } from '@/modules/repo/services/resolvePath'
import { computed, Ref } from 'vue'
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
import { computed } from 'vue'
const SRC_PREFIX = 'data:image/jpeg;charset=utf-8;base64,'
export const useImages = (
user: Ref<string>,
repo: Ref<string>,
sha: string
) => {
const { tree } = useRepo(user, repo, false)
export const useImages = (sha: string) => {
const store = useUserRepoStore()
const currentFilePath = computed(
() => tree.value.find((file) => file.sha === sha)?.path
() => store.files.find((file) => file.sha === sha)?.path
)
const images = document.querySelectorAll(`.note-${sha} img`)
@@ -30,17 +26,12 @@ export const useImages = (
image.getAttribute('src') ?? ''
)
const imageFile = tree.value.find((file) => file.path === imageFilePath)
const imageFile = store.files.find((file) => file.path === imageFilePath)
if (!imageFile?.sha) {
return
}
const { getFileContent } = useFile(
user.value,
repo.value,
imageFile.sha,
false
)
const { getFileContent } = useFile(imageFile.sha, false)
const fileContent = await getFileContent()
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)