Skip to content

Commit 369e5e6

Browse files
authored
Merge pull request #20 from devchat-ai/feat/topic
Refactor Topic component and add AddTopic component
2 parents 7f32fd5 + e9546e8 commit 369e5e6

3 files changed

Lines changed: 41 additions & 13 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
import { Button } from "@mantine/core";
3+
import { IconPlus } from "@tabler/icons-react";
4+
import messageUtil from "@/util/MessageUtil";
5+
6+
export default function Topic({ buttonStyles, disabled }) {
7+
const setNewTopic = () => {
8+
messageUtil.sendMessage({
9+
command: "setNewTopic",
10+
});
11+
};
12+
13+
return (
14+
<Button
15+
variant="default"
16+
size="xs"
17+
radius="xl"
18+
leftIcon={<IconPlus size="1rem" />}
19+
styles={buttonStyles}
20+
onClick={setNewTopic}
21+
disabled={disabled}
22+
>
23+
New Topic
24+
</Button>
25+
);
26+
}

src/views/components/InputMessage/Topic.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
import {
1212
IconClock,
1313
IconChevronDown,
14-
IconPlus,
1514
IconRefresh,
1615
IconTrash,
1716
} from "@tabler/icons-react";
1817
import { useDisclosure } from "@mantine/hooks";
1918
import messageUtil from "@/util/MessageUtil";
2019
import dayjs from "dayjs";
2120

22-
export default function Topic({ styleName }) {
21+
export default function Topic({ styleName, disabled }) {
2322
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
2423
useDisclosure(false);
2524
const [loading, setLoading] = useState(false);
@@ -55,13 +54,6 @@ export default function Topic({ styleName }) {
5554
});
5655
};
5756

58-
const setNewTopic = () => {
59-
messageUtil.sendMessage({
60-
command: "setNewTopic",
61-
});
62-
closeDrawer();
63-
};
64-
6557
const deleteTopic = (topicHash: string) => {
6658
const newTopicList = topicList.filter(
6759
(topic) => topic.root_prompt.hash !== topicHash
@@ -82,9 +74,6 @@ export default function Topic({ styleName }) {
8274
<Flex justify="space-between">
8375
<Text>Devchat Topic</Text>
8476
<Flex>
85-
<ActionIcon onClick={setNewTopic}>
86-
<IconPlus size="1rem" />
87-
</ActionIcon>
8877
<ActionIcon onClick={refreshTopicList}>
8978
<IconRefresh size="1rem" />
9079
</ActionIcon>
@@ -178,6 +167,7 @@ export default function Topic({ styleName }) {
178167
</Drawer>
179168
<ActionIcon
180169
className={styleName}
170+
disabled={disabled}
181171
radius="xl"
182172
variant="default"
183173
onClick={openDrawer}

src/views/components/InputMessage/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import messageUtil from "@/util/MessageUtil";
3232
import InputContexts from "./InputContexts";
3333
import Topic from "./Topic";
34+
import AddTopic from "./AddTopic";
3435
import { observer } from "mobx-react-lite";
3536
import { useMst } from "@/views/stores/RootStore";
3637
import { ChatContext } from "@/views/stores/InputStore";
@@ -481,7 +482,18 @@ const InputMessage = observer((props: any) => {
481482
</ScrollArea.Autosize>
482483
</Menu.Dropdown>
483484
</Menu>
484-
{showTopic && <Topic styleName={classes.actionIcon} />}
485+
{showTopic && (
486+
<>
487+
<Topic
488+
styleName={classes.actionIcon}
489+
disabled={generating || chat.disabled}
490+
/>
491+
<AddTopic
492+
buttonStyles={buttonStyles}
493+
disabled={generating || chat.disabled}
494+
/>
495+
</>
496+
)}
485497
</Group>
486498
{contexts && contexts.length > 0 && (
487499
<Drawer

0 commit comments

Comments
 (0)