signal-desktop/ts/state/selectors/username.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-10-18 17:12:02 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import type { UsernameReservationType } from '../../types/Username';
import type { StateType } from '../reducer';
import type {
UsernameStateType,
UsernameReservationStateType,
} from '../ducks/username';
import type {
UsernameEditState,
2023-07-20 03:14:08 +00:00
UsernameLinkState,
2022-10-18 17:12:02 +00:00
UsernameReservationState,
UsernameReservationError,
} from '../ducks/usernameEnums';
export const getUsernameState = (state: StateType): UsernameStateType =>
state.username;
export const getUsernameEditState = createSelector(
getUsernameState,
(state: UsernameStateType): UsernameEditState => state.editState
);
2023-07-20 03:14:08 +00:00
export const getUsernameLinkState = createSelector(
getUsernameState,
(state: UsernameStateType): UsernameLinkState => state.linkState
);
2022-10-18 17:12:02 +00:00
export const getUsernameReservation = createSelector(
getUsernameState,
(state: UsernameStateType): UsernameReservationStateType =>
state.usernameReservation
);
export const getUsernameReservationState = createSelector(
getUsernameReservation,
(reservation: UsernameReservationStateType): UsernameReservationState =>
reservation.state
);
export const getUsernameReservationObject = createSelector(
getUsernameReservation,
(
reservation: UsernameReservationStateType
): UsernameReservationType | undefined => reservation.reservation
);
export const getUsernameReservationError = createSelector(
getUsernameReservation,
(
reservation: UsernameReservationStateType
): UsernameReservationError | undefined => reservation.error
);
2024-02-06 18:35:59 +00:00
export const getRecoveredUsername = createSelector(
getUsernameReservation,
(reservation: UsernameReservationStateType): string | undefined =>
reservation.recoveredUsername
);