Skip to content

Commit de0580b

Browse files
authored
Merge pull request #18 from devchat-ai/feat/topic
Refactor Topic component to improve readability and maintainability
2 parents e8fa0c1 + 556c589 commit de0580b

File tree

1 file changed

+67
-57
lines changed

1 file changed

+67
-57
lines changed

src/views/components/InputMessage/Topic.tsx

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -105,76 +105,72 @@ export default function Topic({ styleName }) {
105105
},
106106
}}
107107
>
108-
{topicList.map((item: any, index) => (
109-
<Box>
110-
<Flex sx={{ width: "100%" }} gap="sm">
111-
<Box
112-
sx={{
113-
cursor: "pointer",
114-
flex: 1,
115-
overflow: "hidden",
116-
}}
117-
onClick={() => showTopic(item?.root_prompt)}
118-
>
119-
<Flex justify="space-between" gap="sm">
108+
<Box>
109+
{topicList.map((item: any, index) => (
110+
<Box>
111+
<Flex sx={{ width: "100%" }} gap="sm">
112+
<Box
113+
sx={{
114+
cursor: "pointer",
115+
flex: 1,
116+
overflow: "hidden",
117+
}}
118+
onClick={() => showTopic(item?.root_prompt)}
119+
>
120+
<Flex justify="space-between" gap="sm">
121+
<Text
122+
fz="sm"
123+
fw={700}
124+
sx={{
125+
whiteSpace: "nowrap",
126+
overflow: "hidden",
127+
textOverflow: "ellipsis",
128+
flex: 1,
129+
}}
130+
>
131+
{item?.root_prompt.title}
132+
</Text>
133+
<Text
134+
fz="sm"
135+
c="dimmed"
136+
sx={{
137+
whiteSpace: "nowrap",
138+
overflow: "hidden",
139+
textOverflow: "ellipsis",
140+
}}
141+
>
142+
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
143+
</Text>
144+
</Flex>
145+
120146
<Text
147+
c="dimmed"
121148
fz="sm"
122-
fw={700}
123149
sx={{
124150
whiteSpace: "nowrap",
125151
overflow: "hidden",
126152
textOverflow: "ellipsis",
127-
flex: 1,
128153
}}
129154
>
130-
{item?.root_prompt.title}
155+
{item?.root_prompt.responses?.[0]}
131156
</Text>
132-
<Text
133-
fz="sm"
134-
c="dimmed"
135-
sx={{
136-
whiteSpace: "nowrap",
137-
overflow: "hidden",
138-
textOverflow: "ellipsis",
157+
</Box>
158+
<Flex align="center">
159+
<ActionIcon
160+
onClick={() => {
161+
deleteTopic(item?.root_prompt.hash);
139162
}}
140163
>
141-
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
142-
</Text>
164+
<IconTrash size="1rem" />
165+
</ActionIcon>
143166
</Flex>
144-
145-
<Text
146-
c="dimmed"
147-
fz="sm"
148-
sx={{
149-
whiteSpace: "nowrap",
150-
overflow: "hidden",
151-
textOverflow: "ellipsis",
152-
}}
153-
>
154-
{item?.root_prompt.responses?.[0]}
155-
</Text>
156-
</Box>
157-
<Flex align="center">
158-
<ActionIcon
159-
onClick={() => {
160-
deleteTopic(item?.root_prompt.hash);
161-
}}
162-
>
163-
<IconTrash size="1rem" />
164-
</ActionIcon>
165167
</Flex>
166-
</Flex>
167-
{index !== topicList.length - 1 && (
168-
<Divider variant="solid" my={6} opacity="0.5" />
169-
)}
170-
</Box>
171-
))}
172-
<LoadingOverlay
173-
visible={loading}
174-
overlayBlur={3}
175-
overlayOpacity={0}
176-
keepMounted={true}
177-
/>
168+
{index !== topicList.length - 1 && (
169+
<Divider variant="solid" my={6} opacity="0.5" />
170+
)}
171+
</Box>
172+
))}
173+
</Box>
178174
</Drawer>
179175
<ActionIcon
180176
className={styleName}
@@ -184,6 +180,20 @@ export default function Topic({ styleName }) {
184180
>
185181
<IconClock size="1rem" />
186182
</ActionIcon>
183+
<LoadingOverlay
184+
style={{
185+
height: "380px",
186+
inset: "auto",
187+
bottom: "0",
188+
left: "0",
189+
right: "0",
190+
position: "fixed",
191+
}}
192+
visible={loading}
193+
overlayBlur={3}
194+
overlayOpacity={0}
195+
keepMounted={true}
196+
/>
187197
</>
188198
);
189199
}

0 commit comments

Comments
 (0)