mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 11:50:14 +01:00
* feat: initial mockup * wip: activesetting, may use or not use * wip: mention with useCombobox usage * feat: connect textarea to new mention popover * refactor: consolidate icon logic for Landing/convos * refactor: cleanup URL logic * refactor(useTextarea): key up handler * wip: render desired mention options * refactor: improve mention detection * feat: modular chat the default option * WIP: first pass mention selection * feat: scroll mention items with keypad * chore(showMentionPopoverFamily): add typing to atomFamily * feat: removeAtSymbol * refactor(useListAssistantsQuery): use defaultOrderQuery as default param * feat: assistants mentioning * fix conversation switch errors * filter mention selections based on startup settings and available endpoints * fix: mentions model spec icon URL * style: archive icon * fix: convo renaming behavior on click * fix(Convo): toggle hover state * style: EditMenu refactor * fix: archive chats table * fix: errorsToString import * chore: remove comments * chore: remove comment * feat: mention descriptions * refactor: make sure continue hover button is always last, add correct fork button alt text
37 lines
1 KiB
TypeScript
37 lines
1 KiB
TypeScript
import { useMemo, useState } from 'react';
|
|
import { matchSorter } from 'match-sorter';
|
|
import type { OptionWithIcon, MentionOption } from '~/common';
|
|
|
|
export default function useCombobox({
|
|
value,
|
|
options,
|
|
}: {
|
|
value: string;
|
|
options: Array<OptionWithIcon | MentionOption>;
|
|
}) {
|
|
const [open, setOpen] = useState(false);
|
|
const [searchValue, setSearchValue] = useState('');
|
|
|
|
const matches = useMemo(() => {
|
|
if (!searchValue) {
|
|
return options;
|
|
}
|
|
const keys = ['label', 'value'];
|
|
const matches = matchSorter(options, searchValue, { keys });
|
|
// Radix Select does not work if we don't render the selected item, so we
|
|
// make sure to include it in the list of matches.
|
|
const selectedItem = options.find((currentItem) => currentItem.value === value);
|
|
if (selectedItem && !matches.includes(selectedItem)) {
|
|
matches.push(selectedItem);
|
|
}
|
|
return matches;
|
|
}, [searchValue, value, options]);
|
|
|
|
return {
|
|
open,
|
|
setOpen,
|
|
searchValue,
|
|
setSearchValue,
|
|
matches,
|
|
};
|
|
}
|