Skip to content

IBX-10126: Added save selected view type for UDW #1595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@ import PropTypes from 'prop-types';

import SimpleDropdown from '../../../common/simple-dropdown/simple.dropdown';
import { getTranslator } from '../../../../../../Resources/public/js/scripts/helpers/context.helper';
import { CurrentViewContext, ViewContext } from '../../universal.discovery.module';
import {
ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX,
CurrentViewContext,
MarkedLocationIdContext,
ViewContext,
RootLocationIdContext,
} from '../../universal.discovery.module';

const ViewSwitcher = ({ isDisabled }) => {
const Translator = getTranslator();
const viewLabel = Translator.trans(/*@Desc("View")*/ 'view_switcher.view', {}, 'ibexa_universal_discovery_widget');
const [currentView, setCurrentView] = useContext(CurrentViewContext);
const { views } = useContext(ViewContext);
const rootLocationId = useContext(RootLocationIdContext);
const [markedLocationId] = useContext(MarkedLocationIdContext);
const selectedOption = views.find((option) => option.value === currentView);
const onOptionClick = ({ value }) => {
const itemsViewTypeStorageKey = `${ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX}-${markedLocationId ?? rootLocationId}`;

window.localStorage.setItem(itemsViewTypeStorageKey, value);
setCurrentView(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const defaultRestInfo = {
siteaccess: document.querySelector('meta[name="SiteAccess"]')?.content,
};

export const ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX = 'ibexa-udw-active-view-location';

export const SORTING_OPTIONS = [
{
value: 'date:asc',
Expand Down Expand Up @@ -522,6 +524,15 @@ const UniversalDiscoveryModule = (props) => {
}
}, [currentView]);

useEffect(() => {
const itemsViewStorageKey = `${ITEMS_VIEW_TYPE_STORAGE_KEY_PREFIX}-${markedLocationId ?? props.rootLocationId}`;
const itemsViewType = window.localStorage.getItem(itemsViewStorageKey) || props.activeView;

if (itemsViewType) {
setCurrentView(itemsViewType);
}
}, [markedLocationId]);

return (
<div className={className}>
<UDWContext.Provider value={true}>
Expand Down
Loading