Skip to content

Commit 4eb05d1

Browse files
authored
Merge pull request #16 from devchat-ai/feat/text
Refactor InputMessage component
2 parents 16f2905 + c5e5fde commit 4eb05d1

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

src/views/components/InputMessage/index.tsx

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ const InputMessage = observer((props: any) => {
137137
newIndex < commandMenusNode.length ? newIndex : 0
138138
);
139139
viewport.current
140-
?.querySelectorAll('[data-list-item]')
141-
?.[newIndex]?.scrollIntoView({ block: 'nearest' });
140+
?.querySelectorAll("[data-list-item]")
141+
?.[newIndex]?.scrollIntoView({ block: "nearest" });
142142
}
143143
if (event.key === "ArrowUp") {
144144
event.preventDefault();
@@ -147,8 +147,8 @@ const InputMessage = observer((props: any) => {
147147
newIndex < 0 ? commandMenusNode.length - 1 : newIndex
148148
);
149149
viewport.current
150-
?.querySelectorAll('[data-list-item]')
151-
?.[newIndex]?.scrollIntoView({ block: 'nearest' });
150+
?.querySelectorAll("[data-list-item]")
151+
?.[newIndex]?.scrollIntoView({ block: "nearest" });
152152
}
153153
if ((event.key === "Enter" || event.key === "Tab") && !event.shiftKey) {
154154
const commandNode = commandMenusNode[currentMenuIndex];
@@ -415,32 +415,36 @@ const InputMessage = observer((props: any) => {
415415
</ActionIcon>
416416
</Menu.Target>
417417
<Menu.Dropdown>
418-
{[...contextMenus]
419-
.sort((a, b) => {
420-
if (a.name === "<custom command>") {
421-
return 1; // Placing '<custom command>' at the end
422-
} else if (b.name === "<custom command>") {
423-
return -1; // Placing '<custom command>' at the front
424-
} else {
425-
return (a.name || "").localeCompare(b.name || ""); // Sorting alphabetically for other cases
426-
}
427-
})
428-
.map(({ pattern, description, name }, index) => {
429-
return (
430-
<Menu.Item
431-
key={`contexts-menus-${index}`}
432-
icon={contextMenuIcon(name)}
433-
onClick={() => {
434-
handleContextClick(name);
435-
}}
436-
>
437-
{name}
438-
<Text sx={{ fontSize: "9pt", color: theme.colors.gray[6] }}>
439-
{description}
440-
</Text>
441-
</Menu.Item>
442-
);
443-
})}
418+
<ScrollArea.Autosize placeholder="" type="always" mah={240}>
419+
{[...contextMenus]
420+
.sort((a, b) => {
421+
if (a.name === "<custom command>") {
422+
return 1; // Placing '<custom command>' at the end
423+
} else if (b.name === "<custom command>") {
424+
return -1; // Placing '<custom command>' at the front
425+
} else {
426+
return (a.name || "").localeCompare(b.name || ""); // Sorting alphabetically for other cases
427+
}
428+
})
429+
.map(({ pattern, description, name }, index) => {
430+
return (
431+
<Menu.Item
432+
key={`contexts-menus-${index}`}
433+
icon={contextMenuIcon(name)}
434+
onClick={() => {
435+
handleContextClick(name);
436+
}}
437+
>
438+
{name}
439+
<Text
440+
sx={{ fontSize: "9pt", color: theme.colors.gray[6] }}
441+
>
442+
{description}
443+
</Text>
444+
</Menu.Item>
445+
);
446+
})}
447+
</ScrollArea.Autosize>
444448
</Menu.Dropdown>
445449
</Menu>
446450
<Menu
@@ -463,16 +467,18 @@ const InputMessage = observer((props: any) => {
463467
</Button>
464468
</Menu.Target>
465469
<Menu.Dropdown>
466-
{modelMenus.map((modelName) => {
467-
return (
468-
<Menu.Item
469-
key={modelName}
470-
onClick={() => changeModel(modelName)}
471-
>
472-
{getModelShowName(modelName)}
473-
</Menu.Item>
474-
);
475-
})}
470+
<ScrollArea.Autosize placeholder="" type="always" mah={240}>
471+
{modelMenus.map((modelName) => {
472+
return (
473+
<Menu.Item
474+
key={modelName}
475+
onClick={() => changeModel(modelName)}
476+
>
477+
{getModelShowName(modelName)}
478+
</Menu.Item>
479+
);
480+
})}
481+
</ScrollArea.Autosize>
476482
</Menu.Dropdown>
477483
</Menu>
478484
{showTopic && <Topic styleName={classes.actionIcon} />}
@@ -603,7 +609,12 @@ const InputMessage = observer((props: any) => {
603609
}}
604610
>
605611
<Text sx={{ padding: "5px 5px 5px 10px" }}>DevChat Workflows</Text>
606-
<ScrollArea.Autosize mah={240} type="always" placeholder="" viewportRef={viewport}>
612+
<ScrollArea.Autosize
613+
mah={240}
614+
type="always"
615+
placeholder=""
616+
viewportRef={viewport}
617+
>
607618
{commandMenusNode}
608619
</ScrollArea.Autosize>
609620
</Popover.Dropdown>

0 commit comments

Comments
 (0)