mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
feat: add a target description to OneClickEmbedding
Signed-off-by: Philip Molares <philip.molares@udo.edu> Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
644347cee2
commit
79a0ea9602
6 changed files with 22 additions and 12 deletions
|
@ -28,6 +28,9 @@
|
||||||
"png": "Save as PNG",
|
"png": "Save as PNG",
|
||||||
"svg": "Save as SVG",
|
"svg": "Save as SVG",
|
||||||
"errorJson": "Error parsing the JSON"
|
"errorJson": "Error parsing the JSON"
|
||||||
|
},
|
||||||
|
"one-click-embedding": {
|
||||||
|
"previewHoverText": "Click to load content from {{target}}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"landing": {
|
"landing": {
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const AsciinemaFrame: React.FC<IdProps> = ({ id }) => {
|
||||||
containerClassName={'embed-responsive embed-responsive-16by9'}
|
containerClassName={'embed-responsive embed-responsive-16by9'}
|
||||||
previewContainerClassName={'embed-responsive-item'}
|
previewContainerClassName={'embed-responsive-item'}
|
||||||
hoverIcon={'play'}
|
hoverIcon={'play'}
|
||||||
|
targetDescription={'asciinema'}
|
||||||
loadingImageUrl={`https://asciinema.org/a/${id}.png`}>
|
loadingImageUrl={`https://asciinema.org/a/${id}.png`}>
|
||||||
<iframe
|
<iframe
|
||||||
className='embed-responsive-item'
|
className='embed-responsive-item'
|
||||||
|
|
|
@ -28,7 +28,11 @@ export const GistFrame: React.FC<IdProps> = ({ id }) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OneClickEmbedding previewContainerClassName={'gist-frame'} loadingImageUrl={preview} hoverIcon={'github'}>
|
<OneClickEmbedding
|
||||||
|
previewContainerClassName={'gist-frame'}
|
||||||
|
loadingImageUrl={preview}
|
||||||
|
hoverIcon={'github'}
|
||||||
|
targetDescription={'GitHub Gist'}>
|
||||||
<iframe
|
<iframe
|
||||||
sandbox=''
|
sandbox=''
|
||||||
{...cypressId('gh-gist')}
|
{...cypressId('gh-gist')}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useMemo, useState } from 'react'
|
||||||
import { Trans } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { IconName } from '../../../common/fork-awesome/types'
|
import type { IconName } from '../../../common/fork-awesome/types'
|
||||||
import { ShowIf } from '../../../common/show-if/show-if'
|
import { ShowIf } from '../../../common/show-if/show-if'
|
||||||
import './one-click-embedding.scss'
|
import './one-click-embedding.scss'
|
||||||
|
@ -19,7 +19,7 @@ interface OneClickFrameProps {
|
||||||
loadingImageUrl?: string
|
loadingImageUrl?: string
|
||||||
hoverIcon?: IconName
|
hoverIcon?: IconName
|
||||||
hoverTextI18nKey?: string
|
hoverTextI18nKey?: string
|
||||||
tooltip?: string
|
targetDescription?: string
|
||||||
containerClassName?: string
|
containerClassName?: string
|
||||||
previewContainerClassName?: string
|
previewContainerClassName?: string
|
||||||
onActivate?: () => void
|
onActivate?: () => void
|
||||||
|
@ -31,13 +31,13 @@ export const OneClickEmbedding: React.FC<OneClickFrameProps> = ({
|
||||||
onImageFetch,
|
onImageFetch,
|
||||||
loadingImageUrl,
|
loadingImageUrl,
|
||||||
children,
|
children,
|
||||||
tooltip,
|
targetDescription,
|
||||||
hoverIcon,
|
hoverIcon,
|
||||||
hoverTextI18nKey,
|
|
||||||
onActivate
|
onActivate
|
||||||
}) => {
|
}) => {
|
||||||
const [showFrame, setShowFrame] = useState(false)
|
const [showFrame, setShowFrame] = useState(false)
|
||||||
const [previewImageUrl, setPreviewImageUrl] = useState(loadingImageUrl)
|
const [previewImageUrl, setPreviewImageUrl] = useState(loadingImageUrl)
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const showChildren = () => {
|
const showChildren = () => {
|
||||||
setShowFrame(true)
|
setShowFrame(true)
|
||||||
|
@ -59,6 +59,10 @@ export const OneClickEmbedding: React.FC<OneClickFrameProps> = ({
|
||||||
})
|
})
|
||||||
}, [onImageFetch])
|
}, [onImageFetch])
|
||||||
|
|
||||||
|
const previewHoverText = useMemo(() => {
|
||||||
|
return targetDescription ? t('renderer.one-click-embedding.previewHoverText', { target: targetDescription }) : ''
|
||||||
|
}, [t, targetDescription])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={containerClassName}>
|
<span className={containerClassName}>
|
||||||
<ShowIf condition={showFrame}>{children}</ShowIf>
|
<ShowIf condition={showFrame}>{children}</ShowIf>
|
||||||
|
@ -68,17 +72,13 @@ export const OneClickEmbedding: React.FC<OneClickFrameProps> = ({
|
||||||
<ProxyImageFrame
|
<ProxyImageFrame
|
||||||
className={'one-click-embedding-preview'}
|
className={'one-click-embedding-preview'}
|
||||||
src={previewImageUrl}
|
src={previewImageUrl}
|
||||||
alt={tooltip || ''}
|
alt={previewHoverText}
|
||||||
title={tooltip || ''}
|
title={previewHoverText}
|
||||||
/>
|
/>
|
||||||
</ShowIf>
|
</ShowIf>
|
||||||
<ShowIf condition={!!hoverIcon}>
|
<ShowIf condition={!!hoverIcon}>
|
||||||
<span className='one-click-embedding-icon text-center'>
|
<span className='one-click-embedding-icon text-center'>
|
||||||
<i className={`fa fa-${hoverIcon as string} fa-5x mb-2`} />
|
<i className={`fa fa-${hoverIcon as string} fa-5x mb-2`} />
|
||||||
<ShowIf condition={!!hoverTextI18nKey}>
|
|
||||||
<br />
|
|
||||||
<Trans i18nKey={hoverTextI18nKey} />
|
|
||||||
</ShowIf>
|
|
||||||
</span>
|
</span>
|
||||||
</ShowIf>
|
</ShowIf>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -38,6 +38,7 @@ export const VimeoFrame: React.FC<IdProps> = ({ id }) => {
|
||||||
previewContainerClassName={'embed-responsive-item'}
|
previewContainerClassName={'embed-responsive-item'}
|
||||||
loadingImageUrl={'https://i.vimeocdn.com/video/'}
|
loadingImageUrl={'https://i.vimeocdn.com/video/'}
|
||||||
hoverIcon={'vimeo-square'}
|
hoverIcon={'vimeo-square'}
|
||||||
|
targetDescription={'Vimeo'}
|
||||||
onImageFetch={getPreviewImageLink}>
|
onImageFetch={getPreviewImageLink}>
|
||||||
<iframe
|
<iframe
|
||||||
className='embed-responsive-item'
|
className='embed-responsive-item'
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const YouTubeFrame: React.FC<IdProps> = ({ id }) => {
|
||||||
containerClassName={'embed-responsive embed-responsive-16by9'}
|
containerClassName={'embed-responsive embed-responsive-16by9'}
|
||||||
previewContainerClassName={'embed-responsive-item'}
|
previewContainerClassName={'embed-responsive-item'}
|
||||||
hoverIcon={'youtube-play'}
|
hoverIcon={'youtube-play'}
|
||||||
|
targetDescription={'YouTube'}
|
||||||
loadingImageUrl={`https://i.ytimg.com/vi/${id}/maxresdefault.jpg`}>
|
loadingImageUrl={`https://i.ytimg.com/vi/${id}/maxresdefault.jpg`}>
|
||||||
<iframe
|
<iframe
|
||||||
className='embed-responsive-item'
|
className='embed-responsive-item'
|
||||||
|
|
Loading…
Reference in a new issue