forked from webxdc/webxdc-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChat.tsx
76 lines (69 loc) · 1.86 KB
/
Chat.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
import {
Component,
For,
Accessor,
createSignal,
createEffect,
Show,
} from "solid-js";
import { Flex, Box, Table, Thead, Tbody, Th, Badge } from "@hope-ui/solid";
import { Message } from "../types/message";
import ChatRow from "./ChatRow";
import { getMessages, summary } from "./store";
export type Search = {
instanceId?: string;
type?: string;
};
const Chat: Component<{
search: Accessor<Search>;
onSelectMessage: (message: Message) => void;
}> = (props) => {
const [chatIndex, setChatIndex] = createSignal<number | null>(null);
createEffect(() => {
// whenever we get a new message, we should scroll to the last message
getMessages({}).length;
// we scroll to the last message
scrollToLastChat();
});
return (
<Flex flexDirection="column">
<Show when={summary()}>
{(summary) => <Badge>Summary: {summary}</Badge>}
</Show>
<Box>
<Table id="chat" dense css={{ "table-layout": "fixed" }}>
<Thead>
<Th width="10%" minWidth="7em">
Id
</Th>
<Th>Info</Th>
</Thead>
<Tbody>
<For
each={getMessages({
instanceId: props.search().instanceId,
type: "sent",
info: true,
})}
>
{(message, index) => (
<ChatRow
isSelected={chatIndex() === index()}
message={message}
onSelect={(message) => {
setChatIndex(index());
props.onSelectMessage(message);
}}
/>
)}
</For>
</Tbody>
</Table>
</Box>
</Flex>
);
};
function scrollToLastChat() {
document.querySelector("#chat > tbody > tr:last-child")?.scrollIntoView();
}
export default Chat;