mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +00:00
[PM-17673] - fix loading state for vault popup items service (#13711)
* fix loading state for vault popup items service * fix tests * add fallback in collectPageDetailsFromTab$ * add pageDetailsTimeout to autofill service
This commit is contained in:
@@ -1,7 +1,16 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import { filter, firstValueFrom, merge, Observable, ReplaySubject, scan, startWith } from "rxjs";
|
import {
|
||||||
import { pairwise } from "rxjs/operators";
|
filter,
|
||||||
|
firstValueFrom,
|
||||||
|
merge,
|
||||||
|
Observable,
|
||||||
|
ReplaySubject,
|
||||||
|
scan,
|
||||||
|
startWith,
|
||||||
|
timer,
|
||||||
|
} from "rxjs";
|
||||||
|
import { map, pairwise, share, takeUntil } from "rxjs/operators";
|
||||||
|
|
||||||
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
|
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
|
||||||
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
@@ -146,7 +155,19 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
pageDetailsFallback$.next([]);
|
pageDetailsFallback$.next([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return merge(pageDetailsFromTab$, pageDetailsFallback$);
|
// Share the pageDetailsFromTab$ observable so that multiple subscribers don't trigger multiple executions.
|
||||||
|
const sharedPageDetailsFromTab$ = pageDetailsFromTab$.pipe(share());
|
||||||
|
|
||||||
|
// Create a timeout observable that emits an empty array if pageDetailsFromTab$ hasn't emitted within 1 second.
|
||||||
|
const pageDetailsTimeout$ = timer(1000).pipe(
|
||||||
|
map(() => []),
|
||||||
|
takeUntil(sharedPageDetailsFromTab$),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Merge the responses so that if pageDetailsFromTab$ emits, that value is used.
|
||||||
|
// Otherwise, if it doesn't emit in time, the timeout observable emits an empty array.
|
||||||
|
// Also, pageDetailsFallback$ will emit in error cases.
|
||||||
|
return merge(sharedPageDetailsFromTab$, pageDetailsFallback$, pageDetailsTimeout$);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user