Skip to content

Commit

Permalink
ActionSheet [nfc]: Rename HeaderActionSheet to TopicActionSheet.
Browse files Browse the repository at this point in the history
This is a better name since this type of action sheet is used with
Topics.
  • Loading branch information
AkashDhiman committed Jun 15, 2021
1 parent 4dd471c commit 28d86d0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HOME_NARROW } from '../../utils/narrow';
import { streamNameOfStreamMessage } from '../../utils/recipient';

import * as eg from '../../__tests__/lib/exampleData';
import { constructMessageActionButtons, constructHeaderActionButtons } from '../messageActionSheet';
import { constructMessageActionButtons, constructTopicActionButtons } from '../messageActionSheet';

const baseBackgroundData = deepFreeze({
alertWords: [],
Expand Down Expand Up @@ -56,10 +56,10 @@ describe('constructActionButtons', () => {
});
});

describe('constructHeaderActionButtons', () => {
describe('constructTopicActionButtons', () => {
test('show Unmute topic option if topic is muted', () => {
const mute = deepFreeze([['electron issues', 'issue #556']]);
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: { ...baseBackgroundData, mute },
stream: 'electron issues',
topic: 'issue #556',
Expand All @@ -68,7 +68,7 @@ describe('constructHeaderActionButtons', () => {
});

test('show mute topic option if topic is not muted', () => {
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: { ...baseBackgroundData, mute: [] },
stream: streamNameOfStreamMessage(eg.streamMessage()),
topic: eg.streamMessage().subject,
Expand All @@ -78,7 +78,7 @@ describe('constructHeaderActionButtons', () => {

test('show Unmute stream option if stream is not in home view', () => {
const subscriptions = [{ ...eg.subscription, in_home_view: false }];
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: { ...baseBackgroundData, subscriptions },
stream: streamNameOfStreamMessage(eg.streamMessage()),
topic: eg.streamMessage().subject,
Expand All @@ -88,7 +88,7 @@ describe('constructHeaderActionButtons', () => {

test('show mute stream option if stream is in home view', () => {
const subscriptions = [{ ...eg.subscription, in_home_view: true }];
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: { ...baseBackgroundData, subscriptions },
stream: streamNameOfStreamMessage(eg.streamMessage()),
topic: eg.streamMessage().subject,
Expand All @@ -98,7 +98,7 @@ describe('constructHeaderActionButtons', () => {

test('show delete topic option if current user is an admin', () => {
const ownUser = { ...eg.selfUser, is_admin: true };
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: { ...baseBackgroundData, ownUser },
stream: streamNameOfStreamMessage(eg.streamMessage()),
topic: eg.streamMessage().subject,
Expand All @@ -107,7 +107,7 @@ describe('constructHeaderActionButtons', () => {
});

test('do not show delete topic option if current user is not an admin', () => {
const buttons = constructHeaderActionButtons({
const buttons = constructTopicActionButtons({
backgroundData: baseBackgroundData,
stream: streamNameOfStreamMessage(eg.streamMessage()),
topic: eg.streamMessage().subject,
Expand Down
17 changes: 7 additions & 10 deletions src/message/messageActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type ShowActionSheetWithOptions = (
(number) => void,
) => void;

type HeaderArgs = {
type TopicArgs = {
auth: Auth,
stream: string,
topic: string,
Expand All @@ -55,7 +55,7 @@ type MessageArgs = {
...
};

type Button<Args: HeaderArgs | MessageArgs> = {|
type Button<Args: TopicArgs | MessageArgs> = {|
(Args): void | Promise<void>,

/** The label for the button. */
Expand Down Expand Up @@ -226,7 +226,7 @@ const cancel = params => {};
cancel.title = 'Cancel';
cancel.errorMessage = 'Failed to hide menu';

export const constructHeaderActionButtons = ({
export const constructTopicActionButtons = ({
backgroundData: { mute, subscriptions, ownUser },
stream,
topic,
Expand All @@ -239,7 +239,7 @@ export const constructHeaderActionButtons = ({
}>,
stream: string,
topic: string,
|}): Button<HeaderArgs>[] => {
|}): Button<TopicArgs>[] => {
const buttons = [];
if (ownUser.is_admin) {
buttons.push(deleteTopic);
Expand Down Expand Up @@ -338,10 +338,7 @@ export const constructNonHeaderActionButtons = ({
}
};

function makeButtonCallback<Args: HeaderArgs | MessageArgs>(
buttonList: Button<Args>[],
args: Args,
) {
function makeButtonCallback<Args: TopicArgs | MessageArgs>(buttonList: Button<Args>[], args: Args) {
return buttonIndex => {
(async () => {
const pressedButton: Button<Args> = buttonList[buttonIndex];
Expand Down Expand Up @@ -392,7 +389,7 @@ export const showMessageActionSheet = ({
);
};

export const showHeaderActionSheet = ({
export const showTopicActionSheet = ({
showActionSheetWithOptions,
callbacks,
backgroundData,
Expand All @@ -415,7 +412,7 @@ export const showHeaderActionSheet = ({
stream: string,
topic: string,
|}): void => {
const buttonList = constructHeaderActionButtons({
const buttonList = constructTopicActionButtons({
backgroundData,
stream,
topic,
Expand Down
4 changes: 2 additions & 2 deletions src/streams/TopicItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useActionSheet } from '@expo/react-native-action-sheet';

import styles, { BRAND_COLOR, createStyleSheet } from '../styles';
import { RawLabel, Touchable, UnreadCount } from '../common';
import { showHeaderActionSheet } from '../message/messageActionSheet';
import { showTopicActionSheet } from '../message/messageActionSheet';
import type { ShowActionSheetWithOptions } from '../message/messageActionSheet';
import { TranslationContext } from '../boot/TranslationProvider';
import { useDispatch, useSelector } from '../react-redux';
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function TopicItem(props: Props) {
<Touchable
onPress={() => onPress(stream, name)}
onLongPress={() => {
showHeaderActionSheet({
showTopicActionSheet({
showActionSheetWithOptions,
callbacks: { dispatch, _ },
backgroundData,
Expand Down
4 changes: 2 additions & 2 deletions src/title/TitleStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
getOwnUser,
getStreamInNarrow,
} from '../selectors';
import { showHeaderActionSheet } from '../message/messageActionSheet';
import { showTopicActionSheet } from '../message/messageActionSheet';
import type { ShowActionSheetWithOptions } from '../message/messageActionSheet';

type SelectorProps = {|
Expand Down Expand Up @@ -74,7 +74,7 @@ const TitleStream = (props: Props) => {
onLongPress={
isTopicNarrow(narrow)
? () => {
showHeaderActionSheet({
showTopicActionSheet({
showActionSheetWithOptions,
callbacks: { dispatch, _ },
backgroundData,
Expand Down
4 changes: 2 additions & 2 deletions src/webview/handleOutboundEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
navigateToLightbox,
messageLinkPress,
} from '../actions';
import { showHeaderActionSheet, showMessageActionSheet } from '../message/messageActionSheet';
import { showTopicActionSheet, showMessageActionSheet } from '../message/messageActionSheet';
import { ensureUnreachable } from '../types';
import { base64Utf8Decode } from '../utils/encoding';

Expand Down Expand Up @@ -214,7 +214,7 @@ const handleLongPress = (
const { dispatch, showActionSheetWithOptions, backgroundData, narrow, startEditMessage } = props;
if (target === 'header') {
if (message.type === 'stream') {
showHeaderActionSheet({
showTopicActionSheet({
showActionSheetWithOptions,
callbacks: { dispatch, _ },
backgroundData,
Expand Down

0 comments on commit 28d86d0

Please sign in to comment.