added os icons

This commit is contained in:
CodeServer 2022-04-12 03:54:09 +01:00
parent e566be9c67
commit b4495c59c0
12 changed files with 209 additions and 51 deletions

15
package-lock.json generated
View File

@ -15,6 +15,7 @@
"axios": "^0.26.1", "axios": "^0.26.1",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-icons": "^4.3.1",
"react-router-dom": "^6.2.1" "react-router-dom": "^6.2.1"
}, },
"devDependencies": { "devDependencies": {
@ -10224,6 +10225,14 @@
"react": "17.0.2" "react": "17.0.2"
} }
}, },
"node_modules/react-icons": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.3.1.tgz",
"integrity": "sha512-cB10MXLTs3gVuXimblAdI71jrJx8njrJZmNMEMC+sQu5B/BIOmlsAjskdqpn81y8UBVEGuHODd7/ci5DvoSzTQ==",
"peerDependencies": {
"react": "*"
}
},
"node_modules/react-is": { "node_modules/react-is": {
"version": "17.0.2", "version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
@ -20040,6 +20049,12 @@
"scheduler": "^0.20.2" "scheduler": "^0.20.2"
} }
}, },
"react-icons": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.3.1.tgz",
"integrity": "sha512-cB10MXLTs3gVuXimblAdI71jrJx8njrJZmNMEMC+sQu5B/BIOmlsAjskdqpn81y8UBVEGuHODd7/ci5DvoSzTQ==",
"requires": {}
},
"react-is": { "react-is": {
"version": "17.0.2", "version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",

View File

@ -15,6 +15,7 @@
"axios": "^0.26.1", "axios": "^0.26.1",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-icons": "^4.3.1",
"react-router-dom": "^6.2.1" "react-router-dom": "^6.2.1"
}, },
"scripts": { "scripts": {

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -0,0 +1,9 @@
import React from "react";
const Loading: React.FC = () => {
return(
<h1>Loading!</h1>
);
};
export default Loading;

View File

@ -13,7 +13,7 @@ import { getHostNameFromURL } from "../../utils";
const NavBar: React.FC = () => { const NavBar: React.FC = () => {
const { auth } = useAuth(); const { auth } = useAuth();
const { setRepositories } = useRepositories(); const { setIsFetched, setRepositories } = useRepositories();
const [anchorElUser, setAnchorElUser] = React.useState<(EventTarget & HTMLButtonElement) | null>(null); const [anchorElUser, setAnchorElUser] = React.useState<(EventTarget & HTMLButtonElement) | null>(null);
const [snackbarOpen, setSnackbarOpen] = React.useState(false); const [snackbarOpen, setSnackbarOpen] = React.useState(false);
@ -110,6 +110,11 @@ const NavBar: React.FC = () => {
tags.push(tag); tags.push(tag);
}); });
repository.tags = tags; repository.tags = tags;
}).catch((err) => {
const index = newRepositories.indexOf(repository);
if (index > -1) {
newRepositories.splice(index, 1);
}
}); });
promises.push(promise); promises.push(promise);
}); });
@ -140,6 +145,7 @@ const NavBar: React.FC = () => {
await getTags(newRepositories, auth) await getTags(newRepositories, auth)
setRepositories(newRepositories); setRepositories(newRepositories);
setIsFetched(true);
// setRepositories(newRepositories); // setRepositories(newRepositories);
}; };

View File

@ -0,0 +1,13 @@
import React from "react";
interface Props {
repositoryName: string;
}
const NotFound: React.FC<Props> = (props: Props) => {
return(
<h1>Repository "{props.repositoryName}" Not Found!</h1>
);
};
export default NotFound;

View File

