mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 06:43:35 +00:00
[PM-12704] - fix loading state for send list (#11264)
* fix loading state for send service * fix test * fix test and service
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<popup-page>
|
<popup-page [loading]="sendsLoading$ | async">
|
||||||
<popup-header slot="header" [pageTitle]="'send' | i18n">
|
<popup-header slot="header" [pageTitle]="'send' | i18n">
|
||||||
<ng-container slot="end">
|
<ng-container slot="end">
|
||||||
<tools-new-send-dropdown *ngIf="!sendsDisabled"></tools-new-send-dropdown>
|
<tools-new-send-dropdown *ngIf="!sendsDisabled"></tools-new-send-dropdown>
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ describe("SendV2Component", () => {
|
|||||||
{ id: "1", name: "Send A" },
|
{ id: "1", name: "Send A" },
|
||||||
{ id: "2", name: "Send B" },
|
{ id: "2", name: "Send B" },
|
||||||
] as SendView[]),
|
] as SendView[]),
|
||||||
|
loading$: of(false),
|
||||||
latestSearchText$: of(""),
|
latestSearchText$: of(""),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export class SendV2Component implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
protected listState: SendState | null = null;
|
protected listState: SendState | null = null;
|
||||||
protected sends$ = this.sendItemsService.filteredAndSortedSends$;
|
protected sends$ = this.sendItemsService.filteredAndSortedSends$;
|
||||||
|
protected sendsLoading$ = this.sendItemsService.loading$;
|
||||||
protected title: string = "allSends";
|
protected title: string = "allSends";
|
||||||
protected noItemIcon = NoSendsIcon;
|
protected noItemIcon = NoSendsIcon;
|
||||||
protected noResultsIcon = Icons.NoResults;
|
protected noResultsIcon = Icons.NoResults;
|
||||||
|
|||||||
@@ -62,9 +62,15 @@ describe("SendItemsService", () => {
|
|||||||
it("should update loading$ when sends are loading", (done) => {
|
it("should update loading$ when sends are loading", (done) => {
|
||||||
const sendsLoading$ = new Subject<void>();
|
const sendsLoading$ = new Subject<void>();
|
||||||
(service as any)._sendsLoading$ = sendsLoading$;
|
(service as any)._sendsLoading$ = sendsLoading$;
|
||||||
|
let sendLoadingIndex = 0;
|
||||||
service.loading$.subscribe((loading) => {
|
service.loading$.subscribe((loading) => {
|
||||||
expect(loading).toBe(true);
|
if (sendLoadingIndex === 0) {
|
||||||
done();
|
expect(loading).toBe(true);
|
||||||
|
sendLoadingIndex++;
|
||||||
|
} else {
|
||||||
|
expect(loading).toBe(false);
|
||||||
|
done();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sendsLoading$.next();
|
sendsLoading$.next();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
distinctUntilChanged,
|
distinctUntilChanged,
|
||||||
from,
|
from,
|
||||||
map,
|
map,
|
||||||
|
merge,
|
||||||
Observable,
|
Observable,
|
||||||
shareReplay,
|
shareReplay,
|
||||||
startWith,
|
startWith,
|
||||||
@@ -47,7 +48,9 @@ export class SendItemsService {
|
|||||||
this._searchText$,
|
this._searchText$,
|
||||||
this.sendListFiltersService.filterFunction$,
|
this.sendListFiltersService.filterFunction$,
|
||||||
]).pipe(
|
]).pipe(
|
||||||
tap(() => this._sendsLoading$.next()),
|
tap(() => {
|
||||||
|
this._sendsLoading$.next();
|
||||||
|
}),
|
||||||
map(([sends, searchText, filterFunction]): [SendView[], string] => [
|
map(([sends, searchText, filterFunction]): [SendView[], string] => [
|
||||||
filterFunction(sends),
|
filterFunction(sends),
|
||||||
searchText,
|
searchText,
|
||||||
@@ -60,9 +63,10 @@ export class SendItemsService {
|
|||||||
/**
|
/**
|
||||||
* Observable that indicates whether the service is currently loading sends.
|
* Observable that indicates whether the service is currently loading sends.
|
||||||
*/
|
*/
|
||||||
loading$: Observable<boolean> = this._sendsLoading$
|
loading$: Observable<boolean> = merge(
|
||||||
.pipe(map(() => true))
|
this._sendsLoading$.pipe(map(() => true)),
|
||||||
.pipe(startWith(true), distinctUntilChanged(), shareReplay({ refCount: false, bufferSize: 1 }));
|
this.filteredAndSortedSends$.pipe(map(() => false)),
|
||||||
|
).pipe(startWith(true), distinctUntilChanged(), shareReplay({ refCount: false, bufferSize: 1 }));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observable that indicates whether a filter is currently applied to the sends.
|
* Observable that indicates whether a filter is currently applied to the sends.
|
||||||
|
|||||||
Reference in New Issue
Block a user