🐛 (images) fix images not showing when reloading the page

This commit is contained in:
Julien Calixte
2023-07-18 00:19:27 +02:00
parent 9d85abbc64
commit f2d464ce74
2 changed files with 18 additions and 12 deletions

View File

@@ -36,13 +36,15 @@ const { displayNoteOverlay } = useNoteOverlay(className.value, props.index)
const displayedTitle = computed(() => filenameToNoteTitle(props.title)) const displayedTitle = computed(() => filenameToNoteTitle(props.title))
watch(content, () => { watch(content, () => {
if (content.value) { if (!content.value) {
nextTick(() => { return
listenToClick()
useImages(props.sha)
generateTweets()
})
} }
nextTick(() => {
listenToClick()
useImages(props.sha)
generateTweets()
})
}) })
const focus = () => scrollToFocusedNote(props.sha) const focus = () => scrollToFocusedNote(props.sha)

View File

@@ -1,7 +1,7 @@
import { useFile } from '@/hooks/useFile.hook' import { useFile } from '@/hooks/useFile.hook'
import { resolvePath } from '@/modules/repo/services/resolvePath' import { resolvePath } from '@/modules/repo/services/resolvePath'
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store' import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
import { computed } from 'vue' import { computed, watch } from 'vue'
const SRC_PREFIX = 'data:image/jpeg;charset=utf-8;base64,' const SRC_PREFIX = 'data:image/jpeg;charset=utf-8;base64,'
@@ -12,17 +12,21 @@ export const useImages = (sha: string) => {
() => store.files.find((file) => file.sha === sha)?.path () => store.files.find((file) => file.sha === sha)?.path
) )
const images = document.querySelectorAll(`.note-${sha} img`) watch(currentFilePath, (filePath) => {
if (!filePath) {
return
}
images.forEach(async (image) => { const images = document.querySelectorAll(`.note-${sha} img`)
if (currentFilePath.value) {
images.forEach(async (image) => {
const src = image.getAttribute('src') const src = image.getAttribute('src')
if (!src || src.startsWith(SRC_PREFIX)) { if (!src || src.startsWith(SRC_PREFIX)) {
return return
} }
const imageFilePath = resolvePath( const imageFilePath = resolvePath(
currentFilePath.value, filePath,
image.getAttribute('src') ?? '' image.getAttribute('src') ?? ''
) )
@@ -35,6 +39,6 @@ export const useImages = (sha: string) => {
const fileContent = await getCachedFileContent() const fileContent = await getCachedFileContent()
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`) image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
} })
}) })
} }