Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e59d87f
[TS migration] Migrate 'Reactions' component
VickyStash Dec 12, 2023
03eb9cd
Merge branch 'main' into ts-migration/reactions-component
VickyStash Dec 13, 2023
2374486
Fix after merging main
VickyStash Dec 13, 2023
2b4037d
Minor code improvements
VickyStash Dec 13, 2023
5b9c140
Merge branch 'main' into ts-migration/reactions-component
VickyStash Dec 18, 2023
a2134b2
Updates to follow main branch
VickyStash Dec 18, 2023
d4f7ba8
Remove TODO related to PersonalDetailsUtils
VickyStash Dec 18, 2023
a21eef6
Type improvements
VickyStash Dec 21, 2023
78d61d7
Add ReactionListEvent and ReactionListAnchor types
VickyStash Dec 21, 2023
6e94929
Undo unnecessary updates in withCurrentUserPersonalDetails HOC
VickyStash Dec 21, 2023
e5663f1
Get rid of extra emoji types
VickyStash Dec 21, 2023
e1670ca
Add LocaleEmojis type
VickyStash Dec 21, 2023
30ea4d5
Update type imports
VickyStash Dec 21, 2023
2c907a1
Merge branch 'main' into ts-migration/reactions-component
VickyStash Dec 21, 2023
60c58b0
Update TODO comment
VickyStash Dec 21, 2023
52c37de
Merge branch 'main' into ts-migration/reactions-component
VickyStash Dec 22, 2023
0137c9a
TS fixes after merging main
VickyStash Dec 22, 2023
263dbe7
Merge branch 'main' into ts-migration/reactions-component
VickyStash Dec 27, 2023
0ae9f50
Fix TS issues after merging main
VickyStash Dec 27, 2023
115286e
Merge branch 'main' into ts-migration/reactions-component
VickyStash Jan 2, 2024
8ed6017
Update MiniQuickEmojiReactionsOnyxProps type
VickyStash Jan 2, 2024
dbff3bf
Merge branch 'main' into ts-migration/reactions-component
VickyStash Jan 4, 2024
1d4010e
Fix lint errors
VickyStash Jan 4, 2024
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
9 changes: 6 additions & 3 deletions assets/emojis/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type {Locale} from '@src/types/onyx';
import emojis from './common';
import enEmojis from './en';
import esEmojis from './es';
import type {Emoji} from './types';
import type {Emoji, EmojisList} from './types';

type EmojiTable = Record<string, Emoji>;

type LocaleEmojis = Partial<Record<Locale, EmojisList>>;

