Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

desktop: navigate back to chat from notebook/gallery post if linked from chat #4549

Merged
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
21 changes: 18 additions & 3 deletions packages/app/navigation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,31 @@ export function useNavigateBackFromPost() {
const isWindowNarrow = useIsWindowNarrow();
const navigation = useNavigation();
const length = navigation.getState()?.routes.length;
const lastScreenWasActivity =
navigation.getState()?.routes[length - 2]?.name === 'Activity';
const lastScreen = navigation.getState()?.routes[length - 2];
const lastScreenWasActivity = lastScreen?.name === 'Activity';
// @ts-expect-error - ChannelRoot is fine here.
const lastScreenWasChannel = lastScreen?.name === 'ChannelRoot';
const lastChannelWasChat =
// @ts-expect-error - we know we'll have a channelId here if lastScreenWasChannel
lastScreenWasChannel && lastScreen?.params?.channelId
? // @ts-expect-error - we know we'll have a channelId here if lastScreenWasChannel
lastScreen.params.channelId.startsWith('chat')
: false;

return useCallback(
(channel: db.Channel, postId: string) => {
const isChatShaped = ['chat', 'dm', 'groupDM'].includes(channel.type);
if (lastChannelWasChat && !isChatShaped) {
// if we're returning from viewing a notebook/gallery post and the last
// channel was a chat, we should navigate to the chat instead of the
// notebook/gallery channel
navigation.goBack();
return;
}
if (lastScreenWasActivity) {
navigation.navigate('Activity');
return;
}
const isChatShaped = ['chat', 'dm', 'groupDM'].includes(channel.type);
if (isWindowNarrow) {
const screenName = screenNameFromChannelId(channel.id);
navigation.navigate(screenName, {
Expand Down