Chore: Migrate selector/login to TS (#3731)

* migrate selector/login to TS

* Fix lint errors

* set aliases for returns
This commit is contained in:
Gerzon Z 2022-02-16 11:09:38 -04:00 committed by GitHub
parent f51ec9ef0c
commit 78da41d4f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 20 deletions

View File

@ -1,19 +0,0 @@
import { createSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
const getUser = state => {
if (!isEmpty(state.share?.user)) {
return state.share.user;
}
return state.login?.user;
};
const getLoginServices = state => state.login.services || {};
const getShowFormLoginSetting = state => state.settings.Accounts_ShowFormLogin || false;
const getIframeEnabledSetting = state => state.settings.Accounts_iframe_enabled || false;
export const getUserSelector = createSelector([getUser], user => user);
export const getShowLoginButton = createSelector(
[getLoginServices, getShowFormLoginSetting, getIframeEnabledSetting],
(loginServices, showFormLogin, iframeEnabled) => showFormLogin || Object.values(loginServices).length || iframeEnabled
);

32
app/selectors/login.ts Normal file
View File

@ -0,0 +1,32 @@
import { createSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import { IApplicationState } from '../definitions';
interface IServices {
facebook: { clientId: string };
github: { clientId: string };
gitlab: { clientId: string };
google: { clientId: string };
linkedin: { clientId: string };
'meteor-developer': { clientId: string };
wordpress: { clientId: string; serverURL: string };
}
const getUser = (state: IApplicationState) => {
if (!isEmpty(state.share?.user)) {
return state.share.user;
}
return state.login?.user;
};
const getLoginServices = (state: IApplicationState) => (state.login.services as IServices) || {};
const getShowFormLoginSetting = (state: IApplicationState) => (state.settings.Accounts_ShowFormLogin as boolean) || false;
const getIframeEnabledSetting = (state: IApplicationState) => (state.settings.Accounts_iframe_enabled as boolean) || false;
export const getUserSelector = createSelector([getUser], user => user);
export const getShowLoginButton = createSelector(
[getLoginServices, getShowFormLoginSetting, getIframeEnabledSetting],
(loginServices, showFormLogin, iframeEnabled) =>
(showFormLogin || Object.values(loginServices).length || iframeEnabled) as boolean
);

View File

@ -13,13 +13,14 @@ import { SWITCH_TRACK_COLOR } from '../../constants/colors';
import { getUserSelector } from '../../selectors/login';
import RocketChat from '../../lib/rocketchat';
import { ProfileStackParamList } from '../../stacks/types';
import { IApplicationState } from '../../definitions';
interface IUserPreferencesViewProps {
navigation: StackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
}
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
const { enableMessageParserEarlyAdoption, id } = useSelector(state => getUserSelector(state));
const { enableMessageParserEarlyAdoption, id } = useSelector((state: IApplicationState) => getUserSelector(state));
const dispatch = useDispatch();
useEffect(() => {