File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
src/bundle/ui-dev/src/modules/universal-discovery Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,26 @@ import PropTypes from 'prop-types';
33
44import SimpleDropdown from '../../../common/simple-dropdown/simple.dropdown' ;
55import { getTranslator } from '../../../../../../Resources/public/js/scripts/helpers/context.helper' ;
6- import { CurrentViewContext , ViewContext } from '../../universal.discovery.module' ;
6+ import {
7+ ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX ,
8+ CurrentViewContext ,
9+ MarkedLocationIdContext ,
10+ ViewContext ,
11+ RootLocationIdContext ,
12+ } from '../../universal.discovery.module' ;
713
814const ViewSwitcher = ( { isDisabled } ) => {
915 const Translator = getTranslator ( ) ;
1016 const viewLabel = Translator . trans ( /*@Desc ("View")*/ 'view_switcher.view' , { } , 'ibexa_universal_discovery_widget' ) ;
1117 const [ currentView , setCurrentView ] = useContext ( CurrentViewContext ) ;
1218 const { views } = useContext ( ViewContext ) ;
19+ const rootLocationId = useContext ( RootLocationIdContext ) ;
20+ const [ markedLocationId ] = useContext ( MarkedLocationIdContext ) ;
1321 const selectedOption = views . find ( ( option ) => option . value === currentView ) ;
1422 const onOptionClick = ( { value } ) => {
23+ const itemsViewTypeStorageKey = `${ ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX } -${ markedLocationId ?? rootLocationId } ` ;
24+
25+ window . localStorage . setItem ( itemsViewTypeStorageKey , value ) ;
1526 setCurrentView ( value ) ;
1627 } ;
1728
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ const defaultRestInfo = {
3535 siteaccess : document . querySelector ( 'meta[name="SiteAccess"]' ) ?. content ,
3636} ;
3737
38+ export const ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX = 'ibexa-udw-active-view-location' ;
39+
3840export const SORTING_OPTIONS = [
3941 {
4042 value : 'date:asc' ,
@@ -522,6 +524,15 @@ const UniversalDiscoveryModule = (props) => {
522524 }
523525 } , [ currentView ] ) ;
524526
527+ useEffect ( ( ) => {
528+ const itemsViewStorageKey = `${ ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX } -${ markedLocationId ?? props . rootLocationId } ` ;
529+ const itemsViewType = window . localStorage . getItem ( itemsViewStorageKey ) || props . activeView ;
530+
531+ if ( itemsViewType ) {
532+ setCurrentView ( itemsViewType ) ;
533+ }
534+ } , [ markedLocationId ] ) ;
535+
525536 return (
526537 < div className = { className } >
527538 < UDWContext . Provider value = { true } >
You can’t perform that action at this time.
0 commit comments