Skip to content

Commit

Permalink
fix: prevent flickering of product page when switching to another pro…
Browse files Browse the repository at this point in the history
…duct detail page
  • Loading branch information
dhhyi committed Feb 16, 2021
1 parent bfa6647 commit 2b27cb8
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/app/core/directives/product-context.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class ProductContextDirective implements OnInit, OnChanges {
@Input()
set parts(parts: SkuQuantityType[]) {
this.context.set('parts', () => parts);
this.context.set('displayProperties', () => ({
readOnly: true,
addToBasket: true,
}));
}

@Input()
Expand Down
4 changes: 0 additions & 4 deletions src/app/core/facades/product-context.facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ describe('Product Context Facade', () => {
Object {
"allowZeroQuantity": false,
"categoryId": null,
"displayProperties": Object {
"addToBasket": true,
"readOnly": true,
},
"propagateActive": true,
"requiredCompletenessLevel": 2,
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/core/facades/product-context.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ export class ProductContextFacade extends RxState<ProductContext> {
requiredCompletenessLevel: ProductCompletenessLevel.List,
propagateActive: true,
allowZeroQuantity: false,
displayProperties: {
readOnly: true,
addToBasket: true,
},
// tslint:disable-next-line: no-null-keyword
categoryId: null,
});
Expand Down Expand Up @@ -332,6 +328,11 @@ export class ProductContextFacade extends RxState<ProductContext> {
current[index] = childState;
return current;
});
this.set('displayProperties', state => ({
...state.displayProperties,
readOnly: true,
addToBasket: true,
}));
}

validDebouncedQuantityUpdate$(time = 800) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row">
<div *ngIf="product$ | async" class="row">
<div class="col-lg-3 d-none d-lg-block">
<div class="product-img-thumbs" data-type="S">
<div class="product-thumb-set" [ngClass]="{ active: isActiveSlide(0) }" (click)="setActiveSlide(0)">
Expand Down
15 changes: 11 additions & 4 deletions src/app/pages/product/product-images/product-images.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
import { NgbCarousel } from '@ng-bootstrap/ng-bootstrap';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { ProductHelper } from 'ish-core/models/product/product.model';
import { AnyProductViewType, ProductHelper } from 'ish-core/models/product/product.model';

/**
* The Product Images Component
Expand All @@ -19,15 +20,21 @@ import { ProductHelper } from 'ish-core/models/product/product.model';
templateUrl: './product-images.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ProductImagesComponent {
export class ProductImagesComponent implements OnInit {
@ViewChild('carousel') carousel: NgbCarousel;

activeSlide = '0';

product$: Observable<AnyProductViewType>;

constructor(private context: ProductContextFacade) {}

ngOnInit() {
this.product$ = this.context.select('product');
}

getImageViewIDsExcludePrimary$(imageType: string) {
return this.context.select('product').pipe(map(p => ProductHelper.getImageViewIDsExcludePrimary(p, imageType)));
return this.product$.pipe(map(p => ProductHelper.getImageViewIDsExcludePrimary(p, imageType)));
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/app/pages/product/product-page.component.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<div class="clearfix" data-testing-id="product-detail-page" itemscope itemtype="http://schema.org/Product">
<ish-loading *ngIf="productLoading$ | async; else productDetail"></ish-loading>
<ish-loading *ngIf="productLoading$ | async"></ish-loading>

<ng-template #productDetail>
<ish-breadcrumb></ish-breadcrumb>
<ish-breadcrumb></ish-breadcrumb>

<ish-product-detail></ish-product-detail>
<ish-product-detail></ish-product-detail>

<ish-product-master-variations></ish-product-master-variations>
<ish-product-master-variations></ish-product-master-variations>

<ish-product-bundle-parts></ish-product-bundle-parts>
<ish-product-bundle-parts></ish-product-bundle-parts>

<ish-retail-set-parts></ish-retail-set-parts>
<ish-retail-set-parts></ish-retail-set-parts>

<ish-product-links></ish-product-links>
</ng-template>
<ish-product-links></ish-product-links>
</div>

<ng-container *ishFeature="'recently'"> <ish-recently-viewed></ish-recently-viewed> </ng-container>
<ng-container *ishFeature="'recently'"
><ish-recently-viewed *ngIf="!(productLoading$ | async)"></ish-recently-viewed
></ng-container>
7 changes: 1 addition & 6 deletions src/app/pages/product/product-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ describe('Product Page Component', () => {

fixture.detectChanges();

expect(findAllCustomElements(element)).toMatchInlineSnapshot(`
Array [
"ish-loading",
"ish-recently-viewed",
]
`);
expect(findAllCustomElements(element)).toContain('ish-loading');
});

it('should display product page components when product is available', () => {
Expand Down

1 comment on commit 2b27cb8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Demo Servers are available:

Please sign in to comment.