@@ -3,15 +3,32 @@ 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
+ StartingLocationIdContext ,
12
+ RootLocationIdContext
13
+ } from '../../universal.discovery.module' ;
7
14
8
15
const ViewSwitcher = ( { isDisabled } ) => {
9
16
const Translator = getTranslator ( ) ;
10
17
const viewLabel = Translator . trans ( /*@Desc ("View")*/ 'view_switcher.view' , { } , 'ibexa_universal_discovery_widget' ) ;
11
18
const [ currentView , setCurrentView ] = useContext ( CurrentViewContext ) ;
12
19
const { views } = useContext ( ViewContext ) ;
20
+ const startingLocationId = useContext ( StartingLocationIdContext ) ;
21
+ const rootLocationId = useContext ( RootLocationIdContext ) ;
22
+ const [ markedLocationId ] = useContext ( MarkedLocationIdContext ) ;
13
23
const selectedOption = views . find ( ( option ) => option . value === currentView ) ;
24
+
25
+ console . log ( 'ViewSwitcher render' , startingLocationId , rootLocationId , markedLocationId ) ;
26
+
14
27
const onOptionClick = ( { value } ) => {
28
+ const defaultMarkedLocationId = startingLocationId || rootLocationId ;
29
+ const itemsViewStorageKey = `${ ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX } -${ markedLocationId ?? defaultMarkedLocationId } ` ;
30
+
31
+ window . localStorage . setItem ( itemsViewStorageKey , value ) ;
15
32
setCurrentView ( value ) ;
16
33
} ;
17
34
0 commit comments