From 266403f7da753f85f469f42fcc6dc6153a095a84 Mon Sep 17 00:00:00 2001 From: Gabriel Pelouze Date: Thu, 14 Sep 2023 13:50:50 +0200 Subject: [PATCH 01/10] cleanup and reformat index --- vre-panel/pages/index.tsx | 144 ++++++++++++++------------------------ 1 file changed, 54 insertions(+), 90 deletions(-) diff --git a/vre-panel/pages/index.tsx b/vre-panel/pages/index.tsx index f29f40e..15b942d 100644 --- a/vre-panel/pages/index.tsx +++ b/vre-panel/pages/index.tsx @@ -1,106 +1,70 @@ -import { getToken } from 'next-auth/jwt'; -// import { signIn, useSession } from 'next-auth/react'; +import {useEffect, useState} from 'react'; import getConfig from 'next/config'; import Link from 'next/link'; -import { useEffect, useState } from 'react'; -import { NewVREDialog } from '../components/NewVREDialog'; -import { Nav } from '../templates/Nav'; -// import useAuth from './auth/useAuth'; + +import {NewVREDialog} from '../components/NewVREDialog'; +import {Nav} from '../templates/Nav'; const getSlug = (title: string) => { - return title - .toLowerCase() - .replace(/ /g, '-') - .replace(/[^\w-]+/g, ''); + return title + .toLowerCase() + .replace(/ /g, '-') + .replace(/[^\w-]+/g, ''); } const VLabs = () => { - const { publicRuntimeConfig } = getConfig() - - // const isAuthenticated = useAuth(true); - const [isOpen, setIsOpen] = useState(false); - const [vlabs, setVlabs] = useState([]); - - useEffect(() => { - - // if (isAuthenticated) { + const {publicRuntimeConfig} = getConfig() - // var requestOptions: RequestInit = { - // method: "GET", - // headers: { - // "Authorization": "Bearer: " + token.accessToken - // }, - // }; - const apiUrl = `${window.location.origin}/${publicRuntimeConfig.apiBasePath}` - fetch(`${apiUrl}/vlabs`) - .then((res) => res.json()) - .then((data) => { - setVlabs(data); - }) - .catch((error) => { - console.log(error) - }); - // } - }, []); + const [isOpen, setIsOpen] = useState(false); + const [vlabs, setVlabs] = useState([]); - // const { status } = useSession({ - // required: true, - // onUnauthenticated() { - // signIn(); - // }, - // }) + useEffect(() => { - // if (status === "loading") { - // return "Loading or not authenticated..." - // } + const apiUrl = `${window.location.origin}/${publicRuntimeConfig.apiBasePath}` + fetch(`${apiUrl}/vlabs`) + .then((res) => res.json()) + .then((data) => { + setVlabs(data); + }) + .catch((error) => { + console.log(error) + }); + }, []); - return ( -
-
- ) + return ( +
+
+ ) }; -export async function getServerSideProps(context:any) { - - const { req } = context; - const secret = process.env.SECRET; - const token = await getToken({ req, secret }); - - return { - props: { - token: token - } - }; -} - export default VLabs; \ No newline at end of file From b7d0099f06070978be0fe62f63d4a862f6d8bfb8 Mon Sep 17 00:00:00 2001 From: Gabriel Pelouze Date: Thu, 14 Sep 2023 14:30:50 +0200 Subject: [PATCH 02/10] add loading virtual labs status --- vre-panel/pages/index.tsx | 70 +++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/vre-panel/pages/index.tsx b/vre-panel/pages/index.tsx index 15b942d..6c9a22c 100644 --- a/vre-panel/pages/index.tsx +++ b/vre-panel/pages/index.tsx @@ -19,6 +19,7 @@ const VLabs = () => { const [isOpen, setIsOpen] = useState(false); const [vlabs, setVlabs] = useState([]); + const [vlabsLoading, setVlabsLoading] = useState(true); useEffect(() => { @@ -27,9 +28,11 @@ const VLabs = () => { .then((res) => res.json()) .then((data) => { setVlabs(data); + setVlabsLoading(false) }) .catch((error) => { console.log(error) + setVlabsLoading(false) }); }, []); @@ -38,28 +41,53 @@ const VLabs = () => {