Skip to content

Commit e553fe8

Browse files
committed
IBX-10126: Added save selected view type for UDW
1 parent 03ee5c9 commit e553fe8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/bundle/ui-dev/src/modules/universal-discovery/components/view-switcher/view.switcher.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ import PropTypes from 'prop-types';
33

44
import SimpleDropdown from '../../../common/simple-dropdown/simple.dropdown';
55
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';
713

814
const 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);
22+
23+
console.log('ViewSwitcher render', startingLocationId, rootLocationId, markedLocationId);
24+
1425
const onOptionClick = ({ value }) => {
26+
const itemsViewTypeStorageKey = `${ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX}-${markedLocationId ?? rootLocationId}`;
27+
28+
window.localStorage.setItem(itemsViewTypeStorageKey, value);
1529
setCurrentView(value);
1630
};
1731

src/bundle/ui-dev/src/modules/universal-discovery/universal.discovery.module.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
3840
export const SORTING_OPTIONS = [
3941
{
4042
value: 'date:asc',
@@ -522,6 +524,16 @@ const UniversalDiscoveryModule = (props) => {
522524
}
523525
}, [currentView]);
524526

527+
useEffect(() => {
528+
const itemsViewStorageKey = `${ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX}-${markedLocationId ?? rootLocationId}`;
529+
const itemsViewType = window.localStorage.getItem(itemsViewStorageKey) || props.activeView;
530+
531+
if (itemsViewType) {
532+
setCurrentView(itemsViewType);
533+
}
534+
535+
}, [markedLocationId]);
536+
525537
return (
526538
<div className={className}>
527539
<UDWContext.Provider value={true}>

0 commit comments

Comments
 (0)