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/chat-indicator.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// TODO: for a frame tree it really only makes sense for this button6// to always show the chat. For sagews and old stuff it should hide7// and show it. But it's very hard to know from here which doc type8// this is... so for now it still sort of toggles. For now things9// do work properly via a hack in close_chat in project_actions.1011import { filename_extension } from "@cocalc/util/misc";12import { Button, Tooltip } from "antd";13import { debounce } from "lodash";14import { useMemo } from "react";15import { FormattedMessage, useIntl } from "react-intl";16import { UsersViewing } from "@cocalc/frontend/account/avatar/users-viewing";17import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";18import { HiddenXS } from "@cocalc/frontend/components";19import { Icon } from "@cocalc/frontend/components/icon";20import track from "@cocalc/frontend/user-tracking";21import { labels } from "../i18n";2223export type ChatState =24| "" // not opened (also undefined counts as not open)25| "internal" // chat is open and managed internally (via frame tree)26| "external" // chat is open and managed externally (e.g., legacy sage worksheet)27| "pending"; // chat should be opened when the file itself is actually initialized.2829const CHAT_INDICATOR_STYLE: React.CSSProperties = {30fontSize: "15pt",31paddingTop: "3px",32cursor: "pointer",33} as const;3435const USERS_VIEWING_STYLE: React.CSSProperties = {36maxWidth: "120px",37marginRight: "5px",38} as const;3940interface Props {41project_id: string;42path: string;43chatState?: ChatState;44}4546export function ChatIndicator({ project_id, path, chatState }: Props) {47const style: React.CSSProperties = {48...CHAT_INDICATOR_STYLE,49...{ display: "flex" },50};5152return (53<div style={style}>54<UsersViewing55project_id={project_id}56path={path}57style={USERS_VIEWING_STYLE}58/>59<ChatButton project_id={project_id} path={path} chatState={chatState} />60</div>61);62}6364function ChatButton({ project_id, path, chatState }) {65const intl = useIntl();6667const toggleChat = debounce(68() => {69const actions = redux.getProjectActions(project_id);70if (chatState) {71track("close-chat", { project_id, path, how: "chat-button" });72actions.close_chat({ path });73} else {74track("open-chat", { project_id, path, how: "chat-button" });75actions.open_chat({ path });76}77},781000,79{ leading: true },80);81const fileUse = useTypedRedux("file_use", "file_use");82const isNewChat = useMemo(83() =>84!!redux.getStore("file_use")?.get_file_info(project_id, path)85?.is_unseenchat,86[fileUse, project_id, path],87);8889if (filename_extension(path) === "sage-chat") {90// Special case: do not show side chat for chatrooms91return null;92}9394return (95<Tooltip96title={97<span>98<Icon name="comment" style={{ marginRight: "5px" }} />99<FormattedMessage100id="chat.chat-indicator.tooltip"101defaultMessage={"Hide or Show Document Chat"}102/>103</span>104}105placement={"leftTop"}106mouseEnterDelay={0.5}107>108<Button109type="text"110danger={isNewChat}111className={isNewChat ? "smc-chat-notification" : undefined}112onClick={toggleChat}113style={{ color: chatState ? "orange" : "#333" }}114>115<Icon name="comment" />116<HiddenXS>117<span style={{ marginLeft: "5px" }}>118{intl.formatMessage(labels.chat)}119</span>120</HiddenXS>121</Button>122</Tooltip>123);124}125126127