-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathConversation.tsx
103 lines (98 loc) · 2.79 KB
/
Conversation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {
Button,
Flex,
Group,
LoadingOverlay,
ScrollArea,
Stack,
Text,
Title,
} from "@mantine/core";
import type { Conversation as XmtpConversation } from "@xmtp/browser-sdk";
import { useEffect } from "react";
import { Link, Outlet } from "react-router";
import { Messages } from "@/components/Messages/Messages";
import { useBodyClass } from "@/hooks/useBodyClass";
import { useConversation } from "@/hooks/useConversation";
import { Composer } from "./Composer";
export type ConversationProps = {
conversation?: XmtpConversation;
loading: boolean;
};
export const Conversation: React.FC<ConversationProps> = ({
conversation,
loading,
}) => {
useBodyClass("main-flex-layout");
const {
messages,
getMessages,
loading: conversationLoading,
syncing: conversationSyncing,
} = useConversation(conversation);
useEffect(() => {
const loadMessages = async () => {
await getMessages();
};
void loadMessages();
}, [conversation?.id]);
const handleSync = async () => {
await getMessages(undefined, true);
};
return (
<>
<Stack
style={{
overflow: "hidden",
margin: "calc(var(--mantine-spacing-md) * -1)",
}}
pos="relative"
gap="lg"
flex={1}>
{conversation && (
<>
<Flex align="center" gap="xs" justify="space-between" p="md">
{conversation.name ? (
<Title order={3}>{conversation.name}</Title>
) : (
<Text size="lg" fw={700} c="dimmed">
Untitled
</Text>
)}
<Group gap="xs">
<Button component={Link} to="manage">
Manage
</Button>
<Button
loading={conversationSyncing}
onClick={() => void handleSync()}>
Sync
</Button>
</Group>
</Flex>
<Stack flex={1} style={{ overflow: "hidden" }}>
{loading || conversationLoading || messages.length === 0 ? (
<Stack
style={{
margin: "calc(var(--mantine-spacing-md) * -1)",
}}
flex={1}
align="center"
justify="center">
{messages.length === 0 && <Text>No messages</Text>}
</Stack>
) : (
<ScrollArea type="scroll" className="scrollfade">
<Messages messages={messages} />
</ScrollArea>
)}
</Stack>
<Composer conversation={conversation} />
<LoadingOverlay visible={loading || conversationLoading} />
</>
)}
</Stack>
<Outlet />
</>
);
};