forked from ProjectMirador/mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COLUMBIA: SelectCollectionFolders uses window state instead of local …
…state - configurable collection nav button in top bar - clean up unused imports
- Loading branch information
Showing
6 changed files
with
90 additions
and
64 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
src/culPlugins/mirador-hinting-sidebar/components/TopCollectionButton.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,50 @@ | ||
import AccountTreeIcon from '@mui/icons-material/AccountTree'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { Utils } from 'manifesto.js'; | ||
import { getCollectionPath } from '../../state/selectors'; | ||
import { getManifest, getManifestoInstance } from '../../../state/selectors'; | ||
Check warning on line 5 in src/culPlugins/mirador-hinting-sidebar/components/TopCollectionButton.js
|
||
import { updateWindow } from '../../../state/actions'; | ||
import MiradorMenuButton from '../../../containers/MiradorMenuButton'; | ||
import ns from '../../../config/css-ns'; | ||
|
||
/** render a topbar button that returns to a view of the containing collection */ | ||
export const TopCollectionButton = (props) => { | ||
const { className, color, windowId } = props; | ||
const collectionPath = useSelector((state) => getCollectionPath(state, { windowId })); | ||
|
||
/** compare o(ld) manifest and n(ew) manifest to see if difference should update state */ | ||
const equalManifest = (o, n) => { | ||
if (!o && !n) return true; | ||
if (!o || !n) return false; | ||
if (o?.id !== n?.id) return false; | ||
if (o?.isFetching !== n?.isFetching) return false; | ||
return true; | ||
}; | ||
|
||
const manifest = useSelector(state => getManifest(state, { windowId }), equalManifest); | ||
const dispatch = useDispatch(); | ||
|
||
const manifestoObject = manifest ? Utils.parseManifest(manifest.json, undefined) : false; | ||
if (!manifestoObject || manifestoObject.isCollection()) return false; | ||
|
||
const disableButton = !collectionPath?.at(0); | ||
|
||
/** onclick to update collection data on window and return to collection view */ | ||
const clickHandler = () => { | ||
if (!manifestoObject || disableButton) return; | ||
const update = { collectionPath: collectionPath.slice(0, -1), manifestId: collectionPath.at(-1) }; | ||
dispatch(updateWindow(windowId, update)); | ||
}; | ||
|
||
return ( | ||
<MiradorMenuButton | ||
aria-label="View Collection" | ||
className={className || ns('window-menu-btn')} | ||
color={color} | ||
disabled={disableButton} | ||
onClick={clickHandler} | ||
> | ||
<AccountTreeIcon /> | ||
</MiradorMenuButton> | ||
); | ||
}; |
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