CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/chat/viewer.tsx
Views: 687
1
/*
2
Used for viewing a list of messages, e.g., in timetravel.
3
*/
4
5
import { MessageList, getSortedDates } from "./chat-log";
6
import { useTypedRedux } from "@cocalc/frontend/app-framework";
7
import { useMemo } from "react";
8
import { Map as immutableMap } from "immutable";
9
import type { ChatMessages } from "./types";
10
11
export default function Viewer({
12
doc,
13
font_size,
14
}: {
15
doc;
16
font_size?: number;
17
}) {
18
const messages = useMemo<ChatMessages>(() => {
19
let m = immutableMap();
20
for (let v of doc.get()) {
21
if (v.get("event") == "chat") {
22
const date = new Date(v.get("date"));
23
v = v.set("date", date);
24
m = m.set(`${date.valueOf()}`, v);
25
}
26
}
27
return m as ChatMessages;
28
}, [doc]);
29
const user_map = useTypedRedux("users", "user_map");
30
const account_id = useTypedRedux("account", "account_id");
31
const { dates: sortedDates, numChildren } = useMemo(() => {
32
return getSortedDates(messages, "", account_id, undefined);
33
}, [messages]);
34
35
return (
36
<MessageList
37
messages={messages}
38
user_map={user_map}
39
account_id={account_id}
40
fontSize={font_size}
41
mode="standalone"
42
sortedDates={sortedDates}
43
numChildren={numChildren}
44
/>
45
);
46
}
47
48