Skip to content

Commit 90fd429

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

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,32 @@ 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+
StartingLocationIdContext,
12+
RootLocationIdContext
13+
} from '../../universal.discovery.module';
714

815
const ViewSwitcher = ({ isDisabled }) => {
916
const Translator = getTranslator();
1017
const viewLabel = Translator.trans(/*@Desc("View")*/ 'view_switcher.view', {}, 'ibexa_universal_discovery_widget');
1118
const [currentView, setCurrentView] = useContext(CurrentViewContext);
1219
const { views } = useContext(ViewContext);
20+
const startingLocationId = useContext(StartingLocationIdContext);
21+
const rootLocationId = useContext(RootLocationIdContext);
22+
const [ markedLocationId ] = useContext(MarkedLocationIdContext);
1323
const selectedOption = views.find((option) => option.value === currentView);
24+
25+
console.log('ViewSwitcher render', startingLocationId, rootLocationId, markedLocationId);
26+
1427
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);
1532
setCurrentView(value);
1633
};
1734

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 ?? defaultMarkedLocationId}`;
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)