Skip to content

Commit 055e30b

Browse files
committed
chatroom: move "scroll to bottom" to a menu item
1 parent cb8445c commit 055e30b

File tree

10 files changed

+66
-85
lines changed

10 files changed

+66
-85
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { Button, Tooltip } from "antd";
1414
import { debounce } from "lodash";
1515
import { useMemo } from "react";
1616
import { FormattedMessage, useIntl } from "react-intl";
17-
1817
import { UsersViewing } from "@cocalc/frontend/account/avatar/users-viewing";
1918
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
2019
import { HiddenXS } from "@cocalc/frontend/components";

src/packages/frontend/chat/chatroom.tsx

Lines changed: 6 additions & 41 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 } from "@cocalc/frontend/components";
18+
import { Icon, Loading } 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";
@@ -34,7 +34,7 @@ const FILTER_RECENT_NONE = {
3434
value: 0,
3535
label: (
3636
<>
37-
<Icon name="clock" /> All
37+
<Icon name="clock" />
3838
</>
3939
),
4040
} as const;
@@ -114,10 +114,6 @@ export function ChatRoom({
114114
on_send();
115115
}
116116

117-
function button_scroll_to_bottom(): void {
118-
scrollToBottomRef.current?.(true);
119-
}
120-
121117
function render_preview_message(): JSX.Element | undefined {
122118
if (!is_preview) return;
123119
if (input.length === 0 || preview.length === 0) return;
@@ -152,45 +148,16 @@ export function ChatRoom({
152148
);
153149
}
154150

155-
function render_bottom_button(): JSX.Element {
156-
return (
157-
<Button onClick={button_scroll_to_bottom}>
158-
<Tip
159-
title={
160-
<FormattedMessage
161-
id="chatroom.scroll_bottom.tooltip.title"
162-
defaultMessage={"Newest Messages"}
163-
/>
164-
}
165-
tip={
166-
<span>
167-
<FormattedMessage
168-
id="chatroom.scroll_bottom.tooltip.tip"
169-
defaultMessage={
170-
"Scrolls the chat to the bottom showing the newest messages"
171-
}
172-
/>
173-
</span>
174-
}
175-
placement="left"
176-
>
177-
<Icon name="arrow-down" />{" "}
178-
<FormattedMessage
179-
id="chatroom.scroll_bottom.label"
180-
defaultMessage={"Newest"}
181-
/>
182-
</Tip>
183-
</Button>
184-
);
185-
}
186-
187151
function render_video_chat_button() {
188152
if (project_id == null || path == null) return;
189153
return (
190154
<VideoChatButton
191155
project_id={project_id}
192156
path={path}
193-
sendChat={(value) => actions.sendChat({ input: value })}
157+
sendChat={(value) => {
158+
actions.sendChat({ input: value });
159+
actions.scrollToBottom();
160+
}}
194161
/>
195162
);
196163
}
@@ -213,7 +180,6 @@ export function ChatRoom({
213180
actions.setFilterRecentH(0);
214181
setFilterRecentHCustom("");
215182
}}
216-
style={{ width: 120 }}
217183
popupMatchSelectWidth={false}
218184
onSelect={(val: number) => actions.setFilterRecentH(val)}
219185
options={[
@@ -302,7 +268,6 @@ export function ChatRoom({
302268
{renderFilterRecent()}
303269
<ButtonGroup style={{ marginLeft: "5px" }}>
304270
{render_video_chat_button()}
305-
{render_bottom_button()}
306271
</ButtonGroup>
307272
</Space>
308273
);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default function SideChat({
137137
path,
138138
) as ChatActions;
139139
actions.sendChat({ input: value });
140+
actions.scrollToBottom();
140141
}}
141142
/>
142143
<Tooltip title="Show TimeTravel change history of this side chat.">

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,9 @@ export default function VideoChatButton({
125125
</>
126126
);
127127

128-
const btn = <Button style={{ ...style, ...style0 }}>{body}</Button>;
129-
130128
return (
131-
<Popconfirm
132-
onOpenChange={setOpen}
133-
title={`${
134-
num_users_chatting ? "Join the current" : "Launch "
135-
} video chat?`}
136-
onConfirm={click_video_button}
137-
okText={`${num_users_chatting ? "Join" : "Launch"} video chat`}
138-
cancelText={<CancelText />}
139-
>
140-
{open ? (
141-
btn
142-
) : (
143-
<Popover
144-
mouseEnterDelay={0.8}
145-
title={() => (
146-
<span>
147-
{render_join(num_users_chatting)}
148-
{render_num_chatting(num_users_chatting)}
149-
</span>
150-
)}
151-
>
152-
{btn}
153-
</Popover>
154-
)}
155-
</Popconfirm>
129+
<Button onClick={click_video_button} style={{ ...style, ...style0 }}>
130+
{body}
131+
</Button>
156132
);
157133
}

src/packages/frontend/frame-editors/chat-editor/actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,12 @@ export class Actions extends CodeEditorActions<ChatEditorState> {
129129
this.set_error(`${error}`);
130130
}
131131
}
132+
133+
scrollToBottom = (frameId) => {
134+
this.getChatActions(frameId)?.scrollToBottom();
135+
};
136+
137+
scrollToTop = (frameId) => {
138+
this.getChatActions(frameId)?.scrollToBottom(0);
139+
};
132140
}

src/packages/frontend/frame-editors/chat-editor/editor.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,28 @@ const chatroom: EditorDescription = {
3737
"help",
3838
"export_to_markdown",
3939
"chatgpt",
40+
"scrollToBottom",
41+
"scrollToTop",
42+
]),
43+
customizeCommands: {
44+
scrollToTop: {
45+
label: "Scroll to Old",
46+
button: "Oldest",
47+
title: "Scroll to oldest message in chat",
48+
},
49+
scrollToBottom: {
50+
label: "Scroll to Newest",
51+
button: "Newest",
52+
title: "Scroll to newest message in chat",
53+
},
54+
},
55+
buttons: set([
56+
"undo",
57+
"redo",
58+
"decrease_font_size",
59+
"increase_font_size",
60+
"scrollToBottom",
4061
]),
41-
buttons: set(["undo", "redo", "decrease_font_size", "increase_font_size"]),
4262
} as const;
4363

