-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[IMPROVE] Add All tab in Reactions List
#4409
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e2553d4
Add 'All' tab in Reactions List
try-catch-stack 6ae31b1
Add names to message reactions
try-catch-stack 3797933
useRealName settings
try-catch-stack 1debafa
Move ReactionsList components to separate files
try-catch-stack 78f17c6
Add unit tests and storybook stories
try-catch-stack d5bfbc2
Add detox test
try-catch-stack 2adbfcb
Fix UsersList styles
diegolmello 501bfca
Move useSelector to top
diegolmello 8a891a4
ListHeaderComponent can be a React component instead of a function
diegolmello ff4e50b
Fixing more styles
diegolmello cde3ec7
All tab emojis
diegolmello fc8e85b
Fix tab styles
diegolmello 40e3346
Fix flatlist notch
diegolmello 3e2a0e8
Fixing tab styles
diegolmello 75afd5d
Update snapshots
diegolmello fbd5cf4
Fix tabWidth issue on landscape and useRealName on all tab
try-catch-stack 51602c6
Merge branch 'develop' into improve.reactions-list
diegolmello ea30a99
Fix storybook not displaying the component
diegolmello 2f2e955
Stop baseUrl prop drill
diegolmello c06e66b
Stop width prop drill
diegolmello 746d8a5
baseUrl and width on RoomView
diegolmello fba798f
Add 80% snap
diegolmello 21bf216
Update tests
diegolmello a9f8797
Remove username prop drill and fix some tests
diegolmello efc03af
Minor style change on header
diegolmello dc599c5
Update detox tests
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
__tests__/containers/ReactionsList/__snapshots__/ReactionsList.stories.storyshot
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React from 'react'; | ||
| import { Text, View, FlatList } from 'react-native'; | ||
|
|
||
| import Emoji from '../message/Emoji'; | ||
| import { useTheme } from '../../theme'; | ||
| import { IReaction } from '../../definitions'; | ||
| import { TGetCustomEmoji } from '../../definitions/IEmoji'; | ||
| import I18n from '../../i18n'; | ||
| import styles from './styles'; | ||
| import { useAppSelector } from '../../lib/hooks'; | ||
|
|
||
| interface IAllReactionsListItemProps { | ||
| getCustomEmoji: TGetCustomEmoji; | ||
| item: IReaction; | ||
| } | ||
|
|
||
| interface IAllTabProps { | ||
| getCustomEmoji: TGetCustomEmoji; | ||
| tabLabel: IReaction; | ||
| reactions?: IReaction[]; | ||
| } | ||
|
|
||
| const AllReactionsListItem = ({ item, getCustomEmoji }: IAllReactionsListItemProps) => { | ||
| const { colors } = useTheme(); | ||
| const useRealName = useAppSelector(state => state.settings.UI_Use_Real_Name); | ||
| const server = useAppSelector(state => state.server.server); | ||
| const username = useAppSelector(state => state.login.user.username); | ||
| const count = item.usernames.length; | ||
|
|
||
| let displayNames; | ||
| if (useRealName && item.names) { | ||
| displayNames = item.names | ||
| .slice(0, 3) | ||
| .map((name, index) => (item.usernames[index] === username ? I18n.t('you') : name)) | ||
| .join(', '); | ||
| } else { | ||
| displayNames = item.usernames | ||
| .slice(0, 3) | ||
| .map((otherUsername: string) => (username === otherUsername ? I18n.t('you') : otherUsername)) | ||
| .join(', '); | ||
| } | ||
| if (count > 3) { | ||
| displayNames = `${displayNames} ${I18n.t('and_more')} ${count - 3}`; | ||
| } else { | ||
| displayNames = displayNames.replace(/,(?=[^,]*$)/, ` ${I18n.t('and')}`); | ||
| } | ||
| return ( | ||
| <View style={styles.listItemContainer}> | ||
| <Emoji | ||
| content={item.emoji} | ||
| standardEmojiStyle={styles.allTabStandardEmojiStyle} | ||
| customEmojiStyle={styles.allTabCustomEmojiStyle} | ||
| baseUrl={server} | ||
| getCustomEmoji={getCustomEmoji} | ||
| /> | ||
| <View style={styles.textContainer}> | ||
| <Text style={[styles.allListNPeopleReacted, { color: colors.bodyText }]}> | ||
| {count === 1 ? I18n.t('1_person_reacted') : I18n.t('N_people_reacted', { n: count })} | ||
| </Text> | ||
| <Text style={[styles.allListWhoReacted, { color: colors.auxiliaryText }]}>{displayNames}</Text> | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const AllTab = ({ reactions, getCustomEmoji }: IAllTabProps): React.ReactElement => ( | ||
| <View style={styles.allTabContainer} testID='reactionsListAllTab'> | ||
| <FlatList | ||
| data={reactions} | ||
| contentContainerStyle={styles.listContainer} | ||
| renderItem={({ item }) => <AllReactionsListItem item={item} getCustomEmoji={getCustomEmoji} />} | ||
| keyExtractor={item => item.emoji} | ||
| /> | ||
| </View> | ||
| ); | ||
|
|
||
| export default AllTab; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import React from 'react'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import { TGetCustomEmoji, IEmoji } from '../../definitions'; | ||
| import ReactionsList from '.'; | ||
| import { mockedStore as store } from '../../reducers/mockedStore'; | ||
| import { updateSettings } from '../../actions/settings'; | ||
|
|
||
| const getCustomEmoji: TGetCustomEmoji = content => { | ||
| const customEmoji = { | ||
| marioparty: { name: content, extension: 'gif' }, | ||
| react_rocket: { name: content, extension: 'png' }, | ||
| nyan_rocket: { name: content, extension: 'png' } | ||
| }[content] as IEmoji; | ||
| return customEmoji; | ||
| }; | ||
|
|
||
| const reactions = [ | ||
| { | ||
| emoji: ':marioparty:', | ||
| _id: 'marioparty', | ||
| usernames: ['rocket.cat', 'diego.mello'], | ||
| names: ['Rocket Cat', 'Diego Mello'] | ||
| }, | ||
| { | ||
| emoji: ':react_rocket:', | ||
| _id: 'react_rocket', | ||
| usernames: ['rocket.cat', 'diego.mello'], | ||
| names: ['Rocket Cat', 'Diego Mello'] | ||
| }, | ||
| { | ||
| emoji: ':nyan_rocket:', | ||
| _id: 'nyan_rocket', | ||
| usernames: ['rocket.cat'], | ||
| names: ['Rocket Cat'] | ||
| }, | ||
| { | ||
| emoji: ':grinning:', | ||
| _id: 'grinning', | ||
| usernames: ['diego.mello'], | ||
| names: ['Diego Mello'] | ||
| }, | ||
| { | ||
| emoji: ':tada:', | ||
| _id: 'tada', | ||
| usernames: ['diego.mello'], | ||
| names: ['Diego Mello'] | ||
| } | ||
| ]; | ||
|
|
||
| export const ReactionsListStory = () => { | ||
| store.dispatch(updateSettings('UI_Use_Real_Name', false)); | ||
| return ( | ||
| <View style={{ paddingVertical: 10, flex: 1 }}> | ||
| <ReactionsList getCustomEmoji={getCustomEmoji} reactions={reactions} /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export const ReactionsListFullName = () => { | ||
| store.dispatch(updateSettings('UI_Use_Real_Name', true)); | ||
| return ( | ||
| <View style={{ paddingVertical: 10, flex: 1 }}> | ||
| <ReactionsList getCustomEmoji={getCustomEmoji} reactions={reactions} /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default { | ||
| title: 'ReactionsList' | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import React from 'react'; | ||
| import { fireEvent, render, within } from '@testing-library/react-native'; | ||
| import { Provider } from 'react-redux'; | ||
|
|
||
| import ReactionsList from '.'; | ||
| import { mockedStore } from '../../reducers/mockedStore'; | ||
|
|
||
| const getCustomEmoji = jest.fn(); | ||
| const reactions = [ | ||
| { | ||
| emoji: 'marioparty', | ||
| _id: 'marioparty', | ||
| usernames: ['rocket.cat', 'diego.mello'], | ||
| names: ['Rocket Cat', 'Diego Mello'] | ||
| }, | ||
| { | ||
| emoji: 'react_rocket', | ||
| _id: 'react_rocket', | ||
| usernames: ['rocket.cat', 'diego.mello'], | ||
| names: ['Rocket Cat', 'Diego Mello'] | ||
| }, | ||
| { | ||
| emoji: 'nyan_rocket', | ||
| _id: 'nyan_rocket', | ||
| usernames: ['rocket.cat'], | ||
| names: ['Rocket Cat'] | ||
| }, | ||
| { | ||
| emoji: 'grinning', | ||
| _id: 'grinning', | ||
| usernames: ['diego.mello'], | ||
| names: ['Diego Mello'] | ||
| } | ||
| ]; | ||
|
|
||
| const Render = () => ( | ||
| <Provider store={mockedStore}> | ||
| <ReactionsList getCustomEmoji={getCustomEmoji} reactions={reactions} /> | ||
| </Provider> | ||
| ); | ||
|
|
||
| describe('ReactionsList', () => { | ||
| test('should render Reactions List', async () => { | ||
| const { findByTestId } = render(<Render />); | ||
| const ReactionsListView = await findByTestId('reactionsList'); | ||
| expect(ReactionsListView).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should render tab bar', async () => { | ||
| const { findByTestId } = render(<Render />); | ||
| const AllTab = await findByTestId('reactionsTabBar'); | ||
| expect(AllTab).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should render All tab', async () => { | ||
| const { findByTestId } = render(<Render />); | ||
| const AllTab = await findByTestId('reactionsListAllTab'); | ||
| expect(AllTab).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('correct tab on clicking tab item', async () => { | ||
| const { findByTestId } = render(<Render />); | ||
| const tab = await findByTestId(`tabBarItem-${reactions[0].emoji}`); | ||
| fireEvent.press(tab); | ||
| const usersList = await findByTestId(`usersList-${reactions[0].emoji}`); | ||
| expect(usersList).toBeTruthy(); | ||
| const emojiName = await within(usersList).getByTestId(`usersListEmojiName`); | ||
| expect(emojiName.props.children).toEqual(reactions[0].emoji); | ||
| }); | ||
|
|
||
| test('should render correct number of reactions', async () => { | ||
| const { findByTestId } = render(<Render />); | ||
| const tab = await findByTestId(`tabBarItem-${reactions[0].emoji}`); | ||
| fireEvent.press(tab); | ||
| const usersList = await findByTestId(`usersList-${reactions[0].emoji}`); | ||
| const allReactions = await within(usersList).getAllByTestId('userItem'); | ||
| expect(allReactions).toHaveLength(reactions[0].usernames.length); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.