Skip to content

Commit 15cfcf5

Browse files
committed
frontend/chat: fold thread in bottom thread row, some cleanups
1 parent 5e5608c commit 15cfcf5

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

src/packages/frontend/chat/filter-messages.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ NOTE: chat uses every imaginable way to store a timestamp at once,
66
which is the may source of weirdness in the code below... Beware.
77
*/
88

9-
import type { ChatMessages, ChatMessageTyped, MessageHistory } from "./types";
10-
import { search_match, search_split } from "@cocalc/util/misc";
119
import { List } from "immutable";
10+
import LRU from "lru-cache";
11+
1212
import type { TypedMap } from "@cocalc/frontend/app-framework";
1313
import { redux } from "@cocalc/frontend/app-framework";
1414
import { webapp_client } from "@cocalc/frontend/webapp-client";
15-
import LRU from "lru-cache";
15+
import { search_match, search_split } from "@cocalc/util/misc";
16+
import type { ChatMessages, ChatMessageTyped, MessageHistory } from "./types";
1617

1718
export function filterMessages({
1819
messages,

src/packages/frontend/chat/message.tsx

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { Name } from "./name";
4141
import { Time } from "./time";
4242
import { ChatMessageTyped, Mode, SubmitMentionsFn } from "./types";
4343
import {
44+
getReplyToRoot,
4445
getThreadRootDate,
4546
is_editing,
4647
message_colors,
@@ -384,19 +385,15 @@ export default function Message({
384385
}
385386

386387
function contentColumn() {
387-
let marginTop;
388-
let value = newest_content(message);
388+
const value = newest_content(message);
389389

390390
const { background, color, lighten, message_class } = message_colors(
391391
account_id,
392392
message,
393393
);
394394

395-
if (!is_prev_sender && is_viewers_message) {
396-
marginTop = MARGIN_TOP_VIEWER;
397-
} else {
398-
marginTop = "5px";
399-
}
395+
const marginTop =
396+
!is_prev_sender && is_viewers_message ? MARGIN_TOP_VIEWER : "5px";
400397

401398
const messageStyle: CSSProperties = {
402399
color,
@@ -911,6 +908,21 @@ export default function Message({
911908
{showAISummarize && is_thread ? (
912909
<SummarizeThread message={message} actions={actions} />
913910
) : undefined}
911+
{is_thread ? (
912+
<Button
913+
type="text"
914+
style={{ color: COLORS.GRAY_M }}
915+
icon={<Icon name="to-top-outlined" />}
916+
onClick={() =>
917+
actions?.toggleFoldThread(
918+
new Date(getThreadRootDate({ date, messages })),
919+
index,
920+
)
921+
}
922+
>
923+
Fold Thread…
924+
</Button>
925+
) : undefined}
914926
</div>
915927
);
916928
}
@@ -920,16 +932,13 @@ export default function Message({
920932
return;
921933
}
922934

923-
let label;
924-
if (numChildren) {
925-
label = (
926-
<>
927-
{numChildren} {plural(numChildren, "Reply", "Replies")}
928-
</>
929-
);
930-
} else {
931-
label = "View Replies";
932-
}
935+
const label = numChildren ? (
936+
<>
937+
Show {numChildren} {plural(numChildren, "Reply", "Replies")}
938+
</>
939+
) : (
940+
"View Replies…"
941+
);
933942

934943
return (
935944
<Col xs={24}>
@@ -940,6 +949,7 @@ export default function Message({
940949
}
941950
type="link"
942951
style={{ color: "darkblue" }}
952+
icon={<Icon name="to-top-outlined" rotate="180" />}
943953
>
944954
{label}
945955
</Button>
@@ -956,24 +966,26 @@ export default function Message({
956966
const style: CSS =
957967
mode === "standalone"
958968
? {
959-
color: "#666",
969+
color: COLORS.GRAY_M,
960970
marginTop: MARGIN_TOP_VIEWER,
961971
marginLeft: "5px",
962972
marginRight: "5px",
963973
}
964974
: {
965-
color: "#666",
975+
color: COLORS.GRAY_M,
966976
marginTop: "5px",
967977
width: "100%",
968978
textAlign: "center",
969979
};
980+
970981
const iconName = is_folded
971982
? mode === "standalone"
972983
? reverseRowOrdering
973984
? "right-circle-o"
974985
: "left-circle-o"
975986
: "right-circle-o"
976987
: "down-circle-o";
988+
977989
const button = (
978990
<Button
979991
type="text"

src/packages/frontend/chat/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function compute_cursor_offset_position(
4242
mentions: MentionList,
4343
) {
4444
let index_offset = 0;
45-
let usuable_cursor_index = cursor_plain_text_index;
45+
let usable_cursor_index = cursor_plain_text_index;
4646
const mention_array = mentions.toJS() as any;
4747

4848
for (let i = 0; i < mention_array.length; i++) {
@@ -60,19 +60,19 @@ export function compute_cursor_offset_position(
6060
index_offset = mention_offset + id.length + SINGLE_MENTION_OFFSET;
6161
}
6262
} else if (cursor_plain_text_index > plainTextIndex + display.length / 2) {
63-
usuable_cursor_index = plainTextIndex + display.length;
63+
usable_cursor_index = plainTextIndex + display.length;
6464
if (i == mention_array.length - 1) {
6565
// Cursor is inside the second half of the last mention.
6666
index_offset = mention_offset + id.length + SINGLE_MENTION_OFFSET;
6767
}
6868
} else if (cursor_plain_text_index <= plainTextIndex + display.length / 2) {
6969
// Cursor is inside the first half of this mention
70-
usuable_cursor_index = plainTextIndex;
70+
usable_cursor_index = plainTextIndex;
7171
index_offset = mention_offset;
7272
break;
7373
}
7474
}
75-
return index_offset + usuable_cursor_index;
75+
return index_offset + usable_cursor_index;
7676
}
7777

7878
export function newest_content(message: ChatMessageTyped): string {

src/packages/frontend/components/icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ import {
200200
TagsFilled,
201201
TagsOutlined,
202202
TagsTwoTone,
203+
ToTopOutlined,
203204
TeamOutlined,
204205
ThunderboltOutlined,
205206
ToolOutlined,
@@ -631,6 +632,7 @@ const IconSpec = {
631632
"down-square-outlined": DownSquareOutlined,
632633
"merge-cells-outlined": MergeCellsOutlined,
633634
"fork-outlined": ForkOutlined,
635+
"to-top-outlined": ToTopOutlined,
634636
} as const;
635637

636638
// Icon Fonts coming from https://www.iconfont.cn/?lang=en-us

src/packages/frontend/cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"mathjax",
1616
"matplotlib",
1717
"Miniterm",
18-
"Miniterm",
1918
"nbconvert",
2019
"nbgrader",
2120
"nbviewer",
@@ -45,6 +44,7 @@
4544
],
4645
"ignoreWords": [
4746
"antd",
47+
"collab",
4848
"immutablejs",
4949
"ipynb",
5050
"isdir",

src/packages/frontend/editors/slate/mostly-static-markdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Mostly static markdown, but with some minimal dynamic editable content, e.g., checkboxes,
33
and maybe some other nice features, but much less than a full slate editor!
44
5-
This is used a lot in the fronend app, whereas the fully static one is used a lot in the next.js app.
5+
This is used a lot in the frontend app, whereas the fully static one is used a lot in the next.js app.
66
77
Extras include:
88
@@ -59,7 +59,7 @@ interface Props {
5959
onChange?: (string) => void; // if given support some very minimal amount of editing, e.g., checkboxes; onChange is called with modified markdown.
6060
selectedHashtags?: Set<string>; // assumed lower case!
6161
toggleHashtag?: (string) => void;
62-
searchWords?: Set<string> | string[]; // higlight text that matches anything in here
62+
searchWords?: Set<string> | string[]; // highlight text that matches anything in here
6363
}
6464

6565
export default function MostlyStaticMarkdown({

0 commit comments

Comments
 (0)