Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/chat/composing.tsx
Views: 687
import { useRedux } from "@cocalc/frontend/app-framework";1import { getUserName } from "./chat-log";2import ProgressEstimate from "@cocalc/frontend/components/progress-estimate";3import { Avatar } from "@cocalc/frontend/account/avatar/avatar";45export default function Composing({ projectId, path, accountId, userMap }) {6const drafts = useRedux(["drafts"], projectId, path);78if (!drafts || drafts.size == 0) {9return null;10}1112const v: JSX.Element[] = [];13const cutoff = Date.now() - 1000 * 30; // 30s14for (const [senderId] of drafts) {15if (accountId == senderId) {16// this is us17continue;18}19const record = drafts.get(senderId);20if (record.get("date") != 0) {21// editing an already sent message, rather than composing a new one.22// This is indicated elsewhere (at that message).23continue;24}25if (record.get("active") < cutoff || !record.get("input")?.trim()) {26continue;27}28v.push(29<div30key={senderId}31style={{ margin: "5px", color: "#666", textAlign: "center" }}32>33<Avatar size={20} account_id={senderId} />34<span style={{ marginLeft: "15px" }}>35{getUserName(userMap, senderId)} is writing a message...36</span>37{senderId?.startsWith("chatgpt") && (38<ProgressEstimate39style={{ marginLeft: "15px", maxWidth: "600px" }}40seconds={5 /* seconds until answer starts stream */}41/>42)}43</div>44);45// NOTE: We use a longer chatgpt estimate here than in the frontend nextjs46// app, since the nature of questions when you're fully using cocalc47// is that they tend to be much deeper.48}49if (v.length == 0) return null;50return <div>{v}</div>;51}525354