|
|
@ -14,20 +14,22 @@ import { BodyText, HeaderText } from '../Text'; |
|
|
|
|
|
|
|
|
|
|
|
type PreviewOptionalProps = { |
|
|
|
type PreviewOptionalProps = { |
|
|
|
externalPreview?: string; |
|
|
|
externalPreview?: string; |
|
|
|
isFetchScreenshot?: boolean; |
|
|
|
isExternalPreviewStale?: boolean; |
|
|
|
|
|
|
|
isFetchPreview?: boolean; |
|
|
|
isShowControls?: boolean; |
|
|
|
isShowControls?: boolean; |
|
|
|
isUseInnerPanel?: boolean; |
|
|
|
isUseInnerPanel?: boolean; |
|
|
|
setMode?: Dispatch<SetStateAction<boolean>> | null; |
|
|
|
setMode?: Dispatch<SetStateAction<boolean>> | null; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
type PreviewProps = PreviewOptionalProps & { |
|
|
|
type PreviewProps = PreviewOptionalProps & { |
|
|
|
uuid: string; |
|
|
|
|
|
|
|
serverName: string | string[] | undefined; |
|
|
|
serverName: string | string[] | undefined; |
|
|
|
|
|
|
|
serverUUID: string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const PREVIEW_DEFAULT_PROPS: Required<PreviewOptionalProps> = { |
|
|
|
const PREVIEW_DEFAULT_PROPS: Required<PreviewOptionalProps> = { |
|
|
|
externalPreview: '', |
|
|
|
externalPreview: '', |
|
|
|
isFetchScreenshot: true, |
|
|
|
isExternalPreviewStale: false, |
|
|
|
|
|
|
|
isFetchPreview: true, |
|
|
|
isShowControls: true, |
|
|
|
isShowControls: true, |
|
|
|
isUseInnerPanel: false, |
|
|
|
isUseInnerPanel: false, |
|
|
|
setMode: null, |
|
|
|
setMode: null, |
|
|
@ -62,36 +64,43 @@ const PreviewPanelHeader: FC<{ isUseInnerPanel: boolean; text: string }> = ({ |
|
|
|
|
|
|
|
|
|
|
|
const Preview: FC<PreviewProps> = ({ |
|
|
|
const Preview: FC<PreviewProps> = ({ |
|
|
|
externalPreview = PREVIEW_DEFAULT_PROPS.externalPreview, |
|
|
|
externalPreview = PREVIEW_DEFAULT_PROPS.externalPreview, |
|
|
|
isFetchScreenshot = PREVIEW_DEFAULT_PROPS.isFetchScreenshot, |
|
|
|
isExternalPreviewStale = PREVIEW_DEFAULT_PROPS.isExternalPreviewStale, |
|
|
|
|
|
|
|
isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, |
|
|
|
isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls, |
|
|
|
isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls, |
|
|
|
isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, |
|
|
|
isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, |
|
|
|
serverName, |
|
|
|
serverName, |
|
|
|
|
|
|
|
serverUUID, |
|
|
|
setMode, |
|
|
|
setMode, |
|
|
|
uuid, |
|
|
|
|
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
|
|
|
|
const [isPreviewStale, setIsPreviewStale] = useState<boolean>(false); |
|
|
|
const [preview, setPreview] = useState<string>(''); |
|
|
|
const [preview, setPreview] = useState<string>(''); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (isFetchScreenshot) { |
|
|
|
if (isFetchPreview) { |
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch(`${API_BASE_URL}/server/${uuid}?ss`, { |
|
|
|
const response = await fetch( |
|
|
|
method: 'GET', |
|
|
|
`${API_BASE_URL}/server/${serverUUID}?ss`, |
|
|
|
headers: { |
|
|
|
{ |
|
|
|
'Content-Type': 'application/json', |
|
|
|
method: 'GET', |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
); |
|
|
|
const { screenshot: fetchedScreenshot } = await response.json(); |
|
|
|
const { screenshot: fetchedScreenshot } = await response.json(); |
|
|
|
|
|
|
|
|
|
|
|
setPreview(fetchedScreenshot); |
|
|
|
setPreview(fetchedScreenshot); |
|
|
|
|
|
|
|
setIsPreviewStale(false); |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
setPreview(''); |
|
|
|
setIsPreviewStale(true); |
|
|
|
} |
|
|
|
} |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
} else if (externalPreview) { |
|
|
|
} else if (externalPreview) { |
|
|
|
setPreview(externalPreview); |
|
|
|
setPreview(externalPreview); |
|
|
|
|
|
|
|
setIsPreviewStale(isExternalPreviewStale); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [externalPreview, isFetchScreenshot, uuid]); |
|
|
|
}, [externalPreview, isExternalPreviewStale, isFetchPreview, serverUUID]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<PreviewPanel isUseInnerPanel={isUseInnerPanel}> |
|
|
|
<PreviewPanel isUseInnerPanel={isUseInnerPanel}> |
|
|
@ -126,6 +135,7 @@ const Preview: FC<PreviewProps> = ({ |
|
|
|
src={`data:image/png;base64,${preview}`} |
|
|
|
src={`data:image/png;base64,${preview}`} |
|
|
|
sx={{ |
|
|
|
sx={{ |
|
|
|
height: '100%', |
|
|
|
height: '100%', |
|
|
|
|
|
|
|
opacity: isPreviewStale ? '0.4' : '1', |
|
|
|
width: '100%', |
|
|
|
width: '100%', |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|