-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from mlibrary/LIBSEARCH-899-convert-choose-af…
…filiation-into-a-select-dropdown-filter-option [LIBSEARCH-899] Convert ChooseAffiliation into a select dropdown filter option.
- Loading branch information
Showing
12 changed files
with
74 additions
and
353 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/modules/affiliation/components/ChooseAffiliation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { React, useState } from 'react'; | ||
|
||
const initialAffiliationState = { | ||
active: undefined, | ||
defaultAffiliation: 'aa', | ||
affiliationOptions: { | ||
aa: 'Ann Arbor', | ||
flint: 'Flint' | ||
} | ||
}; | ||
|
||
function ChooseAffiliation () { | ||
let defaultAffiliation = initialAffiliationState.defaultAffiliation; | ||
// Set default affiliation if query parameter exists | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const affiliationParam = urlParams.get('affiliation'); | ||
if (affiliationParam) { | ||
defaultAffiliation = affiliationParam; | ||
// Set localStorage | ||
localStorage.setItem('affiliation', affiliationParam); | ||
} | ||
const affiliationLocalStorage = localStorage.getItem('affiliation'); | ||
// Set default affiliation if localStorage exists | ||
if (affiliationLocalStorage) { | ||
defaultAffiliation = affiliationLocalStorage; | ||
} | ||
const [affiliation, setAffiliation] = useState(defaultAffiliation); | ||
const onAffiliationChange = (event) => { | ||
const value = event.target.value; | ||
setAffiliation(value); | ||
urlParams.set('affiliation', value); | ||
window.location.href = `${window.location.origin}${window.location.pathname}?${urlParams.toString()}`; | ||
}; | ||
|
||
return ( | ||
<fieldset className='institution-select-container'> | ||
<legend className='visually-hidden'>Choose Affiliation</legend> | ||
<label | ||
className='institution-select-label institution-select-label-text' | ||
htmlFor='choose-affiliation' | ||
> | ||
Affiliation | ||
</label> | ||
<select | ||
className='dropdown' | ||
id='choose-affiliation' | ||
autoComplete='off' | ||
value={affiliation} | ||
onChange={onAffiliationChange} | ||
aria-describedby='affiliation-description' | ||
> | ||
{Object.keys(initialAffiliationState.affiliationOptions).map((affiliationOption) => { | ||
return ( | ||
<option value={affiliationOption} key={`affiliation-${affiliationOption}`}> | ||
{initialAffiliationState.affiliationOptions[affiliationOption]} | ||
</option> | ||
); | ||
})} | ||
</select> | ||
<p className='font-small' id='affiliation-description'>Selecting an affiliation helps us connect you to available online materials licensed for your campus. You can still use Library Search if you're not affiliated with either campus.</p> | ||
</fieldset> | ||
); | ||
} | ||
|
||
export { initialAffiliationState, ChooseAffiliation }; |
201 changes: 0 additions & 201 deletions
201
src/modules/affiliation/components/choose-affiliation.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.