@ -1,17 +1,19 @@
import React from "react"; import React from "react";
import { useLocation } from "react-router-dom"; import { useLocation, Link } from "react-router-dom";
import { ListItemButton, Button, Box, Card, CardContent, Typography, CardActions, Grid, ListItemText, Snackbar, Alert } from "@mui/material"; import { ListItemButton, Button, Box, Card, CardContent, Typography, CardActions, Grid, List, ListItemText, Snackbar, Alert } from "@mui/material";
import AccessTimeIcon from '@mui/icons-material/AccessTime'; import AccessTimeIcon from '@mui/icons-material/AccessTime';
import useRepositories from "../../hooks/useRepositories"; import useRepositories from "../../hooks/useRepositories";
import Tag from "../../interfaces/Tag"; import Tag from "../../interfaces/Tag";
import Repository from "../../interfaces/Repositoriy"; import Repository from "../../interfaces/Repositoriy";
import { getHostNameFromURL, printSize, printTimePassed } from "../../utils"; import { getHostNameFromURL, printSize, printTimePassed, PrintOSIcon } from "../../utils";
import NotFound from "../NotFound"; import RepoNotFound from "./RepoNotFound"
import Loading from "../Loading";
const RepositoryInfo: React.FC = () => { const RepositoryInfo: React.FC = () => {
const location = useLocation(); const location = useLocation();
const path = location.pathname; const path = location.pathname;
const { repositories } = useRepositories(); const { isFetched, repositories } = useRepositories();
const [hideTags, setHideTags] = React.useState(true);
const [snackbarOpen, setSnackbarOpen] = React.useState(false); const [snackbarOpen, setSnackbarOpen] = React.useState(false);
const repository = repositories.find((element) => (element.name === path.slice(12,path.length))); const repository = repositories.find((element) => (element.name === path.slice(12,path.length)));
@ -29,53 +31,127 @@ const RepositoryInfo: React.FC = () => {
setSnackbarOpen(false); setSnackbarOpen(false);
}; };
return (repository ? ( const toggleHide = () => {
<div className="repositoryInfo"> setHideTags(!hideTags);
<Card className="repositoryDetail" variant="outlined"> }
<CardContent>
{/* <Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom> return (isFetched ? (
Word of the Day repository ? (
</Typography> */} <div className="repositoryInfo">
<Typography className="lines" variant="h5" component="div"> <Card className="repositoryDetail" variant="outlined">
{repository.name} <CardContent>
</Typography> {/* <Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
<Typography className="lines" sx={{ mb: 1.5 }} color="text.secondary"> Word of the Day
<AccessTimeIcon className="clock-icon" /> </Typography> */}
{"Last updated: " + repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.created ? printTimePassed(tag.created) : "")).join(" ")} <Grid container>
</Typography> <Grid item lg={6} sm={12}>
<Typography className="lines" variant="h6"> <Typography className="lines" variant="h5" component="div">
Docker commands {repository.name}
</Typography> </Typography>
<Typography className="lines" variant="body2"> <Typography className="lines" sx={{ mb: 1.5 }} color="text.secondary">
To push a new tag to this repository, <AccessTimeIcon className="clock-icon" />
</Typography> {"Last updated: " + repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.created ? printTimePassed(tag.created) : "")).join(" ")}
<Box className="commandDisplay" onClick={handleClick} component="span" sx={{ display: 'block', bgcolor: '#445d6e', color: 'white', borderColor: '#445d6e' }}>{generatePushCommand(getHostNameFromURL(process.env.REGISTRY_URL ? process.env.REGISTRY_URL : ""))}</Box> </Typography>
</CardContent> </Grid>
{/* <CardActions> <Grid item lg={6} sm={12}>
<Button size="small">Learn More</Button> <Box sx={{ display: "flex", flexDirection: "column" }}>
</CardActions> */} <Typography className="lines" variant="h6">
Docker commands
</Typography>
<Typography className="lines" variant="body2">
To push a new tag to this repository,
</Typography>
<Box className="commandDisplay" onClick={handleClick} component="span" sx={{ display: 'block', bgcolor: '#445d6e', color: 'white', borderColor: '#445d6e' }}>{generatePushCommand(getHostNameFromURL(process.env.REGISTRY_URL ? process.env.REGISTRY_URL : ""))}</Box>
</Box>
</Grid>
</Grid>
</CardContent>
{/* <CardActions>
<Button size="small">Learn More</Button>
</CardActions> */}
</Card>
<Card className="tagsDetail" variant="outlined">
<CardContent>
<Typography className="lines" variant="h6">
Tags
</Typography>
<Typography className="lines" variant="body2">
{"This repository contains " + repository.tags.length + " tag" + (repository.tags.length > 1 ? "s" : "") + "."}
</Typography>
<List>
<Grid container>
<Grid item sm={5}>
<ListItemText primary="TAG" />
</Grid>
<Grid item sm={3}>
<ListItemText primary="OS" />
</Grid>
<Grid item sm={2}>
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary="SIZE" />
</Grid>
<Grid item sm={2}>
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary="CREATED" />
</Grid>
</Grid>
{repository.tags.sort((a,b) => {
let result = (b.created ? b.created.getTime() : 0) - (a.created ? a.created.getTime() : 0);
if (result === 0) {
if (b.label === "latest") {
return 1;
} else if (a.label === "latest") {
return -1;
} else {
return 0;
}
} else {
return result;
}
}).slice(0,((hideTags && repository.tags.length > 4) ? 3 : repository.tags.length)).map((tag) => (
<Grid container>
<Grid item sm={5}>
<ListItemText primary={tag.label} />
</Grid>
<Grid item sm={3}>
<ListItemText primary={<PrintOSIcon os={tag.os} />} />
</Grid>
<Grid item sm={2}>
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary={tag.size ? printSize(tag.size) : "---"} />
</Grid>
<Grid item sm={2}>
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary={tag.created ? printTimePassed(tag.created) : "---"} />
</Grid>
</Grid>
))}
{repository.tags.length > 4 ? (
<Grid container>
<Grid item sm={5}>
<ListItemText
className="moreBtn"
onClick={toggleHide}
primary={hideTags ? "more" : "less"}
/>
</Grid>
</Grid>
) : (
<></>
)}
</List>
</CardContent>
<CardActions>
<Button size="small">Details</Button>
</CardActions>
</Card>
<Snackbar open={snackbarOpen} autoHideDuration={6000} onClose={handleClose}> <Snackbar open={snackbarOpen} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}> <Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
Copied! Copied!
</Alert> </Alert>
</Snackbar> </Snackbar>
</Card> </div>
<Card className="tagsDetail" variant="outlined"> ) : (
<CardContent> <RepoNotFound repositoryName={path.slice(12,path.length)} />
<Typography className="lines" variant="h6"> )
Tags
</Typography>
<Typography className="lines" variant="body2">
{"This repository contains " + repository.tags.length + " tag" + (repository.tags.length > 1 ? "s" : "") + "."}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Details</Button>
</CardActions>
</Card>
</div>
) : ( ) : (
<NotFound /> <Loading />
)); ));
} }

