Skip to content

Commit

Permalink
[PAY-1434] Dismiss keyboard on create chat screen row press (#3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Jun 12, 2023
1 parent c70e9fe commit 001007e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
33 changes: 20 additions & 13 deletions packages/mobile/src/screens/chat-screen/ChatUserListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useCallback } from 'react'

import type { User } from '@audius/common'
import {
chatActions,
accountSelectors,
chatSelectors,
ChatPermissionAction
ChatPermissionAction,
cacheUsersSelectors
} from '@audius/common'
import { useSelector } from 'audius-client/src/common/hooks/useSelector'
import { Text, View, TouchableOpacity } from 'react-native'
import { Text, View, TouchableOpacity, Keyboard } from 'react-native'
import { useDispatch } from 'react-redux'

import IconBlockMessages from 'app/assets/images/iconBlockMessages.svg'
Expand All @@ -22,6 +22,7 @@ import { makeStyles } from 'app/styles'
const { createChat } = chatActions
const { getCanCreateChat } = chatSelectors
const { getUserId } = accountSelectors
const { getUser } = cacheUsersSelectors

const messages = {
followsYou: 'Follows You',
Expand Down Expand Up @@ -150,23 +151,28 @@ const ctaToTextMap = {
}

type ChatUserListItemProps = {
user: User
userId: number
}

export const ChatUserListItem = ({ user }: ChatUserListItemProps) => {
export const ChatUserListItem = ({ userId }: ChatUserListItemProps) => {
const styles = useStyles()
const dispatch = useDispatch()
const user = useSelector((state) => getUser(state, { id: userId }))
const currentUserId = useSelector(getUserId)
const { callToAction, canCreateChat } = useSelector((state) =>
getCanCreateChat(state, { userId: user.user_id })
getCanCreateChat(state, { userId: user?.user_id })
)

const handlePress = useCallback(() => {
dispatch(createChat({ userIds: [user.user_id] }))
}, [dispatch, user.user_id])
if (user?.user_id) {
Keyboard.dismiss()
dispatch(createChat({ userIds: [user.user_id] }))
}
}, [dispatch, user?.user_id])

const handleNotPermittedPress = useCallback(() => {
if (user.user_id) {
if (user?.user_id) {
Keyboard.dismiss()
dispatch(
setVisibility({
drawer: 'InboxUnavailable',
Expand All @@ -175,10 +181,11 @@ export const ChatUserListItem = ({ user }: ChatUserListItemProps) => {
})
)
}
}, [dispatch, user.user_id])
}, [dispatch, user?.user_id])

const handleKebabPress = useCallback(() => {
if (user.user_id) {
if (user?.user_id) {
Keyboard.dismiss()
dispatch(
setVisibility({
drawer: 'CreateChatActions',
Expand All @@ -187,9 +194,9 @@ export const ChatUserListItem = ({ user }: ChatUserListItemProps) => {
})
)
}
}, [dispatch, user.user_id])
}, [dispatch, user?.user_id])

if (currentUserId === user.user_id) {
if (!user || currentUserId === user?.user_id) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ export const ChatUserListScreen = () => {
onEndReached={handleLoadMore}
maintainVisibleContentPosition={{ minIndexForVisible: 0 }}
data={users}
renderItem={({ item }) => <ChatUserListItem user={item} />}
renderItem={({ item }) => (
<ChatUserListItem userId={item.user_id} />
)}
keyExtractor={(user: User) => user.handle}
contentContainerStyle={styles.flatListContainer}
// Only show empty component if there is no search query
Expand Down

0 comments on commit 001007e

Please sign in to comment.