Repository navigation
[TS migration] Migrate 'ReportReactionList' component to TypeScript #34549
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
MonilBhavsar
merged 45 commits into
Expensify:main
from
vadymbokatov:31976-report-reaction-list-migration
Feb 20, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
ec74f83
chore: migrates reactionPropTypes, BaseReactionList and HeaderReactio…
vadymbokatov 0972c81
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov baaa5a5
chore: migrates BasePopoverReactionList and ReactionList to TS
vadymbokatov 28dfadc
Update src/pages/home/report/ReactionList/HeaderReactionList.tsx
vadymbokatov 4bee7c6
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 952c523
chore: renames the types file and fixes its linting errors
vadymbokatov efe9d72
chore: removes any typed and fixes linting errors on the index file
vadymbokatov a303a5e
fix: some linting errors and any types
vadymbokatov 006f1f7
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 846f5c8
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 0129e58
chore: converts BasePopoverReactionList to functional component
vadymbokatov 29f41f2
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 85dcf30
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 1954ddc
chore: fixes the linting error regarding the named export
vadymbokatov ffe26d6
Update src/pages/home/report/ReactionList/PopoverReactionList/index.tsx
vadymbokatov a1a4f17
Update src/pages/home/report/ReactionList/BaseReactionList.tsx
vadymbokatov 1059ccf
Update src/pages/home/report/ReactionList/BaseReactionList.tsx
vadymbokatov 8765899
Update src/pages/home/report/ReactionList/PopoverReactionList/BasePop…
vadymbokatov 37b6250
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov ffca03e
fix: ref object not getting passed as the second arg
vadymbokatov 32b3695
fix: types naming convention
vadymbokatov cebd4dc
chore: removes unneeded JSDocs
vadymbokatov 3f82336
chore: makes isVisible prop optional
vadymbokatov ac5f088
fix: menu ref not getting forwarded and menu not showing up
vadymbokatov f2e0f53
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 5af50d4
chore: makes hasUserReacted optional with default value
vadymbokatov ce370cd
chore: removes unneeded JSDocs returns and comments
vadymbokatov 3fa2b09
fix: reuses the AnchorPosition type
vadymbokatov bceaca2
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 19401b7
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 288a67c
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov ba47730
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov b1b7451
Update src/hooks/useBasePopoverReactionList/index.ts
vadymbokatov ecccc96
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov e9761c3
fix: adds the missing dependencies in the useEffect
vadymbokatov a2d1c03
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 1925a11
fix: popover position
vadymbokatov cd2a45c
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov b083179
chore: adds white space for better readability
vadymbokatov 2bbe9cb
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 2916ba2
Update src/pages/home/report/ReactionList/types.ts
vadymbokatov 5dbe827
chore: removes unnecessary comments
vadymbokatov e5ded33
chore: removes unnecessary variable
vadymbokatov e4a843a
chore: removes unnecessary comments
vadymbokatov 9dfd657
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import {useEffect, useRef, useState} from 'react'; | ||
| import type {SyntheticEvent} from 'react'; | ||
| import {Dimensions} from 'react-native'; | ||
| import * as EmojiUtils from '@libs/EmojiUtils'; | ||
| import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; | ||
| import type {BasePopoverReactionListHookProps, ReactionListAnchor, ShowReactionList} from './types'; | ||
|
|
||
| export default function useBasePopoverReactionList({emojiName, emojiReactions, accountID, reportActionID, preferredLocale}: BasePopoverReactionListHookProps) { | ||
| const [isPopoverVisible, setIsPopoverVisible] = useState(false); | ||
| const [cursorRelativePosition, setCursorRelativePosition] = useState({horizontal: 0, vertical: 0}); | ||
| const [popoverAnchorPosition, setPopoverAnchorPosition] = useState({horizontal: 0, vertical: 0}); | ||
| const reactionListRef = useRef<ReactionListAnchor>(null); | ||
|
|
||
| function getReactionInformation() { | ||
| const selectedReaction = emojiReactions?.[emojiName]; | ||
|
|
||
| if (!selectedReaction) { | ||
| // If there is no reaction, we return default values | ||
| return { | ||
| emojiName: '', | ||
| reactionCount: 0, | ||
| emojiCodes: [], | ||
| hasUserReacted: false, | ||
| users: [], | ||
| }; | ||
| } | ||
|
|
||
| const {emojiCodes, reactionCount, hasUserReacted, userAccountIDs} = EmojiUtils.getEmojiReactionDetails(emojiName, selectedReaction, accountID); | ||
|
|
||
| const users = PersonalDetailsUtils.getPersonalDetailsByIDs(userAccountIDs, accountID, true); | ||
| return { | ||
| emojiName, | ||
| emojiCodes, | ||
| reactionCount, | ||
| hasUserReacted, | ||
| users, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Get the BasePopoverReactionList anchor position | ||
| * We calculate the achor coordinates from measureInWindow async method | ||
| */ | ||
| function getReactionListMeasuredLocation(): Promise<{x: number; y: number}> { | ||
| return new Promise((resolve) => { | ||
| const reactionListAnchor = reactionListRef.current; | ||
| if (reactionListAnchor && 'measureInWindow' in reactionListAnchor) { | ||
| reactionListAnchor.measureInWindow((x, y) => resolve({x, y})); | ||
| } else { | ||
| resolve({x: 0, y: 0}); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Show the ReactionList modal popover. | ||
| * | ||
| * @param event - Object - A press event. | ||
| * @param reactionListAnchor - Element - reactionListAnchor | ||
| */ | ||
| const showReactionList: ShowReactionList = (event, reactionListAnchor) => { | ||
| // We get the cursor coordinates and the reactionListAnchor coordinates to calculate the popover position | ||
| const nativeEvent = (event as SyntheticEvent<ReactionListAnchor, MouseEvent>)?.nativeEvent || {}; | ||
| reactionListRef.current = reactionListAnchor; | ||
| getReactionListMeasuredLocation().then(({x, y}) => { | ||
| setCursorRelativePosition({horizontal: nativeEvent.pageX - x, vertical: nativeEvent.pageY - y}); | ||
| setPopoverAnchorPosition({ | ||
| horizontal: nativeEvent.pageX, | ||
| vertical: nativeEvent.pageY, | ||
|
MonilBhavsar marked this conversation as resolved.
Resolved
|
||
| }); | ||
| setIsPopoverVisible(true); | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Hide the ReactionList modal popover. | ||
| */ | ||
| function hideReactionList() { | ||
| setIsPopoverVisible(false); | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| const dimensionsEventListener = Dimensions.addEventListener('change', () => { | ||
| if (!isPopoverVisible) { | ||
| // If the popover is not visible, we don't need to update the component | ||
| return; | ||
| } | ||
| getReactionListMeasuredLocation().then(({x, y}) => { | ||
| if (!x || !y) { | ||
| return; | ||
| } | ||
| setPopoverAnchorPosition({ | ||
| horizontal: cursorRelativePosition.horizontal + x, | ||
| vertical: cursorRelativePosition.vertical + y, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| return () => { | ||
| dimensionsEventListener.remove(); | ||
| }; | ||
| }, [ | ||
| isPopoverVisible, | ||
| reportActionID, | ||
| preferredLocale, | ||
| cursorRelativePosition.horizontal, | ||
| cursorRelativePosition.vertical, | ||
| popoverAnchorPosition.horizontal, | ||
| popoverAnchorPosition.vertical, | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isPopoverVisible) { | ||
| // If the popover is not visible, we don't need to update the component | ||
| return; | ||
| } | ||
|
|
||
| // Hide the list when all reactions are removed | ||
| const users = emojiReactions?.[emojiName]?.users; | ||
|
|
||
| if (!users || Object.keys(users).length > 0) { | ||
| return; | ||
| } | ||
|
|
||
| hideReactionList(); | ||
| }, [emojiReactions, emojiName, isPopoverVisible, reportActionID, preferredLocale]); | ||
|
|
||
| return {isPopoverVisible, cursorRelativePosition, popoverAnchorPosition, getReactionInformation, hideReactionList, reactionListRef, showReactionList}; | ||
| } | ||
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,60 @@ | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import type {LocaleContextProps} from '@components/LocaleContextProvider'; | ||
| import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; | ||
| import type {ReactionListAnchor, ReactionListEvent} from '@pages/home/ReportScreenContext'; | ||
| import type {AnchorPosition} from '@src/styles'; | ||
| import type {ReportActionReactions} from '@src/types/onyx'; | ||
|
|
||
| type BasePopoverReactionListOnyxProps = { | ||
| /** The reactions for the report action */ | ||
| emojiReactions: OnyxEntry<ReportActionReactions>; | ||
| }; | ||
|
|
||
| type BasePopoverReactionListProps = { | ||
| /** The ID of the report action */ | ||
| reportActionID: string; | ||
|
|
||
| /** The emoji name */ | ||
| emojiName: string; | ||
| }; | ||
|
|
||
| type BasePopoverReactionListHookProps = BasePopoverReactionListProps & { | ||
| /** The reactions for the report action */ | ||
| emojiReactions: OnyxEntry<ReportActionReactions>; | ||
|
|
||
| /** The current user's account ID */ | ||
| accountID: WithCurrentUserPersonalDetailsProps['currentUserPersonalDetails']['accountID']; | ||
|
|
||
| preferredLocale: LocaleContextProps['preferredLocale']; | ||
| }; | ||
|
|
||
| type BasePopoverReactionListPropsWithLocalWithOnyx = WithCurrentUserPersonalDetailsProps & BasePopoverReactionListOnyxProps & BasePopoverReactionListProps; | ||
| type BasePopoverReactionListState = { | ||
| /** Whether the popover is visible */ | ||
| isPopoverVisible: boolean; | ||
|
|
||
| /** The horizontal and vertical position (relative to the screen) where the popover will display. */ | ||
| popoverAnchorPosition: AnchorPosition; | ||
|
|
||
| /** The horizontal and vertical position (relative to the screen) where the cursor is. */ | ||
| cursorRelativePosition: AnchorPosition; | ||
| }; | ||
|
|
||
| type ShowReactionList = (event: ReactionListEvent | undefined, reactionListAnchor: ReactionListAnchor) => void; | ||
|
|
||
| type InnerReactionListRef = { | ||
| showReactionList: ShowReactionList; | ||
| hideReactionList: () => void; | ||
| isActiveReportAction: (actionID: number | string) => boolean; | ||
| }; | ||
|
|
||
| export type { | ||
| BasePopoverReactionListProps, | ||
| BasePopoverReactionListHookProps, | ||
| BasePopoverReactionListPropsWithLocalWithOnyx, | ||
| BasePopoverReactionListState, | ||
| BasePopoverReactionListOnyxProps, | ||
| ShowReactionList, | ||
| ReactionListAnchor, | ||
| InnerReactionListRef, | ||
| }; |
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 was deleted.
Oops, something went wrong.
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.