1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 21:33:27 +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:
Jordan Aasen
2024-09-27 04:38:50 -07:00
committed by GitHub
parent ff57c72df5
commit 739c76a24f
5 changed files with 19 additions and 7 deletions

View File

@@ -62,9 +62,15 @@ describe("SendItemsService", () => {
it("should update loading$ when sends are loading", (done) => {
const sendsLoading$ = new Subject<void>();
(service as any)._sendsLoading$ = sendsLoading$;
let sendLoadingIndex = 0;
service.loading$.subscribe((loading) => {
expect(loading).toBe(true);
done();
if (sendLoadingIndex === 0) {
expect(loading).toBe(true);
sendLoadingIndex++;
} else {
expect(loading).toBe(false);
done();
}
});
sendsLoading$.next();

View File

@@ -5,6 +5,7 @@ import {
distinctUntilChanged,
from,
map,
merge,
Observable,
shareReplay,
startWith,
@@ -47,7 +48,9 @@ export class SendItemsService {
this._searchText$,
this.sendListFiltersService.filterFunction$,
]).pipe(
tap(() => this._sendsLoading$.next()),
tap(() => {
this._sendsLoading$.next();
}),
map(([sends, searchText, filterFunction]): [SendView[], string] => [
filterFunction(sends),
searchText,
@@ -60,9 +63,10 @@ export class SendItemsService {
/**
* Observable that indicates whether the service is currently loading sends.
*/
loading$: Observable<boolean> = this._sendsLoading$
.pipe(map(() => true))
.pipe(startWith(true), distinctUntilChanged(), shareReplay({ refCount: false, bufferSize: 1 }));
loading$: Observable<boolean> = merge(
this._sendsLoading$.pipe(map(() => true)),
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.