View File

@ -3,19 +3,24 @@ import Repository from "../interfaces/Repositoriy";
interface MyRepositoriesState { interface MyRepositoriesState {
isFetched: boolean;
setIsFetched: React.Dispatch<React.SetStateAction<boolean>>
repositories: Repository[]; repositories: Repository[];
setRepositories: React.Dispatch<React.SetStateAction<Repository[]>> setRepositories: React.Dispatch<React.SetStateAction<Repository[]>>
} }
const RepositoriesContext = createContext<MyRepositoriesState>({ const RepositoriesContext = createContext<MyRepositoriesState>({
isFetched: false,
setIsFetched: () => {},
repositories: [], repositories: [],
setRepositories: () => {} setRepositories: () => {}
}); });
export const RepositoriesProvider = ({ children }: { children: React.ReactNode }) => { export const RepositoriesProvider = ({ children }: { children: React.ReactNode }) => {
const [isFetched, setIsFetched] = useState<boolean>(false);
const [repositories, setRepositories] = useState<Repository[]>([]); const [repositories, setRepositories] = useState<Repository[]>([]);
return <RepositoriesContext.Provider value={{repositories, setRepositories}}>{children}</RepositoriesContext.Provider>; return <RepositoriesContext.Provider value={{isFetched, setIsFetched, repositories, setRepositories}}>{children}</RepositoriesContext.Provider>;
}; };
export default RepositoriesContext; export default RepositoriesContext;

View File

@ -1,4 +1,6 @@
.repositoryInfo .repositoryInfo
max-width: 70%
margin: auto
.repositoryDetail .repositoryDetail
margin: 5% margin: 5%
padding: 15px padding: 15px
@ -17,3 +19,8 @@
padding: 15px padding: 15px
.lines .lines
margin-bottom: 10px margin-bottom: 10px
.moreBtn
color: #1976d2
cursor: pointer
.moreBtn:focus
color: purple

View File

@ -24,6 +24,11 @@ a {
margin: auto; margin: auto;
} }
.repositoryInfo {
max-width: 70%;
margin: auto;
}
.repositoryInfo .repositoryDetail { .repositoryInfo .repositoryDetail {
margin: 5%; margin: 5%;
padding: 15px; padding: 15px;
@ -54,6 +59,15 @@ a {
margin-bottom: 10px; margin-bottom: 10px;
} }
.repositoryInfo .tagsDetail .moreBtn {
color: #1976d2;
cursor: pointer;
}
.repositoryInfo .tagsDetail .moreBtn:focus {
color: purple;
}
.login .grid-container { .login .grid-container {
-webkit-box-align: center; -webkit-box-align: center;
-ms-flex-align: center; -ms-flex-align: center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AAC;EACZ,MAAM,EAAE,IAAI;EACZ,gBAAgB,EAAE,OAAO;CAAG;;ACpBxC,AAAA,QAAQ,CAAC;EACL,SAAS,EAAE,GAAG;EACd,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,GAAG;CAEU;;AAL7B,AAII,QAJI,CAIJ,eAAe,CAAC;EACZ,UAAU,EAAE,IAAI;CAAG",
"sources": [ "sources": [
"style.sass", "style.sass",
"_variables.sass", "_variables.sass",

View File

@ -1,4 +1,6 @@
import axios from "./api/axios" import axios from "./api/axios"
import { FcLinux } from "react-icons/fc";
import { FaWindows } from "react-icons/fa";
const checkValidURL = async (url: string) => { const checkValidURL = async (url: string) => {
try { try {
@ -54,4 +56,14 @@ const printSize = (sizeInByte: number): string => {
} }
}; };
export { checkValidURL, printTwoDecimalPlaces, printTimePassed, printSize, getHostNameFromURL }; const PrintOSIcon: React.FC<{ os: string }> = ({ os }) => {
if (os === "linux") {
return <FcLinux />
} else if (os === "windows") {
return <FaWindows />
} else {
return <div>os</div>;
}
}
export { checkValidURL, printTwoDecimalPlaces, printTimePassed, printSize, getHostNameFromURL, PrintOSIcon };