From 89549cd317f68717ae19f2892c4513a4e4d57346 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 22 Jun 2022 17:14:21 -0400 Subject: [PATCH] fix(striker-ui): visually differentiate between fresh and stale server screenshots --- striker-ui/components/Display/Preview.tsx | 36 +++++++++++++++-------- striker-ui/pages/index.tsx | 26 +++++++++------- striker-ui/pages/server/index.tsx | 2 +- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/striker-ui/components/Display/Preview.tsx b/striker-ui/components/Display/Preview.tsx index 4afef796..25c3b59a 100644 --- a/striker-ui/components/Display/Preview.tsx +++ b/striker-ui/components/Display/Preview.tsx @@ -14,20 +14,22 @@ import { BodyText, HeaderText } from '../Text'; type PreviewOptionalProps = { externalPreview?: string; - isFetchScreenshot?: boolean; + isExternalPreviewStale?: boolean; + isFetchPreview?: boolean; isShowControls?: boolean; isUseInnerPanel?: boolean; setMode?: Dispatch> | null; }; type PreviewProps = PreviewOptionalProps & { - uuid: string; serverName: string | string[] | undefined; + serverUUID: string; }; const PREVIEW_DEFAULT_PROPS: Required = { externalPreview: '', - isFetchScreenshot: true, + isExternalPreviewStale: false, + isFetchPreview: true, isShowControls: true, isUseInnerPanel: false, setMode: null, @@ -62,36 +64,43 @@ const PreviewPanelHeader: FC<{ isUseInnerPanel: boolean; text: string }> = ({ const Preview: FC = ({ 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, isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, serverName, + serverUUID, setMode, - uuid, }) => { + const [isPreviewStale, setIsPreviewStale] = useState(false); const [preview, setPreview] = useState(''); useEffect(() => { - if (isFetchScreenshot) { + if (isFetchPreview) { (async () => { try { - const response = await fetch(`${API_BASE_URL}/server/${uuid}?ss`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', + const response = await fetch( + `${API_BASE_URL}/server/${serverUUID}?ss`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, }, - }); + ); const { screenshot: fetchedScreenshot } = await response.json(); setPreview(fetchedScreenshot); + setIsPreviewStale(false); } catch { - setPreview(''); + setIsPreviewStale(true); } })(); } else if (externalPreview) { setPreview(externalPreview); + setIsPreviewStale(isExternalPreviewStale); } - }, [externalPreview, isFetchScreenshot, uuid]); + }, [externalPreview, isExternalPreviewStale, isFetchPreview, serverUUID]); return ( @@ -126,6 +135,7 @@ const Preview: FC = ({ src={`data:image/png;base64,${preview}`} sx={{ height: '100%', + opacity: isPreviewStale ? '0.4' : '1', width: '100%', }} /> diff --git a/striker-ui/pages/index.tsx b/striker-ui/pages/index.tsx index 103439b7..a298f880 100644 --- a/striker-ui/pages/index.tsx +++ b/striker-ui/pages/index.tsx @@ -34,17 +34,20 @@ const createServerPreviewContainer = (servers: ServerListItem[]) => ( }, }} > - {servers.map(({ screenshot, serverName, serverUUID }) => ( - - ))} + {servers.map( + ({ isScreenshotStale, screenshot, serverName, serverUUID }) => ( + + ), + )} ); @@ -109,6 +112,7 @@ const Dashboard: FC = () => { ) .then(({ screenshot }) => { item.screenshot = screenshot; + item.isScreenshotStale = false; const allServersWithScreenshots = [...serverListItems]; diff --git a/striker-ui/pages/server/index.tsx b/striker-ui/pages/server/index.tsx index 6d2bee1f..d2d2dfc9 100644 --- a/striker-ui/pages/server/index.tsx +++ b/striker-ui/pages/server/index.tsx @@ -48,8 +48,8 @@ const Server = (): JSX.Element => { ) : (