Skip to content

Commit

Permalink
feat(lib): resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Sep 19, 2023
2 parents bd8a59a + 6b69833 commit 35bc299
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function ListItem({ title, avatar, badge, onPress, showCheckbox, checked
{badge ? (
<View style={styles.badge}>
<Text variant="body" color="neutral0">
5
{badge}
</Text>
</View>
) : null}
Expand All @@ -59,6 +59,7 @@ const styles = StyleSheet.create({
},
title: {
paddingHorizontal: 16,
flexGrow: 1,
},
badge: {
backgroundColor: colors.badge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function UserSuggestionBox({ users, onUserSelect }: UserSuggestionBoxProp
return (
<View style={styles.container}>
{users.map((user) => (
<ListItem title={user.name} key={user.id} onPress={() => onUserSelect(user)} />
<ListItem title={user.name || user.id} key={user.id} onPress={() => onUserSelect(user)} />
))}
</View>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BottomTabsParamList, "Mentions">) {
const { chat, setCurrentChannel } = useContext(ChatContext)
const [mentions, setMentions] = useState<UserMentionData[]>([])
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 (
<View style={styles.loading}>
{loading ? (
<ActivityIndicator size="large" color={colors.navy700} />
) : (
<Text textAlign="center">No mentions found.</Text>
)}
</View>
)
}

export function MentionsScreen() {
return (
<View>
<Text>Mentions screen</Text>
</View>
<ScrollView style={styles.container}>
{mentions.map((mention, index) => (
<View key={mention.event.timetoken}>
<TouchableHighlight
onPress={() => openChannel(mention.message.channelId)}
underlayColor={colors.neutral50}
>
<View>
<Text variant="smallBody" color="neutral600">
{TimetokenUtils.timetokenToDate(mention.message.timetoken).toLocaleString([], {
weekday: "short",
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
})}
</Text>
<View style={styles.message}>
<Avatar source={mention.user} style={{ marginTop: 10 }} />
<View style={styles.bubble}>
<Text>{mention.message.text}</Text>
</View>
</View>
</View>
</TouchableHighlight>
{index !== mentions.length - 1 && <Line style={{ marginVertical: 16 }} />}
</View>
))}
</ScrollView>
)
}

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,
},
})
9 changes: 6 additions & 3 deletions samples/react-native-group-chat/ui-components/line/Line.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from "react"
import { View } from "react-native"
import { View, ViewProps } from "react-native"

export function Line() {
return <View style={{ width: "100%", height: 1, backgroundColor: "#E2E8F0" }} />
export function Line(props: ViewProps) {
const { style, ...rest } = props
return (
<View style={[{ width: "100%", height: 1, backgroundColor: "#E2E8F0" }, style]} {...rest} />
)
}

0 comments on commit 35bc299

Please sign in to comment.