Skip to content

Commit

Permalink
action-sheets: Use navigation object instead of NavigationService
Browse files Browse the repository at this point in the history
Further in the direction of zulip#5408, which switched most of our
then-existing uses of NavigationService to use `navigation` instead.

As noted there:

> Switching away from `NavigationService` is recommended by React
> Navigation upstream, as described at zulip#4417. We also now get
> type-checking on those `navigation.push` calls -- Flow is able to
> check that the route params we pass line up with what the route in
> question expects -- which wasn't/isn't the case for the
> implementations of the `navActions` functions.

This causes a few of the navActions functions to lose their last
remaining caller, so delete those.
  • Loading branch information
chrisbobbe committed Sep 15, 2022
1 parent 2a0364d commit 1643eac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 41 deletions.
40 changes: 14 additions & 26 deletions src/action-sheets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Clipboard, Share, Alert } from 'react-native';
import invariant from 'invariant';
import * as resolved_topic from '@zulip/shared/js/resolved_topic';

import * as NavigationService from '../nav/NavigationService';
import type {
Auth,
Dispatch,
Expand Down Expand Up @@ -33,18 +32,7 @@ import type { PmKeyRecipients } from '../utils/recipient';
import { isTopicMuted } from '../mute/muteModel';
import * as api from '../api';
import { showConfirmationDialog, showToast } from '../utils/info';
import {
doNarrow,
deleteOutboxMessage,
navigateToEmojiPicker,
navigateToStream,
fetchSomeMessageIdForConversation,
} from '../actions';
import {
navigateToMessageReactionScreen,
navigateToPmConversationDetails,
navigateToReadReceiptsScreen,
} from '../nav/navActions';
import { doNarrow, deleteOutboxMessage, fetchSomeMessageIdForConversation } from '../actions';
import { deleteMessagesForTopic } from '../topics/topicActions';
import * as logging from '../utils/logging';
import { getUnreadCountForTopic } from '../unread/unreadModel';
Expand Down Expand Up @@ -322,8 +310,8 @@ const copyLinkToStream = {
const showStreamSettings = {
title: 'Stream settings',
errorMessage: 'Failed to show stream settings',
action: ({ streamId }) => {
NavigationService.dispatch(navigateToStream(streamId));
action: ({ streamId, navigation }) => {
navigation.push('stream-settings', { streamId });
},
};

Expand Down Expand Up @@ -384,8 +372,8 @@ const disableNotifications = {
const seePmConversationDetails = {
title: 'See details',
errorMessage: 'Failed to show details',
action: async ({ pmKeyRecipients }) => {
NavigationService.dispatch(navigateToPmConversationDetails(pmKeyRecipients));
action: async ({ pmKeyRecipients, navigation }) => {
navigation.push('pm-conversation-details', { recipients: pmKeyRecipients });
},
};

Expand Down Expand Up @@ -418,33 +406,33 @@ const shareMessage = {
const addReaction = {
title: 'Add a reaction',
errorMessage: 'Failed to add reaction',
action: ({ auth, message, _ }) => {
NavigationService.dispatch(
navigateToEmojiPicker(({ code, name, type }) => {
action: ({ auth, message, navigation, _ }) => {
navigation.push('emoji-picker', {
onPressEmoji: ({ code, name, type }) => {
api
.emojiReactionAdd(auth, message.id, reactionTypeFromEmojiType(type, name), code, name)
.catch(err => {
logging.error('Error adding reaction emoji', err);
showToast(_('Failed to add reaction'));
});
}),
);
},
});
},
};

const showReactions = {
title: 'See who reacted',
errorMessage: 'Failed to show reactions',
action: ({ message }) => {
NavigationService.dispatch(navigateToMessageReactionScreen(message.id));
action: ({ message, navigation }) => {
navigation.push('message-reactions', { messageId: message.id });
},
};

const viewReadReceipts = {
title: 'View read receipts',
errorMessage: 'Failed to show read receipts',
action: ({ message }) => {
NavigationService.dispatch(navigateToReadReceiptsScreen(message.id));
action: ({ message, navigation }) => {
navigation.push('read-receipts', { messageId: message.id });
},
};

Expand Down
16 changes: 1 addition & 15 deletions src/nav/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
} from '@react-navigation/native';

import * as NavigationService from './NavigationService';
import type { Message, Narrow, UserId, EmojiType } from '../types';
import type { PmKeyRecipients } from '../utils/recipient';
import type { Message, Narrow, UserId } from '../types';
import type { SharedData } from '../sharing/types';

// TODO: Probably just do a StackActions.pop()?
Expand Down Expand Up @@ -47,29 +46,16 @@ export const navigateToChat = (narrow: Narrow): NavigationAction =>
export const replaceWithChat = (narrow: Narrow): NavigationAction =>
StackActions.replace('chat', { narrow, editMessage: null });

export const navigateToEmojiPicker = (
onPressEmoji: ({| +type: EmojiType, +code: string, +name: string |}) => void,
): NavigationAction => StackActions.push('emoji-picker', { onPressEmoji });

export const navigateToAccountDetails = (userId: UserId): NavigationAction =>
StackActions.push('account-details', { userId });

export const navigateToPmConversationDetails = (recipients: PmKeyRecipients): NavigationAction =>
StackActions.push('pm-conversation-details', { recipients });

export const navigateToLightbox = (src: string, message: Message): NavigationAction =>
StackActions.push('lightbox', { src, message });

export const navigateToStream = (streamId: number): NavigationAction =>
StackActions.push('stream-settings', { streamId });

export const navigateToMessageReactionScreen = (
messageId: number,
reactionName?: string,
): NavigationAction => StackActions.push('message-reactions', { messageId, reactionName });

export const navigateToReadReceiptsScreen = (messageId: number): NavigationAction =>
StackActions.push('read-receipts', { messageId });

export const navigateToSharing = (sharedData: SharedData): NavigationAction =>
StackActions.push('sharing', { sharedData });

0 comments on commit 1643eac

Please sign in to comment.