From 6b69833892037b2b8022a7992f4c930892539fc1 Mon Sep 17 00:00:00 2001 From: Przemek Janowski
scrollToMessage(quotedMessage)} /> @@ -102,7 +102,7 @@ export function useCommonChatRenderers({ {userSuggestionComponent} > ) - }, [messageDraft, showSuggestedUsers, scrollToMessage]) + }, [messageDraft, showSuggestedUsers, scrollToMessage, handleUserToMention, suggestedUsers]) const renderMessagePart = useCallback( (messagePart: MixedTextTypedElement, index: number, userId: string | number) => { diff --git a/samples/react-native-group-chat/screens/tabs/mentions/MentionsScreen.tsx b/samples/react-native-group-chat/screens/tabs/mentions/MentionsScreen.tsx index 2e712adc..45dc1349 100644 --- a/samples/react-native-group-chat/screens/tabs/mentions/MentionsScreen.tsx +++ b/samples/react-native-group-chat/screens/tabs/mentions/MentionsScreen.tsx @@ -1,10 +1,108 @@ -import React from "react"; -import { View, Text } from "react-native"; +import React, { useContext, useState } from "react" +import { View, StyleSheet, ScrollView, TouchableHighlight, ActivityIndicator } from "react-native" +import { useFocusEffect } from "@react-navigation/native" +import { UserMentionData, TimetokenUtils } from "@pubnub/chat" +import { BottomTabScreenProps } from "@react-navigation/bottom-tabs" + +import { colorPalette as colors, Line, Text } from "../../../ui-components" +import { ChatContext } from "../../../context" +import { Avatar } from "../../../components" +import { BottomTabsParamList } from "../../../types" + +export function MentionsScreen({ + navigation, +}: BottomTabScreenProps) { + const { chat, setCurrentChannel } = useContext(ChatContext) + const [mentions, setMentions] = useState ([]) + const [loading, setLoading] = useState(true) + + async function openChannel(channelId: string) { + if (!chat) return + const channel = await chat.getChannel(channelId) + if (!channel) { + alert("This channel no longer exists.") + return + } + setCurrentChannel(channel) + navigation.navigate("Chat") + } + + useFocusEffect(() => { + const init = async () => { + if (!chat) return + const { enhancedMentionsData } = await chat.getCurrentUserMentions() + setMentions(enhancedMentionsData.reverse()) + setLoading(false) + } + if (chat) init() + }) + + if (loading || !mentions.length) { + return ( + + {loading ? ( + + ) + } -export function MentionsScreen() { return ( -+ ) : ( + No mentions found. + )} +- +Mentions screen -+ {mentions.map((mention, index) => ( + ) } + +const styles = StyleSheet.create({ + loading: { + backgroundColor: colors.neutral0, + flex: 1, + justifyContent: "center", + }, + container: { + backgroundColor: colors.neutral0, + flex: 1, + padding: 16, + }, + message: { + flexDirection: "row", + marginTop: 10, + marginLeft: 10, + }, + bubble: { + backgroundColor: colors.neutral50, + borderRadius: 6, + borderTopLeftRadius: 0, + marginLeft: 10, + padding: 10, + }, +}) diff --git a/samples/react-native-group-chat/ui-components/line/Line.tsx b/samples/react-native-group-chat/ui-components/line/Line.tsx index be7b393c..a750e2e5 100644 --- a/samples/react-native-group-chat/ui-components/line/Line.tsx +++ b/samples/react-native-group-chat/ui-components/line/Line.tsx @@ -1,6 +1,9 @@ import React from "react" -import { View } from "react-native" +import { View, ViewProps } from "react-native" -export function Line() { - return+ + ))} +openChannel(mention.message.channelId)} + underlayColor={colors.neutral50} + > + + {index !== mentions.length - 1 &&+ ++ {TimetokenUtils.timetokenToDate(mention.message.timetoken).toLocaleString([], { + weekday: "short", + month: "short", + day: "numeric", + hour: "numeric", + minute: "numeric", + })} + ++ ++ + +{mention.message.text} +} + +export function Line(props: ViewProps) { + const { style, ...rest } = props + return ( + + ) }