Skip to content

Commit 17a9b01

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

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@ 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);
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

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

Lines changed: 11 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,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}>

0 commit comments

Comments
 (0)