Page MenuHomePhabricator

[native] introduce MarkdownUserMention component
ClosedPublic

Authored by ginsu on Oct 6 2023, 5:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 1, 8:43 PM
Unknown Object (File)
Fri, Nov 1, 8:43 PM
Unknown Object (File)
Fri, Nov 1, 8:43 PM
Unknown Object (File)
Fri, Nov 1, 8:43 PM
Unknown Object (File)
Fri, Nov 1, 8:36 PM
Unknown Object (File)
Mon, Oct 21, 3:44 AM
Unknown Object (File)
Oct 16 2024, 12:42 AM
Unknown Object (File)
Oct 15 2024, 7:25 AM

Details

Summary

The last step here is to render a Text component that has an onPress event that will navigate to a user profile whenever that callback is called. Building this component, I took some inspiration from @patryk's work with the MarkdownChatMention component.

https://github.com/CommE2E/comm/blob/master/native/markdown/markdown-chat-mention.react.js

This is step 4 in the list below
Outlined below are the steps I will take to make @metion of a user into a touchable

  1. Introduce createMemberMapForUserMentions function (Right now we only store a set of usernames but we also will want to know the id of the user based on the username)
  2. Introduce parseUserMentions function (We will use this function to get and return a userID from the membersMap)
  3. Introduce userProfileBottomSheetActive state to the markdown context (This will be used for disabling the press to focus on a message functionality)
  4. Introduce MarkdownUserMention component (this will render the touchable that will navigate to the user profile)

Depends on D9393

Test Plan

Please see the demo video below

Testing the onLongPress callback:

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

native/markdown/markdown-user-mention.react.js
32–40 ↗(On Diff #31741)

useFocusEffect is a hook from react-navigation. This allows us to run side-effects (in this case setting the userProfileBottomSheetActive state back to false) as the MessageList screen comes into focus again (this would happen whenever we close out and navigate away from the user profile bottom sheet)

https://reactnavigation.org/docs/use-focus-effect/

47 ↗(On Diff #31741)

We set userProfileBottomSheetActive for this particular message to true here so that it disables the press to focus on the message functionality

ginsu requested review of this revision.Oct 6 2023, 5:37 AM
native/markdown/markdown-user-mention.react.js
33 ↗(On Diff #31741)

Let's keep all hook usages as top-level declarations or assignments. This is the same thing we tend to ask for await calls – we want to make sure hooks are clearly visible at the top level

atul requested changes to this revision.Oct 9 2023, 1:45 PM

Requesting changes for @ashoat's suggestion

This revision now requires changes to proceed.Oct 9 2023, 1:45 PM
atul added inline comments.
native/markdown/markdown-user-mention.react.js
25 ↗(On Diff #31880)

Wonder if we should have a hook for this?

40 ↗(On Diff #31880)

Haven't used useFocusEffect, do we need a dependency list passed as second arg, or is this sufficient?

56–63 ↗(On Diff #31880)

Doesn't hurt to memoize

This revision is now accepted and ready to land.Oct 10 2023, 2:58 PM
native/markdown/markdown-user-mention.react.js
25 ↗(On Diff #31880)
40 ↗(On Diff #31880)

Sorry forgot to copy over my inline comment from earlier:

useFocusEffect is a hook from react-navigation. This allows us to run side-effects (in this case setting the userProfileBottomSheetActive state back to false) as the MessageList screen comes into focus again (this would happen whenever we close out and navigate away from the user profile bottom sheet)
https://reactnavigation.org/docs/use-focus-effect/

address comments + rebase before landing