From 64ad40968ac29018b74da0758a33e58a9329a4db Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Thu, 14 Nov 2024 11:28:54 -0500 Subject: [PATCH 1/3] Forcing all functions to load first prior to `renderApp`. --- src/modules/pride/setup.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/modules/pride/setup.js b/src/modules/pride/setup.js index b561e297..38715145 100644 --- a/src/modules/pride/setup.js +++ b/src/modules/pride/setup.js @@ -538,17 +538,16 @@ const initializePride = () => { Pride.init({ failure: () => { renderPrideFailedToLoad(); - // Console.log('Pride failed to load.'); }, - success: () => { - setupSearches(); - setupAdvancedSearch(); - setupDefaultInstitution(); - setupDefaultAffiliation(); - setupBrowse(); + success: async () => { + await setupSearches(); + await setupAdvancedSearch(); + await setupDefaultInstitution(); + await setupDefaultAffiliation(); + await setupBrowse(); + await prejudice.initialize(); + await setupProfile(); renderApp(); - prejudice.initialize(); - setupProfile(); } }); }; From 98c7b39a008b2709fc6b78a217ff0f5992cc96c4 Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Thu, 14 Nov 2024 11:51:09 -0500 Subject: [PATCH 2/3] Updating showing `Log in/out` to wait until `state.profile.status` has been loaded. Destructuring `state.profile` in `ActionsList` to only pass through the `status` string instead of the full `profile` object. --- src/modules/core/components/SearchHeader/index.js | 6 +++--- src/modules/lists/components/ActionsList/index.js | 12 ++++++------ .../components/AuthenticationRequired/index.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/modules/core/components/SearchHeader/index.js b/src/modules/core/components/SearchHeader/index.js index e193574f..9304cc5f 100644 --- a/src/modules/core/components/SearchHeader/index.js +++ b/src/modules/core/components/SearchHeader/index.js @@ -6,15 +6,15 @@ import React from 'react'; import { useSelector } from 'react-redux'; const SearchHeader = () => { - const isAuthenticated = useSelector((state) => { - return state.profile.status === 'Logged in'; + const { status } = useSelector((state) => { + return state.profile || {}; }); return ( diff --git a/src/modules/lists/components/ActionsList/index.js b/src/modules/lists/components/ActionsList/index.js index bb116f41..2059e56b 100644 --- a/src/modules/lists/components/ActionsList/index.js +++ b/src/modules/lists/components/ActionsList/index.js @@ -50,8 +50,8 @@ const actions = [ const ActionsList = (props) => { const [alert, setAlert] = useState(null); - const profile = useSelector((state) => { - return state.profile; + const { email, status, text } = useSelector((state) => { + return state.profile || {}; }); return ( @@ -85,19 +85,19 @@ const ActionsList = (props) => { })} {props.active?.action === 'email' && ( - + )} {props.active?.action === 'text' && ( - + diff --git a/src/modules/profile/components/AuthenticationRequired/index.js b/src/modules/profile/components/AuthenticationRequired/index.js index cf37656a..6d0f24ab 100644 --- a/src/modules/profile/components/AuthenticationRequired/index.js +++ b/src/modules/profile/components/AuthenticationRequired/index.js @@ -2,12 +2,12 @@ import Authentication from '../Authentication'; import PropTypes from 'prop-types'; import React from 'react'; -const AuthenticationRequired = ({ children, profile }) => { +const AuthenticationRequired = ({ children, status }) => { if (!children) { return null; } - if (profile?.status === 'Logged in') { + if (status === 'Logged in') { return children; } @@ -23,7 +23,7 @@ AuthenticationRequired.propTypes = { PropTypes.arrayOf(PropTypes.node), PropTypes.node ]), - profile: PropTypes.object + status: PropTypes.string }; export default AuthenticationRequired; From 52216fc1d6dc3bf2d438f83630f5e42e245e29ed Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Thu, 14 Nov 2024 14:52:52 -0500 Subject: [PATCH 3/3] Removing unused `profile` properties, and destructuring `profile` state. --- src/modules/datastores/components/FlintAlerts/index.js | 6 +++--- src/modules/pages/components/DatastorePage/index.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/datastores/components/FlintAlerts/index.js b/src/modules/datastores/components/FlintAlerts/index.js index 5d52c17d..ba7b8b49 100644 --- a/src/modules/datastores/components/FlintAlerts/index.js +++ b/src/modules/datastores/components/FlintAlerts/index.js @@ -2,7 +2,7 @@ import { Alert, Anchor } from '../../../reusable'; import React, { useState } from 'react'; import PropTypes from 'prop-types'; -const FlintAlerts = ({ datastore, profile }) => { +const FlintAlerts = ({ datastore, institutions = [] }) => { const [dismiss, setDismiss] = useState([]); const handleDismissClick = () => { setDismiss((previousDismiss) => { @@ -16,7 +16,7 @@ const FlintAlerts = ({ datastore, profile }) => { website: (<>We noticed you are affiliated with U-M Flint. For the best results use the Thompson Library website.) }; - if (!Object.keys(messages).includes(datastore) || !profile.institutions?.includes('Flint') || dismiss.includes(datastore)) { + if (!Object.keys(messages).includes(datastore) || !institutions.includes('Flint') || dismiss.includes(datastore)) { return null; } @@ -37,7 +37,7 @@ const FlintAlerts = ({ datastore, profile }) => { FlintAlerts.propTypes = { datastore: PropTypes.string, - profile: PropTypes.object + institutions: PropTypes.array }; export default FlintAlerts; diff --git a/src/modules/pages/components/DatastorePage/index.js b/src/modules/pages/components/DatastorePage/index.js index 786627f3..69336999 100644 --- a/src/modules/pages/components/DatastorePage/index.js +++ b/src/modules/pages/components/DatastorePage/index.js @@ -37,8 +37,8 @@ const DatastorePage = () => { const institution = useSelector((state) => { return state.institution; }); - const profile = useSelector((state) => { - return state.profile; + const { institutions } = useSelector((state) => { + return state.profile || {}; }); const search = useSelector((state) => { return state.search; @@ -94,7 +94,7 @@ const DatastorePage = () => { <> - + { /> } + element={} />