···
1
-
import { Message } from "@/components/Chat/Message";
2
-
import { Loading } from "@/components/primitives/Loading";
3
-
import { Text } from "@/components/primitives/Text";
4
-
import { useChannel } from "@/lib/hooks/useChannel";
5
-
import type { AtUri } from "@/lib/types/atproto";
6
-
import { useProfile } from "@/providers/authed/ProfileProvider";
7
-
import { useCurrentPalette } from "@/providers/ThemeProvider";
8
-
import { useState } from "react";
15
-
} from "react-native";
17
-
export const Chat = ({ channelAtUri }: { channelAtUri: AtUri }) => {
18
-
const [inputText, setInputText] = useState("");
19
-
const { messages, sendMessageToChannel, isConnected } =
20
-
useChannel(channelAtUri);
21
-
const { semantic } = useCurrentPalette();
23
-
const handleSend = () => {
24
-
if (inputText.trim()) {
25
-
sendMessageToChannel(inputText);
30
-
const { profile, isLoading } = useProfile();
32
-
return isLoading ? (
38
-
flexDirection: "column",
39
-
justifyContent: "center",
40
-
alignItems: "stretch",
48
-
flexDirection: "row",
49
-
justifyContent: "space-between",
51
-
borderBottomWidth: 1,
52
-
borderBottomColor: semantic.border,
53
-
alignItems: "center",
57
-
Hi, {profile.displayName ?? profile.handle}!
59
-
{profile.avatar && (
64
-
borderRadius: 2000000000,
66
-
source={{ uri: profile.avatar }}
75
-
borderBottomWidth: 1,
76
-
borderBottomColor: semantic.border,
85
-
{isConnected ? "🟢 Connected" : "🔴 Disconnected"}
95
-
{messages.map((msg, index) => (
96
-
<Message message={msg} key={index} />
102
-
flexDirection: "row",
105
-
borderTopColor: semantic.border,
112
-
borderColor: semantic.border,
114
-
paddingHorizontal: 12,
115
-
paddingVertical: 8,
118
-
color: semantic.text,
121
-
onChangeText={setInputText}
123
-
placeholderTextColor={semantic.textTertiary}
124
-
onSubmitEditing={handleSend}
128
-
backgroundColor: semantic.primary,
129
-
paddingHorizontal: 20,
130
-
paddingVertical: 10,
132
-
justifyContent: "center",
134
-
onPress={handleSend}
135
-
disabled={!isConnected}
139
-
color: semantic.textInverse,
146
-
</TouchableOpacity>