Skip to content

Commit 9c9d7f4

Browse files
authored
[PAY-1700] Replace navigation if coming from ChatUserListScreen (#3879)
1 parent eaef4e6 commit 9c9d7f4

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

packages/common/src/store/pages/chat/sagas.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ function* doSetMessageReaction(action: ReturnType<typeof setMessageReaction>) {
373373
}
374374

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

388389
// Optimistically go to the chat. If we fail to create it, we'll toast
389390
if (!skipNavigation) {
390-
yield* put(goToChat({ chatId, presetMessage }))
391+
yield* put(goToChat({ chatId, presetMessage, replaceNavigation }))
391392
}
392393

393394
try {

packages/common/src/store/pages/chat/slice.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const slice = createSlice({
132132
userIds: ID[]
133133
skipNavigation?: boolean
134134
presetMessage?: string
135+
replaceNavigation?: boolean
135136
}>
136137
) => {
137138
// triggers saga
@@ -159,7 +160,11 @@ const slice = createSlice({
159160
fetchUnreadMessagesCountFailed: (_state) => {},
160161
goToChat: (
161162
_state,
162-
_action: PayloadAction<{ chatId?: string; presetMessage?: string }>
163+
_action: PayloadAction<{
164+
chatId?: string
165+
presetMessage?: string
166+
replaceNavigation?: boolean
167+
}>
163168
) => {
164169
// triggers saga
165170
},

packages/mobile/src/screens/chat-screen/ChatUserListItem.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ export const ChatUserListItem = ({
162162
const handlePress = useCallback(() => {
163163
if (user?.user_id) {
164164
Keyboard.dismiss()
165-
dispatch(createChat({ userIds: [user.user_id], presetMessage }))
165+
dispatch(
166+
createChat({
167+
userIds: [user.user_id],
168+
presetMessage,
169+
replaceNavigation: true
170+
})
171+
)
166172
}
167173
}, [dispatch, presetMessage, user?.user_id])
168174

packages/mobile/src/store/chat/sagas.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { chatActions } from '@audius/common'
2+
import { StackActions } from '@react-navigation/native'
23
import { takeLatest } from 'redux-saga/effects'
34

45
import { navigationRef } from 'app/components/navigation-container/NavigationContainer'
@@ -8,15 +9,21 @@ const { goToChat } = chatActions
89
function* watchGoToChat() {
910
yield takeLatest(goToChat, function* (action: ReturnType<typeof goToChat>) {
1011
const {
11-
payload: { chatId, presetMessage }
12+
payload: { chatId, presetMessage, replaceNavigation }
1213
} = action
1314
if (navigationRef.isReady()) {
1415
if (!chatId) {
1516
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
1617
navigationRef.navigate('ChatList')
1718
} else {
18-
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
19-
navigationRef.navigate('Chat', { chatId, presetMessage })
19+
if (replaceNavigation) {
20+
navigationRef.current?.dispatch(
21+
StackActions.replace('Chat', { chatId, presetMessage })
22+
)
23+
} else {
24+
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
25+
navigationRef.navigate('Chat', { chatId, presetMessage })
26+
}
2027
}
2128
}
2229
})

0 commit comments

Comments
 (0)