Skip to content

Commit 928cec9

Browse files
committed
chat: use antd Input.Search component for consistency; also when search state gets cleared when sending message, update what is displayed in search; finally also clear hashtag state
1 parent cc0a9ad commit 928cec9

File tree

4 files changed

+66
-39
lines changed

4 files changed

+66
-39
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ export class ChatActions extends Actions<ChatState> {
294294
this.setState({
295295
input: "",
296296
search: "",
297+
selectedHashtags: immutableMap(),
297298
});
298299
} else {
299300
// TODO: but until we improve search to be by thread (instead of by message), do this:
300301
this.setState({
301302
search: "",
303+
selectedHashtags: immutableMap(),
302304
});
303305
}
304306

src/packages/frontend/chat/chatroom.tsx

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ import {
2222
useRef,
2323
useState,
2424
} from "@cocalc/frontend/app-framework";
25-
import {
26-
Icon,
27-
Loading,
28-
SearchInput,
29-
Tip,
30-
VisibleMDLG,
31-
} from "@cocalc/frontend/components";
25+
import { Icon, Loading, Tip, VisibleMDLG } from "@cocalc/frontend/components";
3226
import { computeServersEnabled } from "@cocalc/frontend/compute/config";
3327
import SelectComputeServerForFile from "@cocalc/frontend/compute/select-server-for-file";
3428
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
@@ -43,6 +37,7 @@ import { LLMCostEstimationChat } from "./llm-cost-estimation";
4337
import { SubmitMentionsFn } from "./types";
4438
import { INPUT_HEIGHT, markChatAsReadIfUnseen } from "./utils";
4539
import VideoChatButton from "./video/launch-button";
40+
import Filter from "./filter";
4641

4742
const FILTER_RECENT_NONE = { value: 0, label: "All" } as const;
4843

@@ -304,30 +299,6 @@ export const ChatRoom: React.FC<Props> = ({ project_id, path, is_visible }) => {
304299
);
305300
}
306301

307-
function render_search() {
308-
return (
309-
<SearchInput
310-
autoFocus={false}
311-
placeholder={"Filter messages (use /re/ for regexp)..."}
312-
default_value={search}
313-
on_change={debounce(
314-
(value) => actions.setState({ search: value }),
315-
150,
316-
{ leading: false, trailing: true },
317-
)}
318-
status={!search ? undefined : "warning"}
319-
style={{
320-
margin: 0,
321-
width: "100%",
322-
marginBottom: "5px",
323-
...(messages.size >= 2
324-
? undefined
325-
: { visibility: "hidden", height: 0 }),
326-
}}
327-
/>
328-
);
329-
}
330-
331302
function isValidFilterRecentCustom(): boolean {
332303
const v = parseFloat(filterRecentHCustom);
333304
return isFinite(v) && v >= 0;
@@ -466,7 +437,18 @@ export const ChatRoom: React.FC<Props> = ({ project_id, path, is_visible }) => {
466437
}}
467438
>
468439
{renderFilterRecent()}
469-
{render_search()}
440+
<Filter
441+
actions={actions}
442+
search={search}
443+
style={{
444+
margin: 0,
445+
width: "100%",
446+
marginBottom: "5px",
447+
...(messages.size >= 2
448+
? undefined
449+
: { visibility: "hidden", height: 0 }),
450+
}}
451+
/>
470452
</Col>
471453
</Row>
472454
);

src/packages/frontend/chat/filter.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Input } from "antd";
2+
import { useCallback, useEffect, useMemo, useState } from "react";
3+
import { debounce } from "lodash";
4+
5+
export default function Filter({ actions, search, style }) {
6+
const [value, setValue] = useState<string>(search ?? "");
7+
useEffect(() => {
8+
setValue(search);
9+
}, [search]);
10+
const doSearch = useCallback(
11+
(value: string) => {
12+
actions.setState({ search: value });
13+
},
14+
[actions],
15+
);
16+
const debouncedSearch = useMemo(
17+
() =>
18+
debounce(doSearch, 200, {
19+
leading: false,
20+
trailing: true,
21+
}),
22+
[actions],
23+
);
24+
25+
return (
26+
<Input.Search
27+
style={style}
28+
allowClear
29+
placeholder={"Filter messages (use /re/ for regexp)..."}
30+
value={value}
31+
onChange={(e) => {
32+
setValue(e.target.value ?? "");
33+
debouncedSearch(e.target.value ?? "");
34+
}}
35+
onPressEnter={() => {
36+
debouncedSearch.cancel();
37+
doSearch(value);
38+
}}
39+
onSearch={() => {
40+
debouncedSearch.cancel();
41+
doSearch(value);
42+
}}
43+
/>
44+
);
45+
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Button, Flex, Space, Tooltip } from "antd";
2-
import { debounce } from "lodash";
32
import { CSSProperties, useCallback, useEffect, useRef, useState } from "react";
43
import {
54
redux,
@@ -8,7 +7,7 @@ import {
87
useTypedRedux,
98
} from "@cocalc/frontend/app-framework";
109
import { AddCollaborators } from "@cocalc/frontend/collaborators";
11-
import { A, Icon, Loading, SearchInput } from "@cocalc/frontend/components";
10+
import { A, Icon, Loading } from "@cocalc/frontend/components";
1211
import { IS_MOBILE } from "@cocalc/frontend/feature";
1312
import { ProjectUsers } from "@cocalc/frontend/projects/project-users";
1413
import { user_activity } from "@cocalc/frontend/tracker";
@@ -20,6 +19,7 @@ import { SubmitMentionsFn } from "./types";
2019
import { INPUT_HEIGHT, markChatAsReadIfUnseen } from "./utils";
2120
import VideoChatButton from "./video/launch-button";
2221
import { COLORS } from "@cocalc/util/theme";
22+
import Filter from "./filter";
2323

2424
interface Props {
2525
project_id: string;
@@ -141,11 +141,9 @@ export default function SideChat({ project_id, path, style }: Props) {
141141
<AddChatCollab addCollab={addCollab} project_id={project_id} />
142142
</div>
143143
)}
144-
<SearchInput
145-
autoFocus={false}
146-
placeholder={"Filter messages (use /re/ for regexp)..."}
147-
default_value={search}
148-
on_change={debounce((search) => actions.setState({ search }), 500)}
144+
<Filter
145+
actions={actions}
146+
search={search}
149147
style={{
150148
margin: 0,
151149
...(messages.size >= 2

0 commit comments

Comments
 (0)