Skip to content

Commit 5030ceb

Browse files
authored
Merge pull request #4549 from tloncorp/po/tlon-3829-return-from-notebook-or-gallery-post-to-chat-if-linked-from-chat
desktop: navigate back to chat from notebook/gallery post if linked from chat
2 parents 4272131 + 2c92665 commit 5030ceb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/app/navigation/utils.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,31 @@ export function useNavigateBackFromPost() {
204204
const isWindowNarrow = useIsWindowNarrow();
205205
const navigation = useNavigation();
206206
const length = navigation.getState()?.routes.length;
207-
const lastScreenWasActivity =
208-
navigation.getState()?.routes[length - 2]?.name === 'Activity';
207+
const lastScreen = navigation.getState()?.routes[length - 2];
208+
const lastScreenWasActivity = lastScreen?.name === 'Activity';
209+
// @ts-expect-error - ChannelRoot is fine here.
210+
const lastScreenWasChannel = lastScreen?.name === 'ChannelRoot';
211+
const lastChannelWasChat =
212+
// @ts-expect-error - we know we'll have a channelId here if lastScreenWasChannel
213+
lastScreenWasChannel && lastScreen?.params?.channelId
214+
? // @ts-expect-error - we know we'll have a channelId here if lastScreenWasChannel
215+
lastScreen.params.channelId.startsWith('chat')
216+
: false;
209217

210218
return useCallback(
211219
(channel: db.Channel, postId: string) => {
220+
const isChatShaped = ['chat', 'dm', 'groupDM'].includes(channel.type);
221+
if (lastChannelWasChat && !isChatShaped) {
222+
// if we're returning from viewing a notebook/gallery post and the last
223+
// channel was a chat, we should navigate to the chat instead of the
224+
// notebook/gallery channel
225+
navigation.goBack();
226+
return;
227+
}
212228
if (lastScreenWasActivity) {
213229
navigation.navigate('Activity');
214230
return;
215231
}
216-
const isChatShaped = ['chat', 'dm', 'groupDM'].includes(channel.type);
217232
if (isWindowNarrow) {
218233
const screenName = screenNameFromChannelId(channel.id);
219234
navigation.navigate(screenName, {

0 commit comments

Comments
 (0)