fix(striker-ui): visually differentiate between fresh and stale server screenshots

main
Tsu-ba-me 3 years ago
parent 1d39e4d918
commit 89549cd317
  1. 36
      striker-ui/components/Display/Preview.tsx
  2. 26
      striker-ui/pages/index.tsx
  3. 2
      striker-ui/pages/server/index.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<SetStateAction<boolean>> | null;
};
type PreviewProps = PreviewOptionalProps & {
uuid: string;
serverName: string | string[] | undefined;
serverUUID: string;
};
const PREVIEW_DEFAULT_PROPS: Required<PreviewOptionalProps> = {
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<PreviewProps> = ({
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<boolean>(false);
const [preview, setPreview] = useState<string>('');
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 (
<PreviewPanel isUseInnerPanel={isUseInnerPanel}>
@ -126,6 +135,7 @@ const Preview: FC<PreviewProps> = ({
src={`data:image/png;base64,${preview}`}
sx={{
height: '100%',
opacity: isPreviewStale ? '0.4' : '1',
width: '100%',
}}
/>

@ -34,17 +34,20 @@ const createServerPreviewContainer = (servers: ServerListItem[]) => (
},
}}
>
{servers.map(({ screenshot, serverName, serverUUID }) => (
<Preview
key={`server-preview-${serverUUID}`}
isFetchScreenshot={false}
isShowControls={false}
isUseInnerPanel
externalPreview={screenshot}
serverName={serverName}
uuid={serverUUID}
/>
))}
{servers.map(
({ isScreenshotStale, screenshot, serverName, serverUUID }) => (
<Preview
key={`server-preview-${serverUUID}`}
isExternalPreviewStale={isScreenshotStale}
isFetchPreview={false}
isShowControls={false}
isUseInnerPanel
externalPreview={screenshot}
serverName={serverName}
serverUUID={serverUUID}
/>
),
)}
</Box>
);
@ -109,6 +112,7 @@ const Dashboard: FC = () => {
)
.then(({ screenshot }) => {
item.screenshot = screenshot;
item.isScreenshotStale = false;
const allServersWithScreenshots = [...serverListItems];

@ -48,8 +48,8 @@ const Server = (): JSX.Element => {
<Box className={classes.preview}>
<Preview
setMode={setPreviewMode}
uuid={uuid}
serverName={server_name}
serverUUID={uuid}
/>
</Box>
) : (

Loading…
Cancel
Save