From 0f0594f2c4063466c891abf96948ebf298212df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Sat, 21 Aug 2021 10:45:55 -1000 Subject: [PATCH] Add a button to show the modules statuses It's really annoying to wait for the modules to be loaded while visiting the user profile or admin panel. --- frontend/js/components/admins/modules.js | 14 ++++++++++---- frontend/js/components/modules/modules.js | 23 +++++++++++++++++++++-- frontend/js/components/users/profile.js | 12 ++++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/frontend/js/components/admins/modules.js b/frontend/js/components/admins/modules.js index 895bb99..78f7a55 100644 --- a/frontend/js/components/admins/modules.js +++ b/frontend/js/components/admins/modules.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React from "react"; import { useDispatch, useSelector } from "react-redux"; import { getAdminModules } from "../../actions/admins"; @@ -10,9 +10,15 @@ export const AdminModules = () => { const loading = useSelector((state) => state.admin.fetchingModules); const modules = useSelector((state) => state.admin.modules); - useEffect(() => { + const fetchModules = () => { dispatch(getAdminModules()); - }, [dispatch]); + }; - return ; + return ( + + ); }; diff --git a/frontend/js/components/modules/modules.js b/frontend/js/components/modules/modules.js index 7478136..93aa798 100644 --- a/frontend/js/components/modules/modules.js +++ b/frontend/js/components/modules/modules.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import Loader from "../loader/loader"; import PropTypes from "prop-types"; @@ -7,11 +7,29 @@ import { upperCaseFirst } from "../../utils"; // TODO: udpate this import { OverlayTrigger, Tooltip } from "react-bootstrap"; -const Modules = ({ isLoading, modules }) => { +const Modules = ({ isLoading, modules, fetchModules }) => { + const [show, setShow] = useState(false); if (isLoading) { return ; } + const handleClick = () => { + fetchModules(); + setShow(true); + }; + + if (!show) { + return ( +
+
+
+ Show modules status +
+
+
+ ); + } + return (
{Object.keys(modules).map((type) => ( @@ -23,6 +41,7 @@ const Modules = ({ isLoading, modules }) => { Modules.propTypes = { isLoading: PropTypes.bool.isRequired, modules: PropTypes.object.isRequired, + fetchModules: PropTypes.func.isRequired, }; export default Modules; diff --git a/frontend/js/components/users/profile.js b/frontend/js/components/users/profile.js index 98db391..1bdeeea 100644 --- a/frontend/js/components/users/profile.js +++ b/frontend/js/components/users/profile.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React from "react"; import { useDispatch, useSelector } from "react-redux"; import { PolochonList } from "../polochons/list"; @@ -12,15 +12,19 @@ export const UserProfile = () => { const modules = useSelector((state) => state.user.modules); const modulesLoading = useSelector((state) => state.user.modulesLoading); - useEffect(() => { + const fetchModules = () => { dispatch(getUserModules()); - }, [dispatch]); + }; return (
- +
); };