Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cc56203

Browse filesBrowse files
authored
Search/integrate ngrx (aviabird#322)
### Why? - In order to optimise the search components. We needed redux integration in search. ### This change addresses the need by :- - Upgrades ngrx to v7+. - Creates and integrates a search store with the search module. - Updates search resolver to work with store. - Adds product svg placeholder, while loading.
1 parent 9ca7826 commit cc56203
Copy full SHA for cc56203

44 files changed

+670-249Lines changed: 670 additions & 249 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"@angular/router": "^7.1.3",
4545
"@angular/service-worker": "^7.1.3",
4646
"@ngrx/core": "^1.2.0",
47-
"@ngrx/effects": "^6.1.2",
48-
"@ngrx/entity": "^6.1.2",
49-
"@ngrx/store": "^6.1.2",
47+
"@ngrx/effects": "^7.0.0",
48+
"@ngrx/entity": "^7.0.0",
49+
"@ngrx/store": "^7.0.0",
5050
"@ngu/carousel": "^1.5.4",
5151
"@nguniversal/common": "^7.0.2",
5252
"@nguniversal/express-engine": "^7.0.2",
Collapse file

‎src/app/app.reducers.ts‎

Copy file name to clipboardExpand all lines: src/app/app.reducers.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fromProduct from './product/reducers/product-reducer';
33
import * as fromUser from './user/reducers/user.reducer';
44
import * as fromCheckout from './checkout/reducers/checkout.reducer';
55
import * as fromAuth from './auth/reducers/auth.reducer';
6+
import * as fromSearch from './modules/search/store/reducers/search.reducer';
67
import {Action} from '@ngrx/store';
78

89
/**
@@ -38,7 +39,8 @@ export const reducers: ActionReducerMap<State> = {
3839
products: fromProduct.reducer,
3940
auth: fromAuth.reducer,
4041
checkout: fromCheckout.reducer,
41-
users: fromUser.reducer
42+
users: fromUser.reducer,
43+
search: fromSearch.reducer
4244
};
4345

4446
// console.log all actions
Collapse file

‎src/app/auth/effects/auth.effects.ts‎

Copy file name to clipboardExpand all lines: src/app/auth/effects/auth.effects.ts
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { User } from './../../core/models/user';
22
import { filter, switchMap, map } from 'rxjs/operators';
33
import { Injectable } from '@angular/core';
4-
import { Actions, Effect } from '@ngrx/effects';
4+
import { Actions, Effect, ofType } from '@ngrx/effects';
55
import { Action } from '@ngrx/store';
66
import { AuthService } from '../../core/services/auth.service';
77
import { AuthActions } from '../actions/auth.actions';
@@ -14,17 +14,17 @@ export class AuthenticationEffects {
1414

1515
@Effect()
1616
Authorized$: Observable<Action> = this.actions$
17-
.ofType(AuthActions.AUTHORIZE)
1817
.pipe(
18+
ofType(AuthActions.AUTHORIZE),
1919
switchMap(() => this.authService.authorized()),
2020
filter(data => data.error !== 'unauthenticated'),
2121
map(() => this.authActions.loginSuccess())
2222
);
2323

2424
@Effect()
2525
OAuthLogin: Observable<Action> = this.actions$
26-
.ofType(AuthActions.O_AUTH_LOGIN)
2726
.pipe(
27+
ofType(AuthActions.O_AUTH_LOGIN),
2828
switchMap<Action & { payload: string }, string | User>(action => {
2929
return this.authService.socialLogin(action.payload);
3030
}),
@@ -40,20 +40,22 @@ export class AuthenticationEffects {
4040

4141
@Effect()
4242
AfterLogoutSuccess$: Observable<Action> = this.actions$
43-
.ofType(AuthActions.LOGOUT_SUCCESS)
4443
.pipe(
44+
ofType(AuthActions.LOGOUT_SUCCESS),
4545
map(_ => this.checkoutActions.orderCompleteSuccess())
4646
);
4747

4848
// ToDo
4949
// Needs to move in seprate effects.
5050
@Effect()
51-
GetRatingCategories$ = this.actions$.ofType(AuthActions.GET_RATING_CATEGEORY).pipe(
52-
switchMap<Action, Array<RatingCategory>>(_ => {
53-
return this.authService.getRatingCategories();
54-
}),
55-
map(ratingCategory => this.authActions.getRatingCategoriesSuccess(ratingCategory))
56-
);
51+
GetRatingCategories$ = this.actions$
52+
.pipe(
53+
ofType(AuthActions.GET_RATING_CATEGEORY),
54+
switchMap<Action, Array<RatingCategory>>(_ => {
55+
return this.authService.getRatingCategories();
56+
}),
57+
map(ratingCategory => this.authActions.getRatingCategoriesSuccess(ratingCategory))
58+
);
5759

5860
constructor(
5961
private actions$: Actions,
Collapse file

‎src/app/checkout/effects/checkout.effects.ts‎

Copy file name to clipboardExpand all lines: src/app/checkout/effects/checkout.effects.ts
+57-47Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Action } from '@ngrx/store';
33
import { map, switchMap } from 'rxjs/operators';
44
import { CheckoutService } from './../../core/services/checkout.service';
55
import { CheckoutActions } from './../actions/checkout.actions';
6-
import { Effect, Actions } from '@ngrx/effects';
6+
import { Effect, Actions, ofType } from '@ngrx/effects';
77
import { Injectable } from '@angular/core';
88
import { Order } from '../../core/models/order';
99
import { AddressService } from '../address/services/address.service';
@@ -15,62 +15,72 @@ export class CheckoutEffects {
1515
isBuyNowAction: boolean;
1616

1717
@Effect()
18-
AddToCart$ = this.actions$.ofType(CheckoutActions.ADD_TO_CART).pipe(
19-
switchMap<Action & { payload: { variant_id: number, quantity: number, isBuyNow: boolean } }, Order>(action => {
20-
this.isBuyNowAction = action.payload.isBuyNow;
21-
return this.checkoutService.createNewLineItem(
22-
action.payload.variant_id,
23-
action.payload.quantity
24-
);
25-
}),
26-
map(order => {
27-
if (this.isBuyNowAction) {
28-
this.router.navigate(['checkout', 'cart'])
29-
}
30-
return this.actions.fetchCurrentOrderSuccess(order)
31-
})
32-
);
18+
AddToCart$ = this.actions$
19+
.pipe(
20+
ofType(CheckoutActions.ADD_TO_CART),
21+
switchMap<Action & { payload: { variant_id: number, quantity: number, isBuyNow: boolean } }, Order>(action => {
22+
this.isBuyNowAction = action.payload.isBuyNow;
23+
return this.checkoutService.createNewLineItem(
24+
action.payload.variant_id,
25+
action.payload.quantity
26+
);
27+
}),
28+
map(order => {
29+
if (this.isBuyNowAction) {
30+
this.router.navigate(['checkout', 'cart'])
31+
}
32+
return this.actions.fetchCurrentOrderSuccess(order)
33+
})
34+
);
3335

3436
@Effect()
35-
OrderDetails$ = this.actions$.ofType(CheckoutActions.GET_ORDER_DETAILS).pipe(
36-
switchMap<Action, Order>(_ => this.checkoutService.getOrder()),
37-
map(order => this.actions.fetchCurrentOrderSuccess(order))
38-
);
37+
OrderDetails$ = this.actions$
38+
.pipe(
39+
ofType(CheckoutActions.GET_ORDER_DETAILS),
40+
switchMap<Action, Order>(_ => this.checkoutService.getOrder()),
41+
map(order => this.actions.fetchCurrentOrderSuccess(order))
42+
);
3943

4044

4145
@Effect()
42-
BindAddress$ = this.actions$.ofType(CheckoutActions.BIND_ADDRESS).pipe(
43-
switchMap<Action & { payload: { address: Address, orderId: number } }, Order>(action => {
44-
return this.addressService.
45-
bindAddressToOrder(action.payload.address, action.payload.orderId);
46-
}),
47-
map(order => this.actions.fetchCurrentOrderSuccess(order))
48-
);
46+
BindAddress$ = this.actions$
47+
.pipe(
48+
ofType(CheckoutActions.BIND_ADDRESS),
49+
switchMap<Action & { payload: { address: Address, orderId: number } }, Order>(action => {
50+
return this.addressService.
51+
bindAddressToOrder(action.payload.address, action.payload.orderId);
52+
}),
53+
map(order => this.actions.fetchCurrentOrderSuccess(order))
54+
);
4955

5056

5157
@Effect()
52-
BindPayment$ = this.actions$.ofType(CheckoutActions.BIND_PAYMENT).pipe(
53-
switchMap<Action & { payload: { paymentMethodId: number, orderId: number, orderAmount: number } }, Order>(action => {
54-
return this.paymentService.addPaymentToOrder(
55-
action.payload.paymentMethodId,
56-
action.payload.orderId,
57-
action.payload.orderAmount);
58-
}),
59-
map(order => this.actions.getOrderPaymentsSuccess(order))
60-
);
58+
BindPayment$ = this.actions$
59+
.pipe(
60+
ofType(CheckoutActions.BIND_PAYMENT),
61+
switchMap<Action & { payload: { paymentMethodId: number, orderId: number, orderAmount: number } }, Order>(action => {
62+
return this.paymentService.addPaymentToOrder(
63+
action.payload.paymentMethodId,
64+
action.payload.orderId,
65+
action.payload.orderAmount);
66+
}),
67+
map(order => this.actions.getOrderPaymentsSuccess(order))
68+
);
6169

6270
@Effect()
63-
ShippingPreferencess$ = this.actions$.ofType(CheckoutActions.SHIPPING_PREFERENCES).pipe(
64-
switchMap<Action & { payload: { orderId: number, packages: Array<{}> } }, Order>(action => {
65-
return this.checkoutService.saveShippingPreferences(
66-
action.payload.orderId,
67-
action.payload.packages);
68-
}),
69-
map(order => {
70-
this.router.navigate(['/checkout', 'payment'])
71-
return this.actions.fetchCurrentOrderSuccess(order)
72-
})
73-
);
71+
ShippingPreferencess$ = this.actions$
72+
.pipe(
73+
ofType(CheckoutActions.SHIPPING_PREFERENCES),
74+
switchMap<Action & { payload: { orderId: number, packages: Array<{}> } }, Order>(action => {
75+
return this.checkoutService.saveShippingPreferences(
76+
action.payload.orderId,
77+
action.payload.packages);
78+
}),
79+
map(order => {
80+
this.router.navigate(['/checkout', 'payment'])
81+
return this.actions.fetchCurrentOrderSuccess(order)
82+
})
83+
);
7484

7585
constructor(
7686
private actions$: Actions,
Collapse file

‎src/app/interfaces.ts‎

Copy file name to clipboardExpand all lines: src/app/interfaces.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SearchState } from './modules/search/store/states/search.state';
12
import { ProductState } from './product/reducers/product-state';
23
import { AuthState } from './auth/reducers/auth.state';
34
import { UserState } from './user/reducers/user.state';
@@ -17,4 +18,5 @@ export interface AppState {
1718
auth: AuthState;
1819
checkout: CheckoutState;
1920
users: UserState;
21+
search: SearchState;
2022
}
Collapse file

‎src/app/modules/search/components/filter-summary-container/components/filter-summary-filter-list/filter-summary-filter-list.component.html‎

Copy file name to clipboardExpand all lines: src/app/modules/search/components/filter-summary-container/components/filter-summary-filter-list/filter-summary-filter-list.component.html
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div class="col-12">
22
<div class="row">
33
<div *ngFor="let filter of filterList">
4-
<app-filter-summary-filter class="border" [filter]="filter">
4+
<app-filter-summary-filter
5+
class="border"
6+
[filter]="filter">
57
</app-filter-summary-filter>
68
</div>
79
</div>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
<span>{{filter}}</span>
2-
<span class="ml-2" (click)="removeFilterClicked()">X</span>
2+
<span
3+
class="ml-2"
4+
(click)="removeFilterClicked()">
5+
X
6+
</span>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
<div class="btn-group float-right" dropdown triggers="mouseover">
2-
<button id="button-basic" dropdownToggle type="button" class="btn dropdown-toggle border text-secondary float-right text-left"
1+
<div
2+
class="btn-group float-right"
3+
dropdown
4+
triggers="mouseover">
5+
<button
6+
id="button-basic"
7+
dropdownToggle
8+
type="button"
9+
class="btn dropdown-toggle border text-secondary float-right text-left"
310
aria-controls="dropdown-basic">
4-
Sort by: <b class="px-2">{{currentSort.name}}</b> <span class="caret"></span>
11+
Sort by:
12+
<b class="px-2">{{currentSort.name}}</b>
13+
<span class="caret"></span>
514
</button>
6-
<ul id="dropdown-basic" *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="button-basic">
7-
<li role="menuitem" *ngFor="let sortOption of sortConfig">
8-
<a class="dropdown-item" (click)="sortOrder(sortOption)">{{sortOption.name}}</a>
15+
<ul
16+
id="dropdown-basic"
17+
*dropdownMenu
18+
class="dropdown-menu"
19+
role="menu"
20+
aria-labelledby="button-basic">
21+
<li
22+
role="menuitem"
23+
*ngFor="let sortOption of sortConfig">
24+
<a
25+
class="dropdown-item"
26+
(click)="sortOrder(sortOption)">
27+
{{sortOption.name}}
28+
</a>
929
</li>
1030
</ul>
1131
</div>
Collapse file

‎src/app/modules/search/components/filter-summary-container/filter-summary-container.component.html‎

Copy file name to clipboardExpand all lines: src/app/modules/search/components/filter-summary-container/filter-summary-container.component.html
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="col-8">
33
<app-filter-summary-filter-list [appliedParams]="appliedParams"></app-filter-summary-filter-list>
44
</div>
5-
<app-filter-summary-sort-by class="col-4" (selectedSort)="filterUpdated($event)"></app-filter-summary-sort-by>
5+
<app-filter-summary-sort-by
6+
class="col-4"
7+
(selectedSort)="filterUpdated($event)"></app-filter-summary-sort-by>
68
</section>
7-
Collapse file
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
<ul class="list-group border border-left-0 border-bottom-0 py-3" *ngIf="showFilter">
1+
<ul
2+
class="list-group border border-left-0 border-bottom-0 py-3"
3+
*ngIf="showFilter">
24
<small class="font-weight-bold pb-3 text-uppercase">{{filter.id}}</small>
3-
<li *ngFor="let filterValue of filter.values | slice: skipCount;" class="list-group-item border-0 p-0">
5+
<li
6+
*ngFor="let filterValue of filter.values | slice: skipCount;"
7+
class="list-group-item border-0 p-0">
48
<div class="custom-control custom-checkbox">
5-
<input type="checkbox" class="custom-control-input" id="{{filterValue.id}}" [ngModel]="isSelected(filterValue.id)" (change)="selectedItem(filterValue.id)">
6-
<label class="custom-control-label text-capitalize" for="{{filterValue.id}}">{{filterValue.id}}</label>
7-
<small class="text-secondary font-weight-light"> ( {{filterValue.count}} ) </small>
9+
<input
10+
type="checkbox"
11+
class="custom-control-input"
12+
id="{{filterValue.id}}"
13+
[ngModel]="isSelected(filterValue.id)"
14+
(change)="selectedItem(filterValue.id)">
15+
<label
16+
class="custom-control-label text-capitalize"
17+
for="{{filterValue.id}}">
18+
{{filterValue.id}}
19+
</label>
20+
<small class="text-secondary font-weight-light">( {{filterValue.count}} )</small>
821
</div>
922
</li>
1023
</ul>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.