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';
3
3
4
4
import SimpleDropdown from '../../../common/simple-dropdown/simple.dropdown' ;
5
5
import { 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' ;
7
13
8
14
const ViewSwitcher = ( { isDisabled } ) => {
9
15
const Translator = getTranslator ( ) ;
10
16
const viewLabel = Translator . trans ( /*@Desc ("View")*/ 'view_switcher.view' , { } , 'ibexa_universal_discovery_widget' ) ;
11
17
const [ currentView , setCurrentView ] = useContext ( CurrentViewContext ) ;
12
18
const { views } = useContext ( ViewContext ) ;
19
+ const rootLocationId = useContext ( RootLocationIdContext ) ;
20
+ const [ markedLocationId ] = useContext ( MarkedLocationIdContext ) ;
13
21
const selectedOption = views . find ( ( option ) => option . value === currentView ) ;
14
22
const onOptionClick = ( { value } ) => {
23
+ const itemsViewTypeStorageKey = `${ ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX } -${ markedLocationId ?? rootLocationId } ` ;
24
+
25
+ window . localStorage . setItem ( itemsViewTypeStorageKey , value ) ;
15
26
setCurrentView ( value ) ;
16
27
} ;
17
28
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ const defaultRestInfo = {
35
35
siteaccess : document . querySelector ( 'meta[name="SiteAccess"]' ) ?. content ,
36
36
} ;
37
37
38
+ export const ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX = 'ibexa-udw-active-view-location' ;
39
+
38
40
export const SORTING_OPTIONS = [
39
41
{
40
42
value : 'date:asc' ,
@@ -522,6 +524,15 @@ const UniversalDiscoveryModule = (props) => {
522
524
}
523
525
} , [ currentView ] ) ;
524
526
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
+
525
536
return (
526
537
< div className = { className } >
527
538
< UDWContext . Provider value = { true } >
You can’t perform that action at this time.
0 commit comments