1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

[PM-6853] Recreate getUserStateOrDefault$ (#8374)

* Recreate getUserStateOrDefault$

* Update Tests
This commit is contained in:
Justin Baur
2024-03-18 14:59:06 -05:00
committed by GitHub
parent cc28149e60
commit a3f6b9eacb
2 changed files with 24 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { Observable, map, firstValueFrom } from "rxjs";
import { Observable, map, firstValueFrom, of, switchMap, take } from "rxjs";
import { KeyDefinition, PROVIDERS_DISK, StateProvider } from "../../platform/state";
import { UserId } from "../../types/guid";
@@ -18,9 +18,17 @@ export class ProviderService implements ProviderServiceAbstraction {
constructor(private stateProvider: StateProvider) {}
private providers$(userId?: UserId): Observable<Provider[] | undefined> {
return this.stateProvider
.getUserState$(PROVIDERS, userId)
.pipe(this.mapProviderRecordToArray());
// FIXME: Can be replaced with `getUserStateOrDefault$` if we weren't trying to pick this.
return (
userId != null
? this.stateProvider.getUser(userId, PROVIDERS).state$
: this.stateProvider.activeUserId$.pipe(
take(1),
switchMap((userId) =>
userId != null ? this.stateProvider.getUser(userId, PROVIDERS).state$ : of(null),
),
)
).pipe(this.mapProviderRecordToArray());
}
private mapProviderRecordToArray() {