Skip to content

Commit

Permalink
Disable Chat-button if isMe
Browse files Browse the repository at this point in the history
  • Loading branch information
rottabonus committed Nov 4, 2023
1 parent 141be8a commit bc1d91e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Screens/Main/MentorCardExpanded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';

import * as mentorApi from '../../api/mentors';
import * as buddyState from '../../state/reducers/buddies';
import * as tokenState from '../../state/reducers/accessToken';
import { useSelector } from 'react-redux';

import MentorTitle from '../components/MentorTitle';
Expand Down Expand Up @@ -38,6 +39,7 @@ type Props = OwnProps;

const MentorCardExpanded = ({ navigation, route }: Props) => {
const mentor = route.params?.mentor;
const isMe = useSelector(tokenState.isMe(mentor.buddyId));
const didNavigateFromChat = route.params?.didNavigateFromChat;
const isBuddy = useSelector(buddyState.getIsBuddy(mentor.buddyId));
const shouldNavigateBack = didNavigateFromChat && isBuddy;
Expand Down Expand Up @@ -99,7 +101,7 @@ const MentorCardExpanded = ({ navigation, route }: Props) => {
style={styles.button}
onPress={shouldNavigateBack ? goBack : navigateToChat}
messageId="main.mentorCardExpanded.button"
disabled={isChatDisabled}
disabled={isChatDisabled || isMe}
/>
</SafeAreaView>
</RN.ScrollView>
Expand Down
4 changes: 4 additions & 0 deletions src/state/reducers/accessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const isMentor = flow(
O.toUndefined,
id => !!id,
);
export const isMe = (mentorId: string) => (appState: AppState) => {
const userId = getUserId(appState);
return userId === mentorId;
};

export function withToken<A>(
task: (token: authApi.AccessToken) => T.Task<A>,
Expand Down

0 comments on commit bc1d91e

Please sign in to comment.