From df742285baeaca04cc6e4aa5c2ff7e1698f393a8 Mon Sep 17 00:00:00 2001 From: AntoninoP Date: Wed, 3 Jul 2024 21:00:19 +0200 Subject: [PATCH] =?UTF-8?q?+=20gestion=20loader=20am=C3=A9lior=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 8 +-- src/App.module.scss | 28 ---------- src/components/CreateServer/CreateServer.jsx | 31 ++++++++++- src/pages/DashboardPage/DashboardPage.jsx | 58 +++++++++++--------- src/pages/Loading/loading.jsx | 10 ++++ src/pages/Loading/loading.module.scss | 28 ++++++++++ src/pages/NoServer/NoServer.jsx | 6 +- 7 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 src/pages/Loading/loading.jsx create mode 100644 src/pages/Loading/loading.module.scss diff --git a/src/App.jsx b/src/App.jsx index 542378f..a49c114 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,13 +7,7 @@ import LoginPage from './pages/LoginPage/LoginPage'; import DashboardPage from './pages/DashboardPage/DashboardPage'; import { auth } from './service/firebase'; import styles from './App.module.scss'; - -const Loading = () => ( -
-
-

Chargement...

-
-); +import Loading from './pages/Loading/loading'; const App = () => { const [user, setUser] = useState(null); diff --git a/src/App.module.scss b/src/App.module.scss index 4dec71d..e69de29 100644 --- a/src/App.module.scss +++ b/src/App.module.scss @@ -1,28 +0,0 @@ - - .loading { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - height: 100vh; - font-size: 1.5rem; - } - - .spinner { - border: 4px solid rgba(0, 0, 0, 0.1); - width: 6rem; - height: 6rem; - border-radius: 50%; - border-left-color: #09f; - animation: spin 1s ease infinite; - } - - @keyframes spin { - 0% { - transform: rotate(0deg); - } - 100% { - transform: rotate(360deg); - } - } - \ No newline at end of file diff --git a/src/components/CreateServer/CreateServer.jsx b/src/components/CreateServer/CreateServer.jsx index 636a1ba..92d8e56 100644 --- a/src/components/CreateServer/CreateServer.jsx +++ b/src/components/CreateServer/CreateServer.jsx @@ -4,8 +4,10 @@ import { getUserSubdomain } from "../../service/firebase"; import serviiApi from "../../service/api.tsx"; const CreateServer = ({ user, onCreateServer }) => { - const [subdomain, setSubdomain] = useState('loading'); // Utiliser 'loading' au lieu de null + const [subdomain, setSubdomain] = useState('loading'); const [subdomainInput, setSubdomainInput] = useState(''); + const [serverName, setServerName] = useState(''); + const [serverVersion, setServerVersion] = useState(''); const loadSubdomain = async () => { try { @@ -33,6 +35,14 @@ const CreateServer = ({ user, onCreateServer }) => { } }; + const handleCreateServer = async () => { + try { + await onCreateServer(serverName, serverVersion); + } catch (error) { + console.error('Error creating server:', error); + } + }; + if (subdomain === 'loading') { return (
@@ -63,8 +73,23 @@ const CreateServer = ({ user, onCreateServer }) => {
Création du serveur
- -
diff --git a/src/pages/DashboardPage/DashboardPage.jsx b/src/pages/DashboardPage/DashboardPage.jsx index 2adbfdb..097f74c 100644 --- a/src/pages/DashboardPage/DashboardPage.jsx +++ b/src/pages/DashboardPage/DashboardPage.jsx @@ -4,24 +4,25 @@ import Navbar from '../../components/navbar/Navbar'; import styles from './DashboardPage.module.scss'; import NoServer from '../NoServer/NoServer'; import { getUserSubdomain } from "../../service/firebase"; -import '../../service/api.tsx'; import serviiApi from "../../service/api.tsx"; -import Api from "../../service/api.tsx"; - +import Loading from '../Loading/loading'; const DashboardPage = ({ user }) => { const [servers, setServers] = useState([]); const [subdomain, setSubdomain] = useState(""); + const [loading, setLoading] = useState(true); const loadServers = async () => { try { const ApiResponse = await serviiApi.fetchServers(); - const data = ApiResponse.message + const data = ApiResponse.message; setServers(data); const userSubdomain = await getUserSubdomain(user.uid); setSubdomain(userSubdomain); } catch (error) { console.error('Error fetching data:', error); + } finally { + setLoading(false); } }; @@ -29,11 +30,10 @@ const DashboardPage = ({ user }) => { loadServers(); }, []); - const handleCreateServer = async () => { + const handleCreateServer = async (serverName, serverVersion) => { try { - const serverName = prompt('Enter the name for the new server:'); - if (!serverName) return; - await serviiApi.serverCreate(serverName, "1.20.6", "paper"); + if (!serverName || !serverVersion) return; + await serviiApi.serverCreate(serverName, serverVersion, "paper"); await loadServers(); } catch (error) { console.error('Error creating server:', error); @@ -68,25 +68,29 @@ const DashboardPage = ({ user }) => { return (
-
- {servers.length === 0 ? ( - - ) : ( - servers.map((server, index) => ( - handleRunServer(server.name)} - onStopClick={() => handleStopServer(server.name)} - onDeleteClick={() => handleDeleteServer(server.name)} - /> - )) - )} -
+ {loading ? ( + + ) : ( +
+ {servers.length === 0 ? ( + + ) : ( + servers.map((server, index) => ( + handleRunServer(server.name)} + onStopClick={() => handleStopServer(server.name)} + onDeleteClick={() => handleDeleteServer(server.name)} + /> + )) + )} +
+ )}
); }; diff --git a/src/pages/Loading/loading.jsx b/src/pages/Loading/loading.jsx new file mode 100644 index 0000000..2818fa0 --- /dev/null +++ b/src/pages/Loading/loading.jsx @@ -0,0 +1,10 @@ +import styles from './loading.module.scss'; + +const Loading = () => ( +
+
+

Chargement...

+
+ ); + +export default Loading; \ No newline at end of file diff --git a/src/pages/Loading/loading.module.scss b/src/pages/Loading/loading.module.scss new file mode 100644 index 0000000..9cb534d --- /dev/null +++ b/src/pages/Loading/loading.module.scss @@ -0,0 +1,28 @@ + +.loading { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + height: 100vh; + font-size: 1.5rem; + } + + .spinner { + border: 4px solid rgba(0, 0, 0, 0.1); + width: 6rem; + height: 6rem; + border-radius: 50%; + border-left-color: #09f; + animation: spin 1s ease infinite; + } + + @keyframes spin { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } + } + \ No newline at end of file diff --git a/src/pages/NoServer/NoServer.jsx b/src/pages/NoServer/NoServer.jsx index 7aea1f8..be33ef7 100644 --- a/src/pages/NoServer/NoServer.jsx +++ b/src/pages/NoServer/NoServer.jsx @@ -8,15 +8,15 @@ const NoServer = ({ user, onCreateServer }) => { return (
- { isCreating === false ? ( + {isCreating === false ? ( <> -
Erreur
+
Erreur
Aucun serveur possédé
) : ( <> - {} + )}