const emojiNameTable = emojis.reduce<EmojiTable>((prev, cur) => {
const newValue = prev;
if (!('header' in cur) && cur.name) {
Expand All @@ -26,10 +29,10 @@ const emojiCodeTableWithSkinTones = emojis.reduce<EmojiTable>((prev, cur) => {
return newValue;
}, {});

const localeEmojis = {
const localeEmojis: LocaleEmojis = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, I had a TS error in this function. I guess it also could be resolved with assertion/additional conditions if you think type update isn't a good idea

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine as you coded 👍

en: enEmojis,
es: esEmojis,
} as const;
};

export default emojis;
export {emojiNameTable, emojiCodeTableWithSkinTones, localeEmojis};
Expand Down
8 changes: 5 additions & 3 deletions assets/emojis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type IconAsset from '@src/types/utils/IconAsset';
type Emoji = {
code: string;
name: string;
types?: string[];
types?: readonly string[];
};

type HeaderEmoji = {
Expand All @@ -12,8 +12,10 @@ type HeaderEmoji = {
code: string;
};

type PickerEmojis = Array<Emoji | HeaderEmoji>;
type PickerEmoji = Emoji | HeaderEmoji;

type PickerEmojis = PickerEmoji[];

type EmojisList = Record<string, {keywords: string[]; name?: string}>;

export type {Emoji, HeaderEmoji, EmojisList, PickerEmojis};
export type {Emoji, HeaderEmoji, EmojisList, PickerEmojis, PickerEmoji};
8 changes: 4 additions & 4 deletions src/components/EmojiSuggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {ReactElement} from 'react';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import type {Emoji} from '@assets/emojis/types';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import type {SimpleEmoji} from '@libs/EmojiTrie';
import * as EmojiUtils from '@libs/EmojiUtils';
import getStyledTextArray from '@libs/GetStyledTextArray';
import AutoCompleteSuggestions from './AutoCompleteSuggestions';
Expand All @@ -16,7 +16,7 @@ type EmojiSuggestionsProps = {
highlightedEmojiIndex?: number;

/** Array of suggested emoji */
emojis: SimpleEmoji[];
emojis: Emoji[];

/** Fired when the user selects an emoji */
onSelect: (index: number) => void;
Expand All @@ -40,7 +40,7 @@ type EmojiSuggestionsProps = {
/**
* Create unique keys for each emoji item
*/
const keyExtractor = (item: SimpleEmoji, index: number): string => `${item.name}+${index}}`;
const keyExtractor = (item: Emoji, index: number): string => `${item.name}+${index}}`;

function EmojiSuggestions({emojis, onSelect, prefix, isEmojiPickerLarge, preferredSkinToneIndex, highlightedEmojiIndex = 0, measureParentContainer = () => {}}: EmojiSuggestionsProps) {
const styles = useThemeStyles();
Expand All @@ -49,7 +49,7 @@ function EmojiSuggestions({emojis, onSelect, prefix, isEmojiPickerLarge, preferr
* Render an emoji suggestion menu item component.
*/
const renderSuggestionMenuItem = useCallback(
(item: SimpleEmoji): ReactElement => {
(item: Emoji): ReactElement => {
const styledTextArray = getStyledTextArray(item.name, prefix);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,75 @@
import PropTypes from 'prop-types';
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {Emoji} from '@assets/emojis/types';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import getButtonState from '@libs/getButtonState';
import variables from '@styles/variables';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
import type {AnchorOrigin} from '@userActions/EmojiPickerAction';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import type {ReportAction} from '@src/types/onyx';
import type {CloseContextMenuCallback, OpenPickerCallback, PickerRefElement} from './QuickEmojiReactions/types';

const propTypes = {
type AddReactionBubbleProps = {
/** Whether it is for context menu so we can modify its style */
isContextMenu: PropTypes.bool,
isContextMenu?: boolean;

/**
* Called when the user presses on the icon button.
* Will have a function as parameter which you can call
* to open the picker.
*/
onPressOpenPicker: PropTypes.func,
onPressOpenPicker?: (openPicker: OpenPickerCallback) => void;

/**
* Will get called the moment before the picker opens.
*/
onWillShowPicker: PropTypes.func,
onWillShowPicker?: (callback: CloseContextMenuCallback) => void;

/**
* Called when the user selects an emoji.
*/
onSelectEmoji: PropTypes.func.isRequired,
onSelectEmoji: (emoji: Emoji) => void;

/**
* ReportAction for EmojiPicker.
*/
reportAction: PropTypes.shape({
reportActionID: PropTypes.string.isRequired,
}),

...withLocalizePropTypes,
};

const defaultProps = {
isContextMenu: false,
onWillShowPicker: () => {},
onPressOpenPicker: undefined,
reportAction: {},
reportAction: ReportAction;
};

function AddReactionBubble(props) {
function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWillShowPicker = () => {}, isContextMenu = false}: AddReactionBubbleProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const ref = useRef();
const ref = useRef<View | HTMLDivElement>(null);
const {translate} = useLocalize();

useEffect(() => EmojiPickerAction.resetEmojiPopoverAnchor, []);

const onPress = () => {
const openPicker = (refParam, anchorOrigin) => {
const openPicker = (refParam?: PickerRefElement, anchorOrigin?: AnchorOrigin) => {
EmojiPickerAction.showEmojiPicker(
() => {},
(emojiCode, emojiObject) => {
props.onSelectEmoji(emojiObject);
onSelectEmoji(emojiObject);
},
refParam || ref,
refParam ?? ref,
anchorOrigin,
props.onWillShowPicker,
props.reportAction.reportActionID,
onWillShowPicker,
reportAction.reportActionID,
);
};

if (!EmojiPickerAction.emojiPickerRef.current.isEmojiPickerVisible) {
if (props.onPressOpenPicker) {
props.onPressOpenPicker(openPicker);
if (!EmojiPickerAction.emojiPickerRef.current?.isEmojiPickerVisible) {
if (onPressOpenPicker) {
onPressOpenPicker(openPicker);
} else {
openPicker();
}
Expand All @@ -85,21 +79,21 @@ function AddReactionBubble(props) {
};

return (
<Tooltip text={props.translate('emojiReactions.addReactionTooltip')}>
<Tooltip text={translate('emojiReactions.addReactionTooltip')}>
<PressableWithFeedback
ref={ref}
style={({hovered, pressed}) => [styles.emojiReactionBubble, styles.userSelectNone, StyleUtils.getEmojiReactionBubbleStyle(hovered || pressed, false, props.isContextMenu)]}
style={({hovered, pressed}) => [styles.emojiReactionBubble, styles.userSelectNone, StyleUtils.getEmojiReactionBubbleStyle(hovered || pressed, false, isContextMenu)]}
onPress={Session.checkIfActionIsAllowed(onPress)}
onMouseDown={(e) => {
onMouseDown={(event) => {
// Allow text input blur when Add reaction is right clicked
if (!e || e.button === 2) {
if (!event || event.button === 2) {
return;
}

// Prevent text input blur when Add reaction is left clicked
e.preventDefault();
event.preventDefault();
}}
accessibilityLabel={props.translate('emojiReactions.addReactionTooltip')}
accessibilityLabel={translate('emojiReactions.addReactionTooltip')}
role={CONST.ROLE.BUTTON}
// disable dimming
pressDimmingValue={1}
Expand All @@ -110,12 +104,12 @@ function AddReactionBubble(props) {
{/* This (invisible) text will make the view have the same size as a regular
emoji reaction. We make the text invisible and put the
icon on top of it. */}
<Text style={[styles.opacity0, StyleUtils.getEmojiReactionBubbleTextStyle(props.isContextMenu)]}>{'\u2800\u2800'}</Text>
<Text style={[styles.opacity0, StyleUtils.getEmojiReactionBubbleTextStyle(isContextMenu)]}>{'\u2800\u2800'}</Text>
<View style={styles.pAbsolute}>
<Icon
src={Expensicons.AddReaction}
width={props.isContextMenu ? variables.iconSizeNormal : variables.iconSizeSmall}
height={props.isContextMenu ? variables.iconSizeNormal : variables.iconSizeSmall}
width={isContextMenu ? variables.iconSizeNormal : variables.iconSizeSmall}
height={isContextMenu ? variables.iconSizeNormal : variables.iconSizeSmall}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))}
/>
</View>
Expand All @@ -126,8 +120,6 @@ function AddReactionBubble(props) {
);
}

AddReactionBubble.propTypes = propTypes;
AddReactionBubble.defaultProps = defaultProps;
AddReactionBubble.displayName = 'AddReactionBubble';

export default withLocalize(AddReactionBubble);
export default AddReactionBubble;
110 changes: 0 additions & 110 deletions src/components/Reactions/EmojiReactionBubble.js

This file was deleted.

Loading