4464
const EDITOR_SPEC = {

src/packages/frontend/frame-editors/frame-tree/commands/generic-commands.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ addCommands({
5454
group: "frame-control",
5555
alwaysShow: true,
5656
pos: 2,
57-
title: labels.split_frame_vertically_title,
57+
title: defineMessage({
58+
id: "command.generic.split_col.title",
59+
defaultMessage: "Split frame vertically into two columns",
60+
}),
5861
onClick: ({ props }) => {
5962
if (props.is_full) {
6063
return props.actions.unset_frame_full();
@@ -63,11 +66,7 @@ addCommands({
6366
}
6467
},
6568
icon: "vertical-split",
66-
label: defineMessage({
67-
id: "command.generic.split_col.label",
68-
defaultMessage: "Split Right",
69-
description: "Split a frame vertically",
70-
}),
69+
label: labels.split_frame_vertically_title,
7170
button: menu.split,
7271
},
7372
maximize: {
@@ -305,6 +304,18 @@ addCommands({
305304
};
306305
}),
307306
},
307+
scrollToTop: {
308+
group: "scroll",
309+
pos: 0,
310+
icon: "arrow-up",
311+
label: "Scroll to top",
312+
},
313+
scrollToBottom: {
314+
group: "scroll",
315+
pos: 1,
316+
icon: "arrow-down",
317+
label: "Scroll to bottom",
318+
},
308319
undo: {
309320
disabled: ({ readOnly }) => readOnly,
310321
stayOpenOnClick: true,

src/packages/frontend/frame-editors/frame-tree/commands/generic-menus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ addMenus({
3838
view: {
3939
label: menu.view,
4040
pos: 2,
41-
groups: ["zoom", "frame-control", "show-frames", "button-bar"],
41+
groups: ["zoom", "scroll", "frame-control", "show-frames", "button-bar"],
4242
},
4343
go: {
4444
label: menu.go,

src/packages/frontend/frame-editors/frame-tree/commands/manage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export class ManageCommands {
313313
);
314314
};
315315

316-
private cmd2display = (
316+
private commandToDisplay = (
317317
cmd: Partial<Command>,
318318
aspect: "label" | "title" | "button",
319319
): string | null | undefined | ReactNode => {
@@ -348,9 +348,9 @@ export class ManageCommands {
348348
tip: boolean,
349349
) => {
350350
const width = ICON_WIDTH;
351-
let lbl = this.cmd2display(cmd, "label");
351+
let lbl = this.commandToDisplay(cmd, "label");
352352
if (tip && cmd.title) {
353-
const title = this.cmd2display(cmd, "title");
353+
const title = this.commandToDisplay(cmd, "title");
354354
lbl = (
355355
<Tooltip mouseEnterDelay={0.9} title={title} placement={"left"}>
356356
{lbl}
@@ -473,9 +473,9 @@ export class ManageCommands {
473473
const icon = this.getCommandIcon(cmd);
474474
let buttonLabel;
475475
if (cmd.button != null) {
476-
buttonLabel = this.cmd2display(cmd, "button");
476+
buttonLabel = this.commandToDisplay(cmd, "button");
477477
} else {
478-
buttonLabel = this.cmd2display(cmd, "label");
478+
buttonLabel = this.commandToDisplay(cmd, "label");
479479
}
480480
label = (
481481
<>
@@ -516,7 +516,7 @@ export class ManageCommands {
516516
<>
517517
{this.getCommandLabel(cmd, name, false)}
518518
{cmd.title ? (
519-
<div>{this.cmd2display(cmd, "title")}</div>
519+
<div>{this.commandToDisplay(cmd, "title")}</div>
520520
) : undefined}
521521
</>
522522
);

src/packages/frontend/i18n/common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ export const labels = defineMessages({
200200
},
201201
split_frame_vertically_title: {
202202
id: "labels.split_frame_vertically.title",
203-
defaultMessage: "Split frame vertically into two columns",
203+
defaultMessage: "Split Vertically",
204+
description: "Split frame vertically into two columns",
204205
},
205206
split_frame_horizontally_title: {
206207
id: "labels.split_frame_horizontally.title",
207-
defaultMessage: "Split frame horizontally into two rows",
208+
defaultMessage: "Split Horizontally",
208209
description: "Split frame horizontally",
209210
},
210211
assistant: {

0 commit comments

Comments
 (0)