diff --git a/native/profile/build-info.react.js b/native/profile/build-info.react.js index 3d096ccf6..88d31f6fc 100644 --- a/native/profile/build-info.react.js +++ b/native/profile/build-info.react.js @@ -1,121 +1,117 @@ // @flow import * as React from 'react'; import { View, Text, ScrollView } from 'react-native'; -import { useSelector } from 'react-redux'; - -import { isStaff } from 'lib/shared/user-utils'; import { persistConfig, codeVersion } from '../redux/persist'; import { StaffContext } from '../staff/staff-context'; import { useStyles } from '../themes/colors'; -import { isStaffRelease, useStaffCanSee } from '../utils/staff-utils'; +import { + isStaffRelease, + useIsCurrentUserStaff, + useStaffCanSee, +} from '../utils/staff-utils'; // eslint-disable-next-line no-unused-vars function BuildInfo(props: { ... }): React.Node { - const isCurrentUserStaff = useSelector( - state => - state.currentUserInfo && - state.currentUserInfo.id && - isStaff(state.currentUserInfo.id), - ); + const isCurrentUserStaff = useIsCurrentUserStaff(); const { staffUserHasBeenLoggedIn } = React.useContext(StaffContext); const styles = useStyles(unboundStyles); const staffCanSee = useStaffCanSee(); let staffCanSeeRows; if (staffCanSee || staffUserHasBeenLoggedIn) { staffCanSeeRows = ( <> __DEV__ {__DEV__ ? 'TRUE' : 'FALSE'} Staff Release {isStaffRelease ? 'TRUE' : 'FALSE'} isCurrentUserStaff {isCurrentUserStaff ? 'TRUE' : 'FALSE'} hasStaffUserLoggedIn {staffUserHasBeenLoggedIn ? 'TRUE' : 'FALSE'} ); } return ( Code version {codeVersion} State version {persistConfig.version} {staffCanSeeRows} Thank you for using Comm! ); } const unboundStyles = { label: { color: 'panelForegroundTertiaryLabel', fontSize: 16, paddingRight: 12, }, releaseText: { color: 'orange', fontSize: 16, }, row: { flexDirection: 'row', justifyContent: 'space-between', paddingVertical: 6, }, scrollView: { backgroundColor: 'panelBackground', }, scrollViewContentContainer: { paddingTop: 24, }, section: { backgroundColor: 'panelForeground', borderBottomWidth: 1, borderColor: 'panelForegroundBorder', borderTopWidth: 1, marginBottom: 24, paddingHorizontal: 24, paddingVertical: 6, }, text: { color: 'panelForegroundLabel', fontSize: 16, }, thanksText: { color: 'panelForegroundLabel', flex: 1, fontSize: 16, textAlign: 'center', }, }; export default BuildInfo; diff --git a/native/staff/staff-context.provider.react.js b/native/staff/staff-context.provider.react.js index f124bbc00..d75c650b2 100644 --- a/native/staff/staff-context.provider.react.js +++ b/native/staff/staff-context.provider.react.js @@ -1,44 +1,37 @@ // @flow import * as React from 'react'; -import { useSelector } from 'react-redux'; - -import { isStaff } from 'lib/shared/user-utils'; +import { useIsCurrentUserStaff } from '../utils/staff-utils'; import { StaffContext, type StaffContextType } from './staff-context'; type Props = { +children: React.Node, }; function StaffContextProvider(props: Props): React.Node { const [ staffUserHasBeenLoggedIn, setStaffUserHasBeenLoggedIn, ] = React.useState(false); - const isCurrentUserStaff = useSelector( - state => - state.currentUserInfo && - state.currentUserInfo.id && - isStaff(state.currentUserInfo.id), - ); + const isCurrentUserStaff = useIsCurrentUserStaff(); React.useEffect(() => { if (isCurrentUserStaff) { setStaffUserHasBeenLoggedIn(true); } }, [isCurrentUserStaff]); const staffContextValue: StaffContextType = React.useMemo( () => ({ staffUserHasBeenLoggedIn }), [staffUserHasBeenLoggedIn], ); return ( {props.children} ); } export { StaffContextProvider }; diff --git a/native/utils/staff-utils.js b/native/utils/staff-utils.js index 3ac17d6dc..095b440d5 100644 --- a/native/utils/staff-utils.js +++ b/native/utils/staff-utils.js @@ -1,19 +1,24 @@ // @flow import { useSelector } from 'react-redux'; import { isStaff } from 'lib/shared/user-utils'; const isStaffRelease = false; -function useStaffCanSee(): boolean { +function useIsCurrentUserStaff(): boolean { const isCurrentUserStaff = useSelector( state => state.currentUserInfo && state.currentUserInfo.id && isStaff(state.currentUserInfo.id), ); + return isCurrentUserStaff; +} + +function useStaffCanSee(): boolean { + const isCurrentUserStaff = useIsCurrentUserStaff(); return __DEV__ || isStaffRelease || isCurrentUserStaff; } -export { isStaffRelease, useStaffCanSee }; +export { isStaffRelease, useIsCurrentUserStaff, useStaffCanSee };