Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#1216 from CannonLock/cached-user-1149
Browse files Browse the repository at this point in the history
Upgrade the director login
  • Loading branch information
haoming29 authored May 3, 2024
2 parents e11883f + 21b141d commit 81427ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
17 changes: 4 additions & 13 deletions web_ui/frontend/app/director/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import useSWR from "swr";
import {Server} from "@/components/Main";
import CardList from "@/components/Namespace/CardList";
import DirectorCard, {DirectorCardProps} from "@/components/Namespace/DirectorCard";
import {Authenticated, getAuthenticated, isLoggedIn} from "@/helpers/login";
import {getUser} from "@/helpers/login";


const getServers = async () => {
Expand All @@ -43,18 +43,9 @@ const getServers = async () => {

export default function Home() {

const [error, setError] = useState<string | undefined>(undefined);
const [authenticated, setAuthenticated] = useState<Authenticated | undefined>(undefined)

const {data} = useSWR<Server[]>("getServers", getServers)

useEffect(() => {
(async () => {
if(await isLoggedIn()){
setAuthenticated(getAuthenticated() as Authenticated)
}
})();
}, [])
const {data: user, error} = useSWR("getUser", getUser)

const cacheData = useMemo(() => {
return data?.filter((server) => server.type === "Cache")
Expand All @@ -70,7 +61,7 @@ export default function Home() {
<Grid item xs={12} lg={8} xl={6}>
<Typography variant={"h4"} pb={2}>Origins</Typography>
{originData ?
<CardList<DirectorCardProps> Card={DirectorCard} cardProps={{authenticated: authenticated}} data={originData.map(x => {return {server: x}})}/> :
<CardList<DirectorCardProps> Card={DirectorCard} cardProps={{authenticated: user}} data={originData.map(x => {return {server: x}})}/> :
<Box>
<Skeleton variant="rectangular" height={118} />
</Box>
Expand All @@ -79,7 +70,7 @@ export default function Home() {
<Grid item xs={12} lg={8} xl={6}>
<Typography variant={"h4"} pb={2}>Caches</Typography>
{cacheData ?
<CardList<DirectorCardProps> Card={DirectorCard} cardProps={{authenticated: authenticated}} data={cacheData.map(x => {return {server: x}})}/> :
<CardList<DirectorCardProps> Card={DirectorCard} cardProps={{authenticated: user}} data={cacheData.map(x => {return {server: x}})}/> :
<Box>
<Skeleton variant="rectangular" height={118} />
</Box>
Expand Down
2 changes: 1 addition & 1 deletion web_ui/frontend/components/Namespace/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function CardList<T>({ data, Card, cardProps }: CardListProps<T>) {
...o
} as T

return <Box pb={1} key={JSON.stringify(o)}>
return <Box pb={1} key={JSON.stringify(props)}>
<Card {...props} />
</Box>
})}
Expand Down
3 changes: 2 additions & 1 deletion web_ui/frontend/components/Namespace/DirectorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {Language} from "@mui/icons-material";
import {NamespaceIcon} from "@/components/Namespace/index";
import useSWR from "swr";
import Link from "next/link";
import {User} from "@/index";

export interface DirectorCardProps {
server: Server
authenticated?: Authenticated
authenticated?: User
}

export const DirectorCard = ({ server, authenticated } : DirectorCardProps) => {
Expand Down

0 comments on commit 81427ca

Please sign in to comment.