Skip to content

Commit

Permalink
[PAY-1700] Replace navigation if coming from ChatUserListScreen (#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo committed Aug 14, 2023
1 parent eaef4e6 commit 9c9d7f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/common/src/store/pages/chat/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ function* doSetMessageReaction(action: ReturnType<typeof setMessageReaction>) {
}

function* doCreateChat(action: ReturnType<typeof createChat>) {
const { userIds, skipNavigation, presetMessage } = action.payload
const { userIds, skipNavigation, presetMessage, replaceNavigation } =
action.payload
const { track, make } = yield* getContext('analytics')
try {
const audiusSdk = yield* getContext('audiusSdk')
Expand All @@ -387,7 +388,7 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {

// Optimistically go to the chat. If we fail to create it, we'll toast
if (!skipNavigation) {
yield* put(goToChat({ chatId, presetMessage }))
yield* put(goToChat({ chatId, presetMessage, replaceNavigation }))
}

try {
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/store/pages/chat/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const slice = createSlice({
userIds: ID[]
skipNavigation?: boolean
presetMessage?: string
replaceNavigation?: boolean
}>
) => {
// triggers saga
Expand Down Expand Up @@ -159,7 +160,11 @@ const slice = createSlice({
fetchUnreadMessagesCountFailed: (_state) => {},
goToChat: (
_state,
_action: PayloadAction<{ chatId?: string; presetMessage?: string }>
_action: PayloadAction<{
chatId?: string
presetMessage?: string
replaceNavigation?: boolean
}>
) => {
// triggers saga
},
Expand Down
8 changes: 7 additions & 1 deletion packages/mobile/src/screens/chat-screen/ChatUserListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ export const ChatUserListItem = ({
const handlePress = useCallback(() => {
if (user?.user_id) {
Keyboard.dismiss()
dispatch(createChat({ userIds: [user.user_id], presetMessage }))
dispatch(
createChat({
userIds: [user.user_id],
presetMessage,
replaceNavigation: true
})
)
}
}, [dispatch, presetMessage, user?.user_id])

Expand Down
13 changes: 10 additions & 3 deletions packages/mobile/src/store/chat/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chatActions } from '@audius/common'
import { StackActions } from '@react-navigation/native'
import { takeLatest } from 'redux-saga/effects'

import { navigationRef } from 'app/components/navigation-container/NavigationContainer'
Expand All @@ -8,15 +9,21 @@ const { goToChat } = chatActions
function* watchGoToChat() {
yield takeLatest(goToChat, function* (action: ReturnType<typeof goToChat>) {
const {
payload: { chatId, presetMessage }
payload: { chatId, presetMessage, replaceNavigation }
} = action
if (navigationRef.isReady()) {
if (!chatId) {
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
navigationRef.navigate('ChatList')
} else {
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
navigationRef.navigate('Chat', { chatId, presetMessage })
if (replaceNavigation) {
navigationRef.current?.dispatch(
StackActions.replace('Chat', { chatId, presetMessage })
)
} else {
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
navigationRef.navigate('Chat', { chatId, presetMessage })
}
}
}
})
Expand Down

0 comments on commit 9c9d7f4

Please sign in to comment.