Skip to content

Commit 9a73ae5

Browse files
committed
chat: massive refactor and make a frame editor -- work in progress
1 parent 966f7c1 commit 9a73ae5

File tree

14 files changed

+40
-124
lines changed

14 files changed

+40
-124
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ export class ChatActions extends Actions<ChatState> {
8787
});
8888
}
8989

90-
public close(): void {
91-
this.syncdb?.close();
92-
delete this.syncdb;
93-
}
94-
9590
// Initialize the state of the store from the contents of the syncdb.
9691
public init_from_syncdb(): void {
9792
if (this.syncdb == null) {
@@ -497,12 +492,6 @@ export class ChatActions extends Actions<ChatState> {
497492
this.setState({ is_uploading });
498493
}
499494

500-
public change_font_size(delta: number): void {
501-
if (!this.store) return;
502-
const font_size = this.store.get("font_size") + delta;
503-
this.setState({ font_size });
504-
}
505-
506495
// Scan through all messages and figure out what hashtags are used.
507496
// Of course, at some point we should try to use efficient algorithms
508497
// to make this faster incrementally.

src/packages/frontend/chat/chat-log.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export function ChatLog({
5151
actions,
5252
}: Props) {
5353
const messages = useRedux(["messages"], project_id, path) as ChatMessages;
54-
const font_size = useRedux(["font_size"], project_id, path);
5554
const scrollToBottom = useRedux(["scrollToBottom"], project_id, path);
5655
const llm_cost_reply: [number, number] = useRedux(
5756
["llm_cost_reply"],
@@ -148,6 +147,7 @@ export function ChatLog({
148147
<>
149148
{visibleHashtags.size > 0 && (
150149
<HashtagBar
150+
style={{ margin: "5px 0" }}
151151
actions={{
152152
set_hashtag_state: (tag, state) => {
153153
actions.setHashtagState(tag, state);
@@ -176,7 +176,7 @@ export function ChatLog({
176176
user_map,
177177
project_id,
178178
path,
179-
fontSize: fontSize ?? font_size,
179+
fontSize,
180180
selectedHashtags,
181181
actions,
182182
llm_cost_reply,

src/packages/frontend/chat/chatroom.tsx

Lines changed: 19 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
useRef,
1616
useState,
1717
} from "@cocalc/frontend/app-framework";
18-
import { Icon, Loading, Tip, VisibleMDLG } from "@cocalc/frontend/components";
18+
import { Icon, Loading, Tip } from "@cocalc/frontend/components";
1919
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
2020
import { FrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
2121
import { hoursToTimeIntervalHuman } from "@cocalc/util/misc";
@@ -69,9 +69,16 @@ interface Props {
6969
project_id: string;
7070
path: string;
7171
is_visible?: boolean;
72+
font_size: number;
7273
}
7374

74-
export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
75+
export function ChatRoom({
76+
actions,
77+
project_id,
78+
path,
79+
is_visible,
80+
font_size,
81+
}: Props) {
7582
const useEditor = useEditorRedux<ChatState>({ project_id, path });
7683
const is_uploading = useEditor("is_uploading");
7784
const is_preview = useEditor("is_preview");
@@ -163,68 +170,22 @@ export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
163170
placement="left"
164171
>
165172
<Icon name="arrow-down" />{" "}
166-
<VisibleMDLG>
167-
{" "}
168-
<FormattedMessage
169-
id="chatroom.scroll_bottom.label"
170-
defaultMessage={"Newest"}
171-
/>
172-
</VisibleMDLG>
173-
</Tip>
174-
</Button>
175-
);
176-
}
177-
178-
function render_increase_font_size(): JSX.Element {
179-
return (
180-
<Button onClick={() => actions.change_font_size(1)}>
181-
<Tip
182-
title="Increase font size"
183-
tip={<span>Make the font size larger for chat messages</span>}
184-
placement="left"
185-
>
186-
<Icon name="search-plus" />
187-
</Tip>
188-
</Button>
189-
);
190-
}
191-
192-
function render_decrease_font_size(): JSX.Element {
193-
return (
194-
<Button onClick={() => actions.change_font_size(-1)}>
195-
<Tip
196-
title="Decrease font size"
197-
tip={<span>Make the font size smaller for chat messages</span>}
198-
placement="left"
199-
>
200-
<Icon name="search-minus" />
173+
<FormattedMessage
174+
id="chatroom.scroll_bottom.label"
175+
defaultMessage={"Newest"}
176+
/>
201177
</Tip>
202178
</Button>
203179
);
204180
}
205181

206-
function render_export_button(): JSX.Element {
207-
return (
208-
<VisibleMDLG>
209-
<Button
210-
title={"Export to Markdown"}
211-
onClick={() => actions.export_to_markdown()}
212-
style={{ marginLeft: "5px" }}
213-
>
214-
<Icon name="external-link" />
215-
</Button>
216-
</VisibleMDLG>
217-
);
218-
}
219-
220182
function render_video_chat_button() {
221183
if (project_id == null || path == null) return;
222184
return (
223185
<VideoChatButton
224186
project_id={project_id}
225187
path={path}
226188
sendChat={(value) => actions.send_chat({ input: value })}
227-
label={"Video"}
228189
/>
229190
);
230191
}
@@ -324,36 +285,6 @@ export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
324285
}
325286
return (
326287
<Space style={{ width: "100%", marginTop: "3px" }} wrap>
327-
<ButtonGroup style={{ marginLeft: "5px" }}>
328-
{render_video_chat_button()}
329-
{render_bottom_button()}
330-
</ButtonGroup>
331-
<ButtonGroup style={{ marginLeft: "5px" }}>
332-
{render_decrease_font_size()}
333-
{render_increase_font_size()}
334-
</ButtonGroup>
335-
{render_export_button()}
336-
{actions.syncdb != null && (
337-
<VisibleMDLG>
338-
<ButtonGroup style={{ marginLeft: "5px" }}>
339-
<Button onClick={() => actions.syncdb?.undo()} title="Undo">
340-
<Icon name="undo" />
341-
</Button>
342-
<Button onClick={() => actions.syncdb?.redo()} title="Redo">
343-
<Icon name="redo" />
344-
</Button>
345-
</ButtonGroup>
346-
</VisibleMDLG>
347-
)}
348-
{actions.help != null && (
349-
<Button
350-
onClick={() => actions.help()}
351-
style={{ marginLeft: "5px" }}
352-
title="Documentation"
353-
>
354-
<Icon name="question-circle" />
355-
</Button>
356-
)}
357288
<Filter
358289
actions={actions}
359290
search={search}
@@ -366,6 +297,10 @@ export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
366297
}}
367298
/>
368299
{renderFilterRecent()}
300+
<ButtonGroup style={{ marginLeft: "5px" }}>
301+
{render_video_chat_button()}
302+
{render_bottom_button()}
303+
</ButtonGroup>
369304
</Space>
370305
);
371306
}
@@ -390,6 +325,7 @@ export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
390325
path={path}
391326
scrollToBottomRef={scrollToBottomRef}
392327
mode={"standalone"}
328+
fontSize={font_size}
393329
/>
394330
{render_preview_message()}
395331
</div>
@@ -401,6 +337,7 @@ export function ChatRoom({ actions, project_id, path, is_visible }: Props) {
401337
}}
402338
>
403339
<ChatInput
340+
fontSize={font_size}
404341
autoFocus
405342
cacheId={`${path}${project_id}-new`}
406343
input={input}

src/packages/frontend/chat/input.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import { CSSProperties, useEffect, useMemo, useRef, useState } from "react";
77
import { useIntl } from "react-intl";
88
import { useDebouncedCallback } from "use-debounce";
9-
109
import {
1110
CSS,
1211
redux,
1312
useIsMountedRef,
14-
useRedux,
1513
} from "@cocalc/frontend/app-framework";
1614
import MarkdownInput from "@cocalc/frontend/editors/markdown-input/multimode";
1715
import { IS_MOBILE } from "@cocalc/frontend/feature";
@@ -33,7 +31,7 @@ interface Props {
3331
on_paste?: (e) => void;
3432
height?: string;
3533
submitMentionsRef?: SubmitMentionsRef;
36-
font_size?: number;
34+
fontSize?: number;
3735
hideHelp?: boolean;
3836
style?: CSSProperties;
3937
cacheId?: string;
@@ -49,7 +47,7 @@ export default function ChatInput({
4947
cacheId,
5048
date,
5149
editBarStyle,
52-
font_size,
50+
fontSize,
5351
height,
5452
hideHelp,
5553
input: propsInput,
@@ -67,11 +65,7 @@ export default function ChatInput({
6765
useEffect(() => {
6866
onSendRef.current = on_send;
6967
}, [on_send]);
70-
const { project_id, path, actions } = useFrameContext();
71-
const fontSize = useRedux(["font_size"], project_id, path);
72-
if (font_size == null) {
73-
font_size = fontSize;
74-
}
68+
const { project_id, actions } = useFrameContext();
7569
const sender_id = useMemo(
7670
() => redux.getStore("account").get_account_id(),
7771
[],
@@ -248,7 +242,7 @@ export default function ChatInput({
248242
? "Click the date to edit chats."
249243
: "Double click to edit chats."
250244
}
251-
fontSize={font_size}
245+
fontSize={fontSize}
252246
hideHelp={hideHelp}
253247
style={style}
254248
onUndo={() => {

src/packages/frontend/chat/message.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export default function Message(props: Readonly<Props>) {
138138
messages,
139139
mode,
140140
project_id,
141+
font_size,
141142
} = props;
142143

143144
const showAISummarize = redux
@@ -654,6 +655,7 @@ export default function Message(props: Readonly<Props>) {
654655
return (
655656
<div>
656657
<ChatInput
658+
fontSize={font_size}
657659
autoFocus={autoFocusEdit}
658660
cacheId={`${props.path}${props.project_id}${date}`}
659661
input={newest_content(message)}
@@ -708,6 +710,7 @@ export default function Message(props: Readonly<Props>) {
708710
return (
709711
<div style={{ marginLeft: mode === "standalone" ? "30px" : "0" }}>
710712
<ChatInput
713+
fontSize={font_size}
711714
autoFocus={autoFocusReply}
712715
style={{
713716
borderRadius: "8px",

src/packages/frontend/chat/register.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function initChat(project_id: string, path: string): string {
5959
export function remove(path: string, redux, project_id: string): string {
6060
const name = redux_name(project_id, path);
6161
const actions = redux.getActions(name);
62-
actions?.close();
62+
actions?.syncdb.close();
6363
const store = redux.getStore(name);
6464
if (store == null) {
6565
return name;
@@ -71,4 +71,3 @@ export function remove(path: string, redux, project_id: string): string {
7171
redux.removeActions(name);
7272
return name;
7373
}
74-

src/packages/frontend/chat/side-chat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export default function SideChat({ project_id, path, style, fontSize }: Props) {
210210
) : undefined}
211211
<ChatInput
212212
autoFocus
213+
fontSize={fontSize}
213214
cacheId={`${path}${project_id}-new`}
214215
input={input}
215216
on_send={() => {

src/packages/frontend/chat/store.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
*/
55

66
import { List, fromJS, Map as immutableMap } from "immutable";
7-
8-
import { Store, redux } from "@cocalc/frontend/app-framework";
7+
import { Store } from "@cocalc/frontend/app-framework";
98
import type { HashtagState } from "@cocalc/frontend/editors/task-editor/types";
10-
import { ChatMessages, MentionList } from "./types";
9+
import type { ChatMessages, MentionList } from "./types";
1110

1211
export interface ChatState {
1312
project_id?: string;
@@ -30,7 +29,6 @@ export interface ChatState {
3029
has_unsaved_changes: boolean;
3130
unsent_user_mentions: MentionList;
3231
is_uploading: boolean;
33-
font_size: number;
3432
// whenever this changes and is defined, do a scroll.
3533
// scrollToBottom = 0 -- scroll to the bottom
3634
// scrollToBottom = ms since epoch -- scroll to the bottom of that thread
@@ -60,7 +58,6 @@ export function getInitialState() {
6058
has_unsaved_changes: false,
6159
unsent_user_mentions: List() as any,
6260
is_uploading: false,
63-
font_size: redux.getStore("account").get("font_size"),
6461
filterRecentH: 0,
6562
};
6663
}

src/packages/frontend/chat/video/launch-button.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ export default function VideoChatButton({
131131
<Popconfirm
132132
onOpenChange={setOpen}
133133
title={`${
134-
num_users_chatting ? "Join the current" : "Start a new"
135-
} video chat session about this document?`}
134+
num_users_chatting ? "Join the current" : "Launch "
135+
} video chat?`}
136136
onConfirm={click_video_button}
137-
okText={`${num_users_chatting ? "Join" : "Start"} video chat`}
137+
okText={`${num_users_chatting ? "Join" : "Launch"} video chat`}
138138
cancelText={<CancelText />}
139139
>
140140
{open ? (

src/packages/frontend/editors/slate/editable-markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const EditableMarkdown: React.FC<Props> = React.memo((props: Props) => {
164164
const isMountedRef = useIsMountedRef();
165165
const id = id0 ?? "";
166166
const actions = actions0 ?? {};
167-
const font_size = font_size0 ?? desc.get("font_size") ?? 14; // so possible to use without specifying this. TODO: should be from account settings
167+
const font_size = font_size0 ?? desc?.get("font_size") ?? 14; // so possible to use without specifying this. TODO: should be from account settings
168168
const [change, setChange] = useState<number>(0);
169169

170170
const editor = useMemo(() => {

0 commit comments

Comments
 (0)