aboutsummaryrefslogtreecommitdiff
path: root/src/utils/comments.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-04 20:46:27 -0400
committerIvan Chen <ivan@tagg.id>2021-05-04 20:48:09 -0400
commit7f9799c6693254f8eb6729c0977826694c28c437 (patch)
tree48d119dfa78008b4c6fe44598eb38bf21da0c444 /src/utils/comments.tsx
parentc23feea922da063d88d031f25b72b53ba593ec04 (diff)
added navigation to profile
Diffstat (limited to 'src/utils/comments.tsx')
-rw-r--r--src/utils/comments.tsx46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/utils/comments.tsx b/src/utils/comments.tsx
index c0b522f2..47d26bb5 100644
--- a/src/utils/comments.tsx
+++ b/src/utils/comments.tsx
@@ -1,23 +1,26 @@
import React from 'react';
-import {Text} from 'react-native';
+import {StyleProp, Text, TextStyle} from 'react-native';
import {
isMentionPartType,
parseValue,
Part,
PartType,
} from 'react-native-controlled-mentions';
+import {TouchableOpacity} from 'react-native-gesture-handler';
import TaggTypeahead from '../components/common/TaggTypeahead';
import {TAGG_LIGHT_BLUE} from '../constants';
+import {UserType} from '../types';
/**
* Part renderer
*
* https://github.com/dabakovich/react-native-controlled-mentions#rendering-mentioninputs-value
- *
- * @param part
- * @param index
*/
-const renderPart = (part: Part, index: number) => {
+const renderPart = (
+ part: Part,
+ index: number,
+ handlePress: (user: UserType) => void,
+) => {
// Just plain text
if (!part.partType) {
return <Text key={index}>{part.text}</Text>;
@@ -26,12 +29,18 @@ const renderPart = (part: Part, index: number) => {
// Mention type part
if (isMentionPartType(part.partType)) {
return (
- <Text
+ <TouchableOpacity
key={`${index}-${part.data?.trigger}`}
- style={part.partType.textStyle}
- onPress={() => console.log('Pressed', part.data)}>
- {part.text}
- </Text>
+ onPress={() => {
+ if (part.data) {
+ handlePress({
+ userId: part.data.id,
+ username: part.data.name,
+ });
+ }
+ }}>
+ <Text style={part.partType.textStyle}>{part.text}</Text>
+ </TouchableOpacity>
);
}
@@ -45,23 +54,26 @@ const renderPart = (part: Part, index: number) => {
interface RenderProps {
value: string;
- partTypes: PartType[];
+ styles: StyleProp<TextStyle>;
+ onPress: (user: UserType) => void;
}
/**
* Value renderer. Parsing value to parts array and then mapping the array using 'renderPart'
*
* https://github.com/dabakovich/react-native-controlled-mentions#rendering-mentioninputs-value
- *
- * @param value - value from MentionInput
- * @param partTypes - the part types array that you providing to MentionInput
*/
export const renderTextWithMentions: React.FC<RenderProps> = ({
value,
- partTypes,
+ styles,
+ onPress,
}) => {
- const {parts} = parseValue(value, partTypes);
- return <Text>{parts.map(renderPart)}</Text>;
+ const {parts} = parseValue(value, mentionPartTypes);
+ return (
+ <Text style={styles}>
+ {parts.map((part, index) => renderPart(part, index, onPress))}
+ </Text>
+ );
};
export const mentionPartTypes: PartType[] = [