|
|
@ -27,6 +27,7 @@ type PreviewOptionalProps = { |
|
|
|
externalPreview?: string; |
|
|
|
externalPreview?: string; |
|
|
|
externalTimestamp?: number; |
|
|
|
externalTimestamp?: number; |
|
|
|
headerEndAdornment?: ReactNode; |
|
|
|
headerEndAdornment?: ReactNode; |
|
|
|
|
|
|
|
hrefPreview?: string; |
|
|
|
isExternalLoading?: boolean; |
|
|
|
isExternalLoading?: boolean; |
|
|
|
isExternalPreviewStale?: boolean; |
|
|
|
isExternalPreviewStale?: boolean; |
|
|
|
isFetchPreview?: boolean; |
|
|
|
isFetchPreview?: boolean; |
|
|
@ -43,12 +44,19 @@ type PreviewProps = PreviewOptionalProps & { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const PREVIEW_DEFAULT_PROPS: Required< |
|
|
|
const PREVIEW_DEFAULT_PROPS: Required< |
|
|
|
Omit<PreviewOptionalProps, 'onClickConnectButton' | 'onClickPreview'> |
|
|
|
Omit< |
|
|
|
|
|
|
|
PreviewOptionalProps, |
|
|
|
|
|
|
|
'hrefPreview' | 'onClickConnectButton' | 'onClickPreview' |
|
|
|
|
|
|
|
> |
|
|
|
> & |
|
|
|
> & |
|
|
|
Pick<PreviewOptionalProps, 'onClickConnectButton' | 'onClickPreview'> = { |
|
|
|
Pick< |
|
|
|
|
|
|
|
PreviewOptionalProps, |
|
|
|
|
|
|
|
'hrefPreview' | 'onClickConnectButton' | 'onClickPreview' |
|
|
|
|
|
|
|
> = { |
|
|
|
externalPreview: '', |
|
|
|
externalPreview: '', |
|
|
|
externalTimestamp: 0, |
|
|
|
externalTimestamp: 0, |
|
|
|
headerEndAdornment: null, |
|
|
|
headerEndAdornment: null, |
|
|
|
|
|
|
|
hrefPreview: undefined, |
|
|
|
isExternalLoading: false, |
|
|
|
isExternalLoading: false, |
|
|
|
isExternalPreviewStale: false, |
|
|
|
isExternalPreviewStale: false, |
|
|
|
isFetchPreview: true, |
|
|
|
isFetchPreview: true, |
|
|
@ -90,6 +98,7 @@ const Preview: FC<PreviewProps> = ({ |
|
|
|
externalPreview = PREVIEW_DEFAULT_PROPS.externalPreview, |
|
|
|
externalPreview = PREVIEW_DEFAULT_PROPS.externalPreview, |
|
|
|
externalTimestamp = PREVIEW_DEFAULT_PROPS.externalTimestamp, |
|
|
|
externalTimestamp = PREVIEW_DEFAULT_PROPS.externalTimestamp, |
|
|
|
headerEndAdornment, |
|
|
|
headerEndAdornment, |
|
|
|
|
|
|
|
hrefPreview, |
|
|
|
isExternalLoading = PREVIEW_DEFAULT_PROPS.isExternalLoading, |
|
|
|
isExternalLoading = PREVIEW_DEFAULT_PROPS.isExternalLoading, |
|
|
|
isExternalPreviewStale = PREVIEW_DEFAULT_PROPS.isExternalPreviewStale, |
|
|
|
isExternalPreviewStale = PREVIEW_DEFAULT_PROPS.isExternalPreviewStale, |
|
|
|
isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, |
|
|
|
isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, |
|
|
@ -153,6 +162,44 @@ const Preview: FC<PreviewProps> = ({ |
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const iconButton = useMemo(() => { |
|
|
|
|
|
|
|
if (isPreviewLoading) { |
|
|
|
|
|
|
|
return <Spinner mb="1em" mt="1em" />; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const disabled = !preview; |
|
|
|
|
|
|
|
const sx: MUIIconButtonProps['sx'] = { |
|
|
|
|
|
|
|
borderRadius: BORDER_RADIUS, |
|
|
|
|
|
|
|
color: GREY, |
|
|
|
|
|
|
|
padding: 0, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hrefPreview) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<MUIIconButton disabled={disabled} href={hrefPreview} sx={sx}> |
|
|
|
|
|
|
|
{previewButtonContent} |
|
|
|
|
|
|
|
</MUIIconButton> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<MUIIconButton |
|
|
|
|
|
|
|
component="span" |
|
|
|
|
|
|
|
disabled={disabled} |
|
|
|
|
|
|
|
onClick={previewClickHandler} |
|
|
|
|
|
|
|
sx={sx} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{previewButtonContent} |
|
|
|
|
|
|
|
</MUIIconButton> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, [ |
|
|
|
|
|
|
|
hrefPreview, |
|
|
|
|
|
|
|
isPreviewLoading, |
|
|
|
|
|
|
|
preview, |
|
|
|
|
|
|
|
previewButtonContent, |
|
|
|
|
|
|
|
previewClickHandler, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (isFetchPreview) { |
|
|
|
if (isFetchPreview) { |
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
@ -195,24 +242,7 @@ const Preview: FC<PreviewProps> = ({ |
|
|
|
</PreviewPanelHeader> |
|
|
|
</PreviewPanelHeader> |
|
|
|
<FlexBox row sx={{ '& > :first-child': { flexGrow: 1 } }}> |
|
|
|
<FlexBox row sx={{ '& > :first-child': { flexGrow: 1 } }}> |
|
|
|
{/* Box wrapper below is required to keep external preview size sane. */} |
|
|
|
{/* Box wrapper below is required to keep external preview size sane. */} |
|
|
|
<Box textAlign="center"> |
|
|
|
<Box textAlign="center">{iconButton}</Box> |
|
|
|
{isPreviewLoading ? ( |
|
|
|
|
|
|
|
<Spinner mt="1em" mb="1em" /> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<MUIIconButton |
|
|
|
|
|
|
|
component="span" |
|
|
|
|
|
|
|
disabled={!preview} |
|
|
|
|
|
|
|
onClick={previewClickHandler} |
|
|
|
|
|
|
|
sx={{ |
|
|
|
|
|
|
|
borderRadius: BORDER_RADIUS, |
|
|
|
|
|
|
|
color: GREY, |
|
|
|
|
|
|
|
padding: 0, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{previewButtonContent} |
|
|
|
|
|
|
|
</MUIIconButton> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</Box> |
|
|
|
|
|
|
|
{isShowControls && preview && ( |
|
|
|
{isShowControls && preview && ( |
|
|
|
<FlexBox> |
|
|
|
<FlexBox> |
|
|
|
<IconButton onClick={connectButtonClickHandle}> |
|
|
|
<IconButton onClick={connectButtonClickHandle}> |
|
|
|