signal-desktop/ts/state/selectors/network.ts
Jamie Kyle 27b55e472d
Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
2024-03-13 13:44:13 -07:00

57 lines
1.4 KiB
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import type { StateType } from '../reducer';
import type { NetworkStateType } from '../ducks/network';
import { isDone } from '../../util/registration';
import { SocketStatus } from '../../types/SocketStatus';
const getNetwork = (state: StateType): NetworkStateType => state.network;
export const getNetworkIsOnline = createSelector(
getNetwork,
({ isOnline }) => isOnline
);
export const getNetworkIsOutage = createSelector(
getNetwork,
({ isOutage }) => isOutage
);
export const getNetworkSocketStatus = createSelector(
getNetwork,
({ socketStatus }) => socketStatus
);
export const hasNetworkDialog = createSelector(
getNetwork,
isDone,
(
{
isOnline,
isOutage,
socketStatus,
withinConnectingGracePeriod,
}: NetworkStateType,
isRegistrationDone: boolean
): boolean =>
isRegistrationDone &&
(!isOnline ||
isOutage ||
(socketStatus === SocketStatus.CONNECTING &&
!withinConnectingGracePeriod) ||
socketStatus === SocketStatus.CLOSED ||
socketStatus === SocketStatus.CLOSING)
);
export const getChallengeStatus = createSelector(
getNetwork,
({ challengeStatus }) => challengeStatus
);
export const isChallengePending = createSelector(
getNetwork,
({ challengeStatus }) => challengeStatus === 'pending'
);