Skip to content

Commit

Permalink
fix(view types): handle default view type selection
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjithkumar017 committed Jan 21, 2021
1 parent 0b630bc commit c98f371
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/UnbxdSearchWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { viewTypes } from './config/constants';
* Component to initialize Unbxd Search. UnbxdSearchWrapper also acts as a root component for modules such as Products, Pagination and facets.
*/
const initialUnbxdState = {
viewType: 'GRID',
viewType: '',
paginationType: paginationTypes.FIXED_PAGINATION,
enableApplyFilters: false,
selectedTextFacets: { add: {}, remove: {}, list: {} },
Expand Down Expand Up @@ -132,9 +132,6 @@ class UnbxdSearchWrapper extends Component {
typeof unbxdCore.options.getCategoryId === 'function' &&
unbxdCore.options.getCategoryId();

const viewType =
this.state.unbxdCore.getQueryParams()['viewType'] || viewTypes.GRID;
unbxdCore.options.extraParams['viewType'] = viewType;

if (unbxdCore.options.applyMultipleFilters) {
this.setState((currentState) => {
Expand Down
12 changes: 10 additions & 2 deletions src/modules/viewTypes/ViewTypesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ class ViewTypesContainer extends React.PureComponent {
componentDidMount() {
const {
helpers: { setViewTypeConfiguration },
viewType
viewType,
viewTypes,
unbxdCore
} = this.props;
setViewTypeConfiguration({ viewType });

const currentViewType = unbxdCore.getQueryParams()['viewType'];
if (currentViewType) {
setViewTypeConfiguration({ viewType: currentViewType });
} else {
setViewTypeConfiguration({ viewType: viewType || viewTypes[0] });
}
}

getViewTypesProps() {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/setViewTypeConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function setViewTypeConfiguration(config, triggerResults = false) {
unbxdState: { ...currentState.unbxdState, viewType }
};
});
const { unbxdCore } = this.state;
unbxdCore.options.extraParams['viewType'] = viewType;
if (triggerResults) {
const { unbxdCore } = this.state;
unbxdCore.options.extraParams['viewType'] = viewType;
unbxdCore.getResults();
}
Expand Down

0 comments on commit c98f371

Please sign in to comment.