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/composing.tsx
Views: 687
1
import { useRedux } from "@cocalc/frontend/app-framework";
2
import { getUserName } from "./chat-log";
3
import ProgressEstimate from "@cocalc/frontend/components/progress-estimate";
4
import { Avatar } from "@cocalc/frontend/account/avatar/avatar";
5
6
export default function Composing({ projectId, path, accountId, userMap }) {
7
const drafts = useRedux(["drafts"], projectId, path);
8
9
if (!drafts || drafts.size == 0) {
10
return null;
11
}
12
13
const v: JSX.Element[] = [];
14
const cutoff = Date.now() - 1000 * 30; // 30s
15
for (const [senderId] of drafts) {
16
if (accountId == senderId) {
17
// this is us
18
continue;
19
}
20
const record = drafts.get(senderId);
21
if (record.get("date") != 0) {
22
// editing an already sent message, rather than composing a new one.
23
// This is indicated elsewhere (at that message).
24
continue;
25
}
26
if (record.get("active") < cutoff || !record.get("input")?.trim()) {
27
continue;
28
}
29
v.push(
30
<div
31
key={senderId}
32
style={{ margin: "5px", color: "#666", textAlign: "center" }}
33
>
34
<Avatar size={20} account_id={senderId} />
35
<span style={{ marginLeft: "15px" }}>
36
{getUserName(userMap, senderId)} is writing a message...
37
</span>
38
{senderId?.startsWith("chatgpt") && (
39
<ProgressEstimate
40
style={{ marginLeft: "15px", maxWidth: "600px" }}
41
seconds={5 /* seconds until answer starts stream */}
42
/>
43
)}
44
</div>
45
);
46
// NOTE: We use a longer chatgpt estimate here than in the frontend nextjs
47
// app, since the nature of questions when you're fully using cocalc
48
// is that they tend to be much deeper.
49
}
50
if (v.length == 0) return null;
51
return <div>{v}</div>;
52
}
53
54