fix(gallery): invalid source
This commit is contained in:
parent
0167f90326
commit
4ea00d1af6
@ -35,7 +35,7 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
||||
slide: 1
|
||||
})
|
||||
const slides = useMemo(() => {
|
||||
const urls: string[] = []
|
||||
const sources: { url: string; type: 'image' | 'video' | 'youtube' }[] = []
|
||||
const parts = content.matchAll(new RegExp(`${link.source}`, 'gui'))
|
||||
;[...parts]
|
||||
.filter((p) => typeof p !== 'undefined')
|
||||
@ -43,18 +43,23 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
||||
const [href] = part
|
||||
|
||||
if (href && isValidUrl(href)) {
|
||||
if (isValidImageUrl(href) || isValidVideoUrl(href)) {
|
||||
urls.push(href)
|
||||
if (isValidImageUrl(href)) {
|
||||
sources.push({ url: href, type: 'image' })
|
||||
} else if (isValidVideoUrl(href)) {
|
||||
sources.push({ url: href, type: 'video' })
|
||||
} else if (isYoutubeLink(href)) {
|
||||
const id = getIdFromYoutubeLink(href)
|
||||
if (id) {
|
||||
urls.push(`https://www.youtube.com/embed/${id}`)
|
||||
sources.push({
|
||||
url: `https://www.youtube.com/embed/${id}`,
|
||||
type: 'youtube'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return urls
|
||||
return sources
|
||||
}, [content])
|
||||
|
||||
const openLightBoxOnSlide = useCallback(
|
||||
@ -62,7 +67,7 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
||||
slides.length &&
|
||||
setLightBoxController((prev) => ({
|
||||
toggler: !prev.toggler,
|
||||
slide: slides.findIndex((s) => s === url) + 1
|
||||
slide: slides.findIndex((s) => s.url === url) + 1
|
||||
}))
|
||||
},
|
||||
[slides]
|
||||
@ -184,7 +189,8 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
||||
createPortal(
|
||||
<FsLightbox
|
||||
toggler={lightBoxController.toggler}
|
||||
sources={slides}
|
||||
sources={slides.map((s) => s.url)}
|
||||
types={slides.map((s) => s.type)}
|
||||
slide={lightBoxController.slide}
|
||||
/>,
|
||||
document.body
|
||||
|
Loading…
x
Reference in New Issue
Block a user