Skip to content

Commit

Permalink
Merge pull request #504 from mlibrary/LIBSEARCH-61-investigate-ways-t…
Browse files Browse the repository at this point in the history
…o-overcome-late-loading-of-profile-data

[LIBSEARCH-61] Investigate ways to overcome late loading of profile data
  • Loading branch information
erinesullivan authored Nov 14, 2024
2 parents 0f18a5b + 52216fc commit 7a995a0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/modules/core/components/SearchHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<m-website-header name='Search' variant='dark' to='/everything'>
<nav aria-label='utility'>
<Anchor href='https://account.lib.umich.edu/'>Account</Anchor>
<Authentication logout={isAuthenticated} />
{status && <Authentication logout={status === 'Logged in'} />}
<ChooseAffiliation />
</nav>
</m-website-header>
Expand Down
6 changes: 3 additions & 3 deletions src/modules/datastores/components/FlintAlerts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -16,7 +16,7 @@ const FlintAlerts = ({ datastore, profile }) => {
website: (<>We noticed you are affiliated with U-M Flint. For the best results use the <Anchor href='https://libguides.umflint.edu/library'>Thompson Library website</Anchor>.</>)
};

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;
}

Expand All @@ -37,7 +37,7 @@ const FlintAlerts = ({ datastore, profile }) => {

FlintAlerts.propTypes = {
datastore: PropTypes.string,
profile: PropTypes.object
institutions: PropTypes.array
};

export default FlintAlerts;
12 changes: 6 additions & 6 deletions src/modules/lists/components/ActionsList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -85,19 +85,19 @@ const ActionsList = (props) => {
})}
</ul>
{props.active?.action === 'email' && (
<AuthenticationRequired profile={profile}>
<AuthenticationRequired status={status}>
<EmailAction
action={props.active}
emailAddress={profile?.email || ''}
emailAddress={email || ''}
{...props}
/>
</AuthenticationRequired>
)}
{props.active?.action === 'text' && (
<AuthenticationRequired profile={profile}>
<AuthenticationRequired status={status}>
<TextAction
action={props.active}
phoneNumber={profile?.text || ''}
phoneNumber={text || ''}
{...props}
/>
</AuthenticationRequired>
Expand Down
8 changes: 4 additions & 4 deletions src/modules/pages/components/DatastorePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +94,7 @@ const DatastorePage = () => {
<>
<SearchBox />
<DatastoreNavigation {...{ activeFilters, datastores, institution, search }} />
<FlintAlerts datastore={activeDatastore.uid} profile={profile} />
<FlintAlerts datastore={activeDatastore.uid} institutions={institutions} />
<Routes>
<Route
path='record/:recordUid/get-this/:barcode'
Expand All @@ -106,7 +106,7 @@ const DatastorePage = () => {
/>
<Route
path='list'
element={<List {...{ activeDatastore, institution, list, profile }} />}
element={<List {...{ activeDatastore, institution, list }} />}
/>
<Route
index
Expand Down
17 changes: 8 additions & 9 deletions src/modules/pride/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -23,7 +23,7 @@ AuthenticationRequired.propTypes = {
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]),
profile: PropTypes.object
status: PropTypes.string
};

export default AuthenticationRequired;

0 comments on commit 7a995a0

Please sign in to comment.