implemented RepositoriesProvider
This commit is contained in:
parent
9a49b30cd1
commit
0495bfd295
@ -3,6 +3,7 @@ import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
|||||||
import CheckENVRoute from "./CheckENVRoute";
|
import CheckENVRoute from "./CheckENVRoute";
|
||||||
import Home from "./components/home/Home";
|
import Home from "./components/home/Home";
|
||||||
import Login from "./components/Login";
|
import Login from "./components/Login";
|
||||||
|
import RepositoryInfo from "./components/repositoryInfo/RepositoryInfo";
|
||||||
import ProtectedRoute from "./ProtectedRoute";
|
import ProtectedRoute from "./ProtectedRoute";
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
@ -13,6 +14,7 @@ const App: React.FC = () => {
|
|||||||
<Route path="/login" element={<Login />} />
|
<Route path="/login" element={<Login />} />
|
||||||
<Route element={<ProtectedRoute />}>
|
<Route element={<ProtectedRoute />}>
|
||||||
<Route path="/" element={<Home />} />
|
<Route path="/" element={<Home />} />
|
||||||
|
<Route path="/repository/*" element={<RepositoryInfo />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@ -3,9 +3,10 @@ import NavBar from "./components/navbar/NavBar";
|
|||||||
import useAuth from "./hooks/useAuth";
|
import useAuth from "./hooks/useAuth";
|
||||||
|
|
||||||
const ProtectedRoute = () => {
|
const ProtectedRoute = () => {
|
||||||
const auth = useAuth();
|
const { auth } = useAuth();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
|
||||||
return ((auth.loginNeeded !== undefined && !auth.loginNeeded) || auth?.isLoggedIn) ? (
|
return ((auth.loginNeeded !== undefined && !auth.loginNeeded) || auth?.isLoggedIn) ? (
|
||||||
<>
|
<>
|
||||||
<NavBar />
|
<NavBar />
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { InputLabel, Stack, Typography } from "@mui/material";
|
import { InputLabel, Stack } from "@mui/material";
|
||||||
import Container from "@mui/material/Container";
|
import Container from "@mui/material/Container";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
@ -12,7 +12,7 @@ interface LocationState {
|
|||||||
from: { pathname: string };
|
from: { pathname: string };
|
||||||
}
|
}
|
||||||
const Login: React.FC = () => {
|
const Login: React.FC = () => {
|
||||||
const setAuth = useAuth();
|
const { setAuth } = useAuth();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@ -24,8 +24,12 @@ const Login: React.FC = () => {
|
|||||||
const [hasError, setHasError] = useState(false);
|
const [hasError, setHasError] = useState(false);
|
||||||
|
|
||||||
const handleSkipLogin = () => {
|
const handleSkipLogin = () => {
|
||||||
setAuth["loginNeeded"] = false;
|
setAuth({
|
||||||
setAuth["isLoggedIn"] = false;
|
loginNeeded: false,
|
||||||
|
isLoggedIn: false,
|
||||||
|
username: "",
|
||||||
|
password: ""
|
||||||
|
});
|
||||||
navigate(from, { replace: true });
|
navigate(from, { replace: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +59,15 @@ const Login: React.FC = () => {
|
|||||||
if (status === undefined) {
|
if (status === undefined) {
|
||||||
setHasError(true);
|
setHasError(true);
|
||||||
} else {
|
} else {
|
||||||
setAuth["loginNeeded"] = true
|
setAuth({
|
||||||
setAuth["isLoggedIn"] = true;
|
loginNeeded: true,
|
||||||
// setAuth["username"] = username;
|
isLoggedIn: true,
|
||||||
// setAuth["password"] = password;
|
// username: username,
|
||||||
setAuth["username"] = "pusher";
|
// password: password,
|
||||||
setAuth["password"] = "pusher";
|
username: "pusher",
|
||||||
|
password: "pusher"
|
||||||
|
});
|
||||||
|
|
||||||
setHasError(false);
|
setHasError(false);
|
||||||
navigate(from, { replace: true });
|
navigate(from, { replace: true });
|
||||||
console.log("logged in!");
|
console.log("logged in!");
|
||||||
|
|||||||
125
src/components/fetchRepositories.tsx
Normal file
125
src/components/fetchRepositories.tsx
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import axios from "../api/axios";
|
||||||
|
import useAuth from "../hooks/useAuth";
|
||||||
|
import useRepositories from "../hooks/useRepositories";
|
||||||
|
import { loginInfo } from "../context/AuthProvider";
|
||||||
|
import Tag from "../interfaces/Tag";
|
||||||
|
import Repository from "../interfaces/Repositoriy";
|
||||||
|
import Layer from "../interfaces/Layer";
|
||||||
|
|
||||||
|
// const [repositories, setRepositories] = useState<Repository[]>([]);
|
||||||
|
|
||||||
|
const getTagInfo = async(newRepositories: Repository[], auth: loginInfo) => {
|
||||||
|
let promises: Promise<void>[] = [];
|
||||||
|
newRepositories.forEach((repository: Repository) => {
|
||||||
|
repository.tags.forEach((tag: Tag) => {
|
||||||
|
let promise = axios.get(
|
||||||
|
"/" + repository.name + "/manifests/" + tag.label,
|
||||||
|
{
|
||||||
|
headers:{
|
||||||
|
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((response) => {
|
||||||
|
tag.schemaVersion = response?.data['schemaVersion'];
|
||||||
|
tag.mediaType = response?.data['mediaType'];
|
||||||
|
tag.digest = response?.headers['docker-content-digest'];
|
||||||
|
tag.config = response?.data?.config;
|
||||||
|
tag.layers = response?.data?.layers;
|
||||||
|
let size = 0;
|
||||||
|
response?.data?.layers.forEach((layer: Layer) => {
|
||||||
|
size += layer.size;
|
||||||
|
});
|
||||||
|
tag.size = size;
|
||||||
|
return axios.get(
|
||||||
|
"/" + repository.name + "/blobs/" + response?.data?.config['digest'],
|
||||||
|
{
|
||||||
|
headers:{
|
||||||
|
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((res) => {
|
||||||
|
tag.architecture = res?.data?.architecture;
|
||||||
|
tag.os = res?.data?.os;
|
||||||
|
tag.created = new Date(res?.data?.created);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
promises.push(promise);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return Promise.all(promises);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTags = async(newRepositories: Repository[], auth: loginInfo) => {
|
||||||
|
let promises: Promise<void>[] = [];
|
||||||
|
newRepositories.forEach((repository: Repository) => {
|
||||||
|
let promise = axios.get(
|
||||||
|
"/" + repository.name + "/tags/list",
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((res) => {
|
||||||
|
let tags: Tag[] = [];
|
||||||
|
res?.data?.tags.forEach((tagLabel: string) => {
|
||||||
|
let tag: Tag = {
|
||||||
|
label: tagLabel,
|
||||||
|
architecture: "",
|
||||||
|
os: "",
|
||||||
|
created: undefined,
|
||||||
|
schemaVersion: undefined,
|
||||||
|
mediaType: "",
|
||||||
|
config: undefined,
|
||||||
|
layers: undefined,
|
||||||
|
size: undefined,
|
||||||
|
digest: ""
|
||||||
|
}
|
||||||
|
tags.push(tag);
|
||||||
|
});
|
||||||
|
repository.tags = tags;
|
||||||
|
});
|
||||||
|
promises.push(promise);
|
||||||
|
});
|
||||||
|
await Promise.all(promises);
|
||||||
|
return getTagInfo(newRepositories, auth);
|
||||||
|
};
|
||||||
|
|
||||||
|
const listRepositories = async() => {
|
||||||
|
const { auth } = useAuth();
|
||||||
|
const { setRepositories } = useRepositories();
|
||||||
|
|
||||||
|
const response = await axios.get(
|
||||||
|
"/_catalog",
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let newRepositories: Repository[] = [];
|
||||||
|
response?.data?.repositories.forEach((repositoriyName: string) => {
|
||||||
|
let newRepository: Repository = {
|
||||||
|
name: repositoriyName,
|
||||||
|
tags: []
|
||||||
|
}
|
||||||
|
newRepositories.push(newRepository);
|
||||||
|
});
|
||||||
|
await getTags(newRepositories, auth)
|
||||||
|
|
||||||
|
setRepositories(newRepositories);
|
||||||
|
// setRepositories(newRepositories);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { listRepositories };
|
||||||
@ -1,132 +1,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { List } from "@mui/material";
|
import { List } from "@mui/material";
|
||||||
import RepositoryItem from "./RepositoryEntry";
|
import RepositoryItem from "./RepositoryEntry";
|
||||||
import axios from "../../api/axios";
|
import useRepositories from "../../hooks/useRepositories";
|
||||||
import useAuth from "../../hooks/useAuth";
|
|
||||||
import Tag from "../../interfaces/Tag";
|
|
||||||
import Repository from "../../interfaces/Repositoriy";
|
import Repository from "../../interfaces/Repositoriy";
|
||||||
import Layer from "../../interfaces/Layer";
|
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
const auth = useAuth();
|
const { repositories } = useRepositories();
|
||||||
|
|
||||||
const [repositories, setRepositories] = useState<Repository[]>([]);
|
|
||||||
|
|
||||||
auth['repositories'] = repositories;
|
|
||||||
const getTagInfo = async(newRepositories: Repository[]) => {
|
|
||||||
let promises: Promise<void>[] = [];
|
|
||||||
newRepositories.forEach((repository: Repository) => {
|
|
||||||
repository.tags.forEach((tag: Tag) => {
|
|
||||||
let promise = axios.get(
|
|
||||||
"/" + repository.name + "/manifests/" + tag.label,
|
|
||||||
{
|
|
||||||
headers:{
|
|
||||||
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
|
||||||
},
|
|
||||||
auth: {
|
|
||||||
username: auth.username,
|
|
||||||
password: auth.password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).then((response) => {
|
|
||||||
tag.schemaVersion = response?.data['schemaVersion'];
|
|
||||||
tag.mediaType = response?.data['mediaType'];
|
|
||||||
tag.digest = response?.headers['docker-content-digest'];
|
|
||||||
tag.config = response?.data?.config;
|
|
||||||
tag.layers = response?.data?.layers;
|
|
||||||
let size = 0;
|
|
||||||
response?.data?.layers.forEach((layer: Layer) => {
|
|
||||||
size += layer.size;
|
|
||||||
});
|
|
||||||
tag.size = size;
|
|
||||||
return axios.get(
|
|
||||||
"/" + repository.name + "/blobs/" + response?.data?.config['digest'],
|
|
||||||
{
|
|
||||||
headers:{
|
|
||||||
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
|
||||||
},
|
|
||||||
auth: {
|
|
||||||
username: auth.username,
|
|
||||||
password: auth.password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).then((res) => {
|
|
||||||
tag.architecture = res?.data?.architecture;
|
|
||||||
tag.os = res?.data?.os;
|
|
||||||
tag.created = new Date(res?.data?.created);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
promises.push(promise);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return Promise.all(promises);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTags = async(newRepositories: Repository[]) => {
|
|
||||||
let promises: Promise<void>[] = [];
|
|
||||||
newRepositories.forEach((repository: Repository) => {
|
|
||||||
let promise = axios.get(
|
|
||||||
"/" + repository.name + "/tags/list",
|
|
||||||
{
|
|
||||||
auth: {
|
|
||||||
username: auth.username,
|
|
||||||
password: auth.password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).then((res) => {
|
|
||||||
let tags: Tag[] = [];
|
|
||||||
res?.data?.tags.forEach((tagLabel: string) => {
|
|
||||||
let tag: Tag = {
|
|
||||||
label: tagLabel,
|
|
||||||
architecture: "",
|
|
||||||
os: "",
|
|
||||||
created: undefined,
|
|
||||||
schemaVersion: undefined,
|
|
||||||
mediaType: "",
|
|
||||||
config: undefined,
|
|
||||||
layers: undefined,
|
|
||||||
size: undefined,
|
|
||||||
digest: ""
|
|
||||||
}
|
|
||||||
tags.push(tag);
|
|
||||||
});
|
|
||||||
repository.tags = tags;
|
|
||||||
});
|
|
||||||
promises.push(promise);
|
|
||||||
});
|
|
||||||
await Promise.all(promises);
|
|
||||||
return getTagInfo(newRepositories);
|
|
||||||
};
|
|
||||||
|
|
||||||
const listRepositories = async() => {
|
|
||||||
|
|
||||||
const response = await axios.get(
|
|
||||||
"/_catalog",
|
|
||||||
{
|
|
||||||
auth: {
|
|
||||||
username: auth.username,
|
|
||||||
password: auth.password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let newRepositories: Repository[] = [];
|
|
||||||
response?.data?.repositories.forEach((repositoriyName: string) => {
|
|
||||||
let newRepository: Repository = {
|
|
||||||
name: repositoriyName,
|
|
||||||
tags: []
|
|
||||||
}
|
|
||||||
newRepositories.push(newRepository);
|
|
||||||
});
|
|
||||||
await getTags(newRepositories)
|
|
||||||
setRepositories(newRepositories);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setInterval(() => listRepositories(), 1000);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="sectionHome">
|
<div className="sectionHome">
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { ListItemButton, Box, Typography, Grid, ListItemText } from "@mui/material";
|
import { ListItemButton, Grid, ListItemText } from "@mui/material";
|
||||||
import Tag from "../../interfaces/Tag";
|
import Tag from "../../interfaces/Tag";
|
||||||
import Repository from "../../interfaces/Repositoriy";
|
import Repository from "../../interfaces/Repositoriy";
|
||||||
import { printSize, printTimePassed } from "../../utils";
|
import { printSize, printTimePassed } from "../../utils";
|
||||||
@ -18,12 +18,10 @@ const RepositoryItem: React.FC<Props> = (props: Props) => {
|
|||||||
</Box> */}
|
</Box> */}
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item sm={9}>
|
<Grid item sm={9}>
|
||||||
<ListItemText primary={props.repository.name} secondary={"Last updated: " + props.repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.created ? printTimePassed(tag.created) : "")).join(" ")} />
|
<ListItemText primary={props.repository.name} secondary={"Last updated: " + props.repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.created ? printTimePassed(tag.created) : "")).join(" ")} />
|
||||||
{/* <Typography color="black" variant="h5">{props.repository.name}</Typography>
|
|
||||||
<Typography color="grey" variant="h6">{"Last updated: " + props.repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.created ? printTimePassed(tag.created) : "")).join(" ")}</Typography> */}
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={3}>
|
<Grid item sm={3}>
|
||||||
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary={props.repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.size ? printSize(tag.size) : "")).join(" ")} />
|
<ListItemText style={{display:'flex', justifyContent:'flex-end'}} primary={props.repository.tags.filter((tag: Tag) => (tag.label === "latest")).map((tag: Tag) => (tag.size ? printSize(tag.size) : "")).join(" ")} />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
|
|||||||
@ -1,9 +1,17 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
import { AppBar, Container, Toolbar, Typography, Box, IconButton, Menu, MenuItem , Tooltip, Avatar, Snackbar, Alert} from "@mui/material";
|
import { AppBar, Container, Toolbar, Typography, Box, IconButton, Menu, MenuItem , Tooltip, Avatar, Snackbar, Alert} from "@mui/material";
|
||||||
|
import axios from "../../api/axios";
|
||||||
import useAuth from "../../hooks/useAuth";
|
import useAuth from "../../hooks/useAuth";
|
||||||
|
import useRepositories from "../../hooks/useRepositories";
|
||||||
|
import { loginInfo } from "../../context/AuthProvider";
|
||||||
|
import Tag from "../../interfaces/Tag";
|
||||||
|
import Repository from "../../interfaces/Repositoriy";
|
||||||
|
import Layer from "../../interfaces/Layer";
|
||||||
|
|
||||||
const NavBar: React.FC = () => {
|
const NavBar: React.FC = () => {
|
||||||
const auth = useAuth();
|
const { auth } = useAuth();
|
||||||
|
const { 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);
|
||||||
|
|
||||||
@ -21,6 +29,123 @@ const NavBar: React.FC = () => {
|
|||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setSnackbarOpen(false);
|
setSnackbarOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const getTagInfo = async(newRepositories: Repository[], auth: loginInfo) => {
|
||||||
|
let promises: Promise<void>[] = [];
|
||||||
|
newRepositories.forEach((repository: Repository) => {
|
||||||
|
repository.tags.forEach((tag: Tag) => {
|
||||||
|
let promise = axios.get(
|
||||||
|
"/" + repository.name + "/manifests/" + tag.label,
|
||||||
|
{
|
||||||
|
headers:{
|
||||||
|
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((response) => {
|
||||||
|
tag.schemaVersion = response?.data['schemaVersion'];
|
||||||
|
tag.mediaType = response?.data['mediaType'];
|
||||||
|
tag.digest = response?.headers['docker-content-digest'];
|
||||||
|
tag.config = response?.data?.config;
|
||||||
|
tag.layers = response?.data?.layers;
|
||||||
|
let size = 0;
|
||||||
|
response?.data?.layers.forEach((layer: Layer) => {
|
||||||
|
size += layer.size;
|
||||||
|
});
|
||||||
|
tag.size = size;
|
||||||
|
return axios.get(
|
||||||
|
"/" + repository.name + "/blobs/" + response?.data?.config['digest'],
|
||||||
|
{
|
||||||
|
headers:{
|
||||||
|
Accept: "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((res) => {
|
||||||
|
tag.architecture = res?.data?.architecture;
|
||||||
|
tag.os = res?.data?.os;
|
||||||
|
tag.created = new Date(res?.data?.created);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
promises.push(promise);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return Promise.all(promises);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTags = async(newRepositories: Repository[], auth: loginInfo) => {
|
||||||
|
let promises: Promise<void>[] = [];
|
||||||
|
newRepositories.forEach((repository: Repository) => {
|
||||||
|
let promise = axios.get(
|
||||||
|
"/" + repository.name + "/tags/list",
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then((res) => {
|
||||||
|
let tags: Tag[] = [];
|
||||||
|
res?.data?.tags.forEach((tagLabel: string) => {
|
||||||
|
let tag: Tag = {
|
||||||
|
label: tagLabel,
|
||||||
|
architecture: "",
|
||||||
|
os: "",
|
||||||
|
created: undefined,
|
||||||
|
schemaVersion: undefined,
|
||||||
|
mediaType: "",
|
||||||
|
config: undefined,
|
||||||
|
layers: undefined,
|
||||||
|
size: undefined,
|
||||||
|
digest: ""
|
||||||
|
}
|
||||||
|
tags.push(tag);
|
||||||
|
});
|
||||||
|
repository.tags = tags;
|
||||||
|
});
|
||||||
|
promises.push(promise);
|
||||||
|
});
|
||||||
|
await Promise.all(promises);
|
||||||
|
return getTagInfo(newRepositories, auth);
|
||||||
|
};
|
||||||
|
|
||||||
|
const listRepositories = async() => {
|
||||||
|
|
||||||
|
const response = await axios.get(
|
||||||
|
"/_catalog",
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: auth.username,
|
||||||
|
password: auth.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let newRepositories: Repository[] = [];
|
||||||
|
response?.data?.repositories.forEach((repositoriyName: string) => {
|
||||||
|
let newRepository: Repository = {
|
||||||
|
name: repositoriyName,
|
||||||
|
tags: []
|
||||||
|
}
|
||||||
|
newRepositories.push(newRepository);
|
||||||
|
});
|
||||||
|
await getTags(newRepositories, auth)
|
||||||
|
|
||||||
|
setRepositories(newRepositories);
|
||||||
|
// setRepositories(newRepositories);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInterval(() => listRepositories(), 1000);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppBar className="navbar" position="static">
|
<AppBar className="navbar" position="static">
|
||||||
|
|||||||
15
src/components/repositoryInfo/RepositoryInfo.tsx
Normal file
15
src/components/repositoryInfo/RepositoryInfo.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
import { ListItemButton, Box, Typography, Grid, ListItemText } from "@mui/material";
|
||||||
|
import Tag from "../../interfaces/Tag";
|
||||||
|
import Repository from "../../interfaces/Repositoriy";
|
||||||
|
|
||||||
|
const RepositoryInfo: React.FC = () => {
|
||||||
|
const location = useLocation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<h1>{location.pathname.slice(12,location.pathname.length)}</h1>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RepositoryInfo;
|
||||||
@ -1,26 +1,32 @@
|
|||||||
import { createContext, useState } from "react";
|
import { createContext, useState } from "react";
|
||||||
import Repository from "../interfaces/Repositoriy";
|
|
||||||
|
|
||||||
interface loginInfo {
|
export interface loginInfo {
|
||||||
loginNeeded: boolean;
|
loginNeeded: boolean;
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
repositories: Repository[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<loginInfo>({
|
interface MyAuthState {
|
||||||
loginNeeded: true,
|
auth: loginInfo;
|
||||||
isLoggedIn: false,
|
setAuth: React.Dispatch<React.SetStateAction<loginInfo>>
|
||||||
username: "",
|
}
|
||||||
password: "",
|
|
||||||
repositories: []
|
|
||||||
|
const AuthContext = createContext<MyAuthState>({
|
||||||
|
auth: {
|
||||||
|
loginNeeded: true,
|
||||||
|
isLoggedIn: false,
|
||||||
|
username: "",
|
||||||
|
password: ""
|
||||||
|
},
|
||||||
|
setAuth: () => {}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
const [auth] = useState<loginInfo>({ loginNeeded: true, isLoggedIn: false, username: "", password: "", repositories: [] });
|
const [auth, setAuth] = useState<loginInfo>({ loginNeeded: true, isLoggedIn: false, username: "", password: "" });
|
||||||
|
|
||||||
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
|
return <AuthContext.Provider value={{auth, setAuth}}>{children}</AuthContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AuthContext;
|
export default AuthContext;
|
||||||
|
|||||||
21
src/context/RepositoriesProvider.tsx
Normal file
21
src/context/RepositoriesProvider.tsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { createContext, useState } from "react";
|
||||||
|
import Repository from "../interfaces/Repositoriy";
|
||||||
|
|
||||||
|
|
||||||
|
interface MyRepositoriesState {
|
||||||
|
repositories: Repository[];
|
||||||
|
setRepositories: React.Dispatch<React.SetStateAction<Repository[]>>
|
||||||
|
}
|
||||||
|
|
||||||
|
const RepositoriesContext = createContext<MyRepositoriesState>({
|
||||||
|
repositories: [],
|
||||||
|
setRepositories: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const RepositoriesProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const [repositories, setRepositories] = useState<Repository[]>([]);
|
||||||
|
|
||||||
|
return <RepositoriesContext.Provider value={{repositories, setRepositories}}>{children}</RepositoriesContext.Provider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RepositoriesContext;
|
||||||
@ -1,17 +1,8 @@
|
|||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import AuthContext from "../context/AuthProvider";
|
import AuthContext from "../context/AuthProvider";
|
||||||
import Repository from "../interfaces/Repositoriy";
|
|
||||||
|
|
||||||
interface loginInfo {
|
|
||||||
loginNeeded: boolean;
|
|
||||||
isLoggedIn: boolean;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
repositories: Repository[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const useAuth = () => {
|
const useAuth = () => {
|
||||||
return useContext<loginInfo>(AuthContext);
|
return useContext(AuthContext);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useAuth;
|
export default useAuth;
|
||||||
8
src/hooks/useRepositories.tsx
Normal file
8
src/hooks/useRepositories.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { useContext } from "react";
|
||||||
|
import RepositoriesContext from "../context/RepositoriesProvider";
|
||||||
|
|
||||||
|
const useRepositories = () => {
|
||||||
|
return useContext(RepositoriesContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useRepositories;
|
||||||
@ -2,12 +2,15 @@ import ReactDOM from "react-dom";
|
|||||||
import App from "./App";
|
import App from "./App";
|
||||||
import "./style/style.css";
|
import "./style/style.css";
|
||||||
import { AuthProvider } from "./context/AuthProvider";
|
import { AuthProvider } from "./context/AuthProvider";
|
||||||
|
import { RepositoriesProvider } from "./context/RepositoriesProvider";
|
||||||
|
|
||||||
|
|
||||||
const Index: React.FC = () => {
|
const Index: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<App />
|
<RepositoriesProvider>
|
||||||
|
<App />
|
||||||
|
</RepositoriesProvider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user