Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[PAY-1700] Replace navigation if coming from ChatUserListScreen #3879

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 })
rickyrombo marked this conversation as resolved.
Show resolved Hide resolved
)
} else {
// @ts-ignore navigationRef is not parametrized correctly (PAY-1141)
navigationRef.navigate('Chat', { chatId, presetMessage })
}
}
}
})
Expand Down