From c02dfbcf80c17759653ec8c1e14b022e0215a896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Gie=C3=9Fke?= Date: Wed, 16 Oct 2024 11:56:54 +0200 Subject: [PATCH] fix: implement requested changes - floating buttons changed to normal icon buttons and tooltip with text added - added a label in the wishlist list to indicate that the wishlist is shared - fixed the problems when the wishlist is no longer shared -> redirect to error page - fixed the problem with duplicate requests - added a separate state for the shared wishlist so that logged in users can use the link to the shared wishlist --- .../wishlists/facades/wishlists.facade.ts | 6 +++ .../guards/fetch-shared-wishlist.guard.ts | 41 +++++++++++++------ ...ccount-wishlist-detail-page.component.html | 26 ++++++------ .../account-wishlist-list.component.html | 2 + .../shared-wishlist-page.component.html | 3 -- .../shared-wishlist-page.component.ts | 23 +++++++---- .../store/wishlist/wishlist.effects.ts | 24 ++++++++++- .../store/wishlist/wishlist.reducer.ts | 24 ++++++++++- .../store/wishlist/wishlist.selectors.ts | 20 ++++++++- src/assets/i18n/en_US.json | 1 + 10 files changed, 130 insertions(+), 40 deletions(-) diff --git a/src/app/extensions/wishlists/facades/wishlists.facade.ts b/src/app/extensions/wishlists/facades/wishlists.facade.ts index 4809eac4d8..86d31882d8 100644 --- a/src/app/extensions/wishlists/facades/wishlists.facade.ts +++ b/src/app/extensions/wishlists/facades/wishlists.facade.ts @@ -16,6 +16,9 @@ import { getAllWishlistsItemsSkus, getPreferredWishlist, getSelectedWishlistDetails, + getSharedWishlist, + getSharedWishlistError, + getSharedWishlistLoading, getWishlistsError, getWishlistsLoading, moveItemToWishlist, @@ -35,6 +38,9 @@ export class WishlistsFacade { allWishlistsItemsSkus$: Observable = this.store.pipe(select(getAllWishlistsItemsSkus)); wishlistLoading$: Observable = this.store.pipe(select(getWishlistsLoading)); wishlistError$: Observable = this.store.pipe(select(getWishlistsError)); + sharedWishlist$: Observable = this.store.pipe(select(getSharedWishlist)); + sharedWishlistLoading$: Observable = this.store.pipe(select(getSharedWishlistLoading)); + sharedWishlistError$: Observable = this.store.pipe(select(getSharedWishlistError)); wishlistSelectOptions$(filterCurrent = true) { return this.wishlists$.pipe( diff --git a/src/app/extensions/wishlists/guards/fetch-shared-wishlist.guard.ts b/src/app/extensions/wishlists/guards/fetch-shared-wishlist.guard.ts index 812830e9c7..a9fedce74c 100644 --- a/src/app/extensions/wishlists/guards/fetch-shared-wishlist.guard.ts +++ b/src/app/extensions/wishlists/guards/fetch-shared-wishlist.guard.ts @@ -1,27 +1,42 @@ import { inject } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; -import { Store } from '@ngrx/store'; -import { Observable } from 'rxjs'; -import { map, tap } from 'rxjs/operators'; +import { Store, select } from '@ngrx/store'; +import { Observable, of } from 'rxjs'; +import { map, switchMap, tap } from 'rxjs/operators'; -import { wishlistActions } from '../store/wishlist'; +import { isSharedWishlistLoaded, isSharedWishlistLoading, wishlistActions } from '../store/wishlist'; /** * Fetch the shared wishlist */ export function fetchSharedWishlistGuard(route: ActivatedRouteSnapshot): boolean | Observable { const store = inject(Store); + const wishlistId = route.params.wishlistId; + const owner = route.queryParams.owner; + const secureCode = route.queryParams.secureCode; return store.pipe( - tap(() => { - store.dispatch( - wishlistActions.loadSharedWishlist({ - wishlistId: route.params.wishlistId, - owner: route.queryParams.owner, - secureCode: route.queryParams.secureCode, - }) + select(isSharedWishlistLoaded(wishlistId)), + switchMap(loaded => { + if (loaded) { + return of(true); + } + + return store.pipe( + select(isSharedWishlistLoading(wishlistId)), + tap(loading => { + if (!loading) { + store.dispatch( + wishlistActions.loadSharedWishlist({ + wishlistId, + owner, + secureCode, + }) + ); + } + }), + map(() => true) ); - }), - map(() => true) + }) ); } diff --git a/src/app/extensions/wishlists/pages/account-wishlist-detail/account-wishlist-detail-page.component.html b/src/app/extensions/wishlists/pages/account-wishlist-detail/account-wishlist-detail-page.component.html index e9d4447063..b8dd7bcc07 100644 --- a/src/app/extensions/wishlists/pages/account-wishlist-detail/account-wishlist-detail-page.component.html +++ b/src/app/extensions/wishlists/pages/account-wishlist-detail/account-wishlist-detail-page.component.html @@ -15,41 +15,41 @@ /> -