Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / pass / store / request / selectors.ts
blobfaec2abc8ff281d85910712cc7c341d687ded39b
1 import { createSelector } from '@reduxjs/toolkit';
3 import type { Maybe, MaybeNull } from '@proton/pass/types';
5 import type { RequestEntry, RequestState, RequestStatus } from './types';
7 export const selectRequest =
8     (namespaceOrId: string) =>
9     ({ request }: { request: RequestState }): Maybe<RequestEntry<RequestStatus>> =>
10         request?.[namespaceOrId];
12 export const selectRequestInFlight = (namespaceOrId: string) =>
13     createSelector(selectRequest(namespaceOrId), (request): boolean => Boolean(request?.status === 'start'));
15 export const selectRequestInFlightData = <D>(namespaceOrId: string) =>
16     createSelector(selectRequest(namespaceOrId), (request): MaybeNull<D> => {
17         if (request?.status === 'start') return request?.data ?? null;
18         return null;
19     });