Add ISO catalog
This commit is contained in:
75
virtweb_frontend/src/dialogs/IsoCatalogDialog.tsx
Normal file
75
virtweb_frontend/src/dialogs/IsoCatalogDialog.tsx
Normal file
@ -0,0 +1,75 @@
|
||||
import {
|
||||
Avatar,
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemAvatar,
|
||||
ListItemButton,
|
||||
ListItemText,
|
||||
} from "@mui/material";
|
||||
import React from "react";
|
||||
import { ISOCatalogEntry, IsoFilesApi } from "../api/IsoFilesApi";
|
||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||
|
||||
export function IsoCatalogDialog(p: {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}): React.ReactElement {
|
||||
const [catalog, setCatalog] = React.useState<ISOCatalogEntry[] | undefined>();
|
||||
|
||||
const load = async () => {
|
||||
setCatalog(await IsoFilesApi.Catalog());
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={p.open} onClose={p.onClose}>
|
||||
<DialogTitle>Iso catalog</DialogTitle>
|
||||
<DialogContent>
|
||||
<AsyncWidget
|
||||
loadKey={1}
|
||||
load={load}
|
||||
errMsg="Failed to load catalog"
|
||||
build={() => <IsoCatalogDialogInner catalog={catalog!} />}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button autoFocus onClick={p.onClose}>
|
||||
Close
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function IsoCatalogDialogInner(p: {
|
||||
catalog: ISOCatalogEntry[];
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<List dense>
|
||||
{p.catalog.map((entry) => (
|
||||
<a
|
||||
href={entry.url}
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
style={{ color: "inherit", textDecoration: "none" }}
|
||||
>
|
||||
<ListItem key={entry.name}>
|
||||
<ListItemButton>
|
||||
<ListItemAvatar>
|
||||
<img
|
||||
src={IsoFilesApi.CatalogImageURL(entry)}
|
||||
style={{ width: "2em" }}
|
||||
/>
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary={entry.name} />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
</a>
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user