Skip to content

Commit 661b5d1

Browse files
authored
feat: check or enter to close the list of assistants (#469)
* feat: check or enter to close the list of assistants * docs: update changelog
1 parent 47d2e46 commit 661b5d1

10 files changed

Lines changed: 44 additions & 24 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Information about release notes of Coco Server is provided here.
1313

1414
### 🚀 Features
1515

16+
- feat: check or enter to close the list of assistants #469
17+
1618
### 🐛 Bug fix
1719

1820
### ✈️ Improvements

src/components/Assistant/AssistantList.tsx

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
5151
const aiAssistant = useShortcutsStore((state) => state.aiAssistant);
5252
const [assistants, setAssistants] = useState<any[]>([]);
5353
const [isRefreshing, setIsRefreshing] = useState(false);
54+
const popoverRef = useRef<HTMLDivElement>(null);
5455
const popoverButtonRef = useRef<HTMLButtonElement>(null);
5556
const searchInputRef = useRef<HTMLInputElement>(null);
5657
const [keyword, setKeyword] = useState("");
@@ -195,25 +196,41 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
195196
setTimeout(() => setIsRefreshing(false), 1000);
196197
};
197198

198-
useKeyPress(["uparrow", "downarrow"], (_, key) => {
199-
const isClose = isNil(popoverButtonRef.current?.dataset["open"]);
200-
const index = assistants.findIndex(
201-
(item) => item._id === currentAssistant?._id
202-
);
203-
const length = assistants.length;
199+
useKeyPress(
200+
["uparrow", "downarrow", "enter"],
201+
(event, key) => {
202+
const isClose = isNil(popoverButtonRef.current?.dataset["open"]);
204203

205-
if (isClose || length <= 1) return;
204+
if (isClose) return;
206205

207-
let nextIndex = index;
206+
event.stopPropagation();
207+
event.preventDefault();
208208

209-
if (key === "uparrow") {
210-
nextIndex = index > 0 ? index - 1 : length - 1;
211-
} else {
212-
nextIndex = index < length - 1 ? index + 1 : 0;
213-
}
209+
if (key === "enter") {
210+
return popoverButtonRef.current?.click();
211+
}
214212

215-
setCurrentAssistant(assistants[nextIndex]);
216-
});
213+
const index = assistants.findIndex(
214+
(item) => item._id === currentAssistant?._id
215+
);
216+
const length = assistants.length;
217+
218+
if (length <= 1) return;
219+
220+
let nextIndex = index;
221+
222+
if (key === "uparrow") {
223+
nextIndex = index > 0 ? index - 1 : length - 1;
224+
} else {
225+
nextIndex = index < length - 1 ? index + 1 : 0;
226+
}
227+
228+
setCurrentAssistant(assistants[nextIndex]);
229+
},
230+
{
231+
target: popoverRef,
232+
}
233+
);
217234

218235
const handlePrev = useCallback(() => {
219236
if (pagination.current <= 1) return;
@@ -231,7 +248,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
231248

232249
return (
233250
<div className="relative">
234-
<Popover>
251+
<Popover ref={popoverRef}>
235252
<PopoverButton
236253
ref={popoverButtonRef}
237254
className="h-6 p-1 px-1.5 flex items-center gap-1 rounded-full bg-white dark:bg-[#202126] text-sm/6 font-semibold text-gray-800 dark:text-[#d8d8d8] border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none"
@@ -326,6 +343,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
326343
)}
327344
onClick={() => {
328345
setCurrentAssistant(assistant);
346+
popoverButtonRef.current?.click();
329347
}}
330348
>
331349
<div className="flex items-center justify-center size-6 bg-white border border-[#E6E6E6] rounded-full overflow-hidden">

src/components/Assistant/SessionFile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const SessionFile = (props: SessionFileProps) => {
125125
onChange={handleCheckAll}
126126
/>
127127
</div>
128-
<ul className="flex-1 overflow-auto flex flex-col gap-2 mt-6">
128+
<ul className="flex-1 overflow-auto flex flex-col gap-2 mt-6 p-0">
129129
{uploadedFiles.map((item) => {
130130
const { id, name, icon, size } = item._source;
131131

src/components/ChatMessage/PrevSuggestion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const PrevSuggestion: FC<PrevSuggestionProps> = (props) => {
2424
}, [JSON.stringify(currentAssistant)]);
2525

2626
return (
27-
<ul className="absolute left-2 bottom-2 flex flex-col gap-2">
27+
<ul className="absolute left-2 bottom-2 flex flex-col gap-2 p-0">
2828
{list.map((item) => {
2929
return (
3030
<li

src/components/Common/HistoryList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const HistoryList: FC<HistoryListProps> = (props) => {
206206
<div key={label}>
207207
<span className="text-xs text-[#999] px-3">{t(label)}</span>
208208

209-
<ul>
209+
<ul className="p-0">
210210
{list.map((item) => {
211211
const { _id, _source } = item;
212212

src/components/Search/ContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const ContextMenu = ({ hideCoco }: ContextMenuProps) => {
206206
>
207207
<div className="text-[#999] dark:text-[#666] truncate">{title}</div>
208208

209-
<ul className="flex flex-col -mx-2">
209+
<ul className="flex flex-col -mx-2 p-0">
210210
{searchMenus.map((item, index) => {
211211
const { name, icon, keys, clickEvent } = item;
212212

src/components/Search/MCPPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export default function SearchPopover({
261261
</div>
262262

263263
{visibleList.length > 0 ? (
264-
<ul className="flex flex-col gap-2">
264+
<ul className="flex flex-col gap-2 p-0">
265265
{visibleList?.map((item, index) => {
266266
const { id, name } = item;
267267

src/components/Search/SearchPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export default function SearchPopover({
266266
</div>
267267

268268
{visibleList.length > 0 ? (
269-
<ul className="flex flex-col gap-2">
269+
<ul className="flex flex-col gap-2 p-0">
270270
{visibleList?.map((item, index) => {
271271
const { id, name } = item;
272272

src/components/Settings/Extensions/components/Details/Application/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const App: FC<AppProps> = (props) => {
4444
];
4545

4646
return (
47-
<ul className="flex flex-col gap-2">
47+
<ul className="flex flex-col gap-2 p-0">
4848
{metadata.map((item) => {
4949
const { label, value } = item;
5050

src/components/Settings/Extensions/components/Details/Applications/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Applications = () => {
4040
{t("settings.extensions.application.button.addDirectories")}
4141
</Button>
4242

43-
<ul className="flex flex-col gap-2">
43+
<ul className="flex flex-col gap-2 p-0">
4444
{searchPaths.map((item) => {
4545
return (
4646
<li key={item} className="flex items-center justify-between gap-2">

0 commit comments

Comments
 (0)