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;