Skip to content
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

feat: add default mobile listing viewtype #1243

Merged
merged 5 commits into from
Sep 6, 2022
Merged
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
7 changes: 7 additions & 0 deletions src/app/core/configurations/injection-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const DEFAULT_PRODUCT_LISTING_VIEW_TYPE = new InjectionToken<ViewType>('d
factory: () => environment.defaultProductListingViewType,
});

export const DEFAULT_PRODUCT_LISTING_VIEW_TYPE_MOBILE = new InjectionToken<ViewType>(
'defaultProductListingViewTypeMobile',
{
factory: () => environment.defaultProductListingViewTypeMobile,
}
);

/**
* the configured cookie consent options for the application
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Product Listing Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreStoreModule.forTesting(['router'], [ProductListingEffects]),
CoreStoreModule.forTesting(['router', 'configuration'], [ProductListingEffects]),
RouterTestingModule.withRoutes([{ path: 'some', children: [] }]),
ShoppingStoreModule.forTesting('productListing'),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { Inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store, select } from '@ngrx/store';
import { isEqual } from 'lodash-es';
import { distinctUntilChanged, map, switchMap, take } from 'rxjs/operators';
import { distinctUntilChanged, filter, map, switchMap, take, withLatestFrom } from 'rxjs/operators';

import {
DEFAULT_PRODUCT_LISTING_VIEW_TYPE,
DEFAULT_PRODUCT_LISTING_VIEW_TYPE_MOBILE,
PRODUCT_LISTING_ITEMS_PER_PAGE,
} from 'ish-core/configurations/injection-keys';
import { ViewType } from 'ish-core/models/viewtype/viewtype.types';
import { getDeviceType } from 'ish-core/store/core/configuration';
import { selectQueryParam, selectQueryParams } from 'ish-core/store/core/router';
import {
applyFilter,
Expand All @@ -35,6 +37,7 @@ export class ProductListingEffects {
constructor(
@Inject(PRODUCT_LISTING_ITEMS_PER_PAGE) private itemsPerPage: number,
@Inject(DEFAULT_PRODUCT_LISTING_VIEW_TYPE) private defaultViewType: ViewType,
@Inject(DEFAULT_PRODUCT_LISTING_VIEW_TYPE_MOBILE) private defaultViewTypeMobile: ViewType,
private actions$: Actions,
private store: Store
) {}
Expand All @@ -48,9 +51,15 @@ export class ProductListingEffects {

initializeDefaultViewType$ = createEffect(() =>
this.store.pipe(
filter(() => !SSR),
select(getProductListingViewType),
whenFalsy(),
map(() => setViewType({ viewType: this.defaultViewType }))
withLatestFrom(this.store.pipe(select(getDeviceType))),
map(([, deviceType]) =>
setViewType(
deviceType === 'mobile' ? { viewType: this.defaultViewTypeMobile } : { viewType: this.defaultViewType }
)
)
)
);

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/store/shopping/search/search.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Search Effects', () => {

TestBed.configureTestingModule({
imports: [
CoreStoreModule.forTesting(['router'], [SearchEffects, ProductListingEffects]),
CoreStoreModule.forTesting(['router', 'configuration'], [SearchEffects, ProductListingEffects]),
RouterTestingModule.withRoutes([
{ path: 'error', children: [] },
{ path: 'search/:searchTerm', children: [] },
Expand Down
2 changes: 2 additions & 0 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface Environment {

// default viewType used for product listings
defaultProductListingViewType: ViewType;
defaultProductListingViewTypeMobile: ViewType;

// default device type used for initial page responses
defaultDeviceType: DeviceType;
Expand Down Expand Up @@ -145,6 +146,7 @@ export const ENVIRONMENT_DEFAULTS: Omit<Environment, 'icmChannel'> = {
master: 6,
},
defaultProductListingViewType: 'grid',
defaultProductListingViewTypeMobile: 'grid',
defaultDeviceType: 'mobile',
multiSiteLocaleMap: {
en_US: '/en',
Expand Down