| 1 | import { ChevronDownIcon } from "@heroicons/react/24/outline"; |
| 2 | import { ArrowPathIcon } from "@heroicons/react/24/solid"; |
| 3 | import type { ProfileDescription } from "core/config/ConfigHandler"; |
| 4 | import { useAppSelector } from "../../redux/hooks"; |
| 5 | import { fontSize } from "../../util"; |
| 6 | import { cn } from "../../util/cn"; |
| 7 | import { useLump } from "../mainInput/Lump/LumpContext"; |
| 8 | import { ListboxButton } from "../ui"; |
| 9 | import { AssistantIcon } from "./AssistantIcon"; |
| 10 | |
| 11 | interface SelectedAssistantButtonProps { |
| 12 | selectedProfile: ProfileDescription | null; |
| 13 | } |
| 14 | |
| 15 | export function SelectedAssistantButton({ |
| 16 | selectedProfile, |
| 17 | }: SelectedAssistantButtonProps) { |
| 18 | const { isToolbarExpanded } = useLump(); |
| 19 | const configLoading = useAppSelector((store) => store.config.loading); |
| 20 | |
| 21 | return ( |
| 22 | <ListboxButton |
| 23 | data-testid="assistant-select-button" |
| 24 | className="text-description border-none bg-transparent hover:brightness-125" |
| 25 | style={{ fontSize: fontSize(-3) }} |
| 26 | > |
| 27 | <div className="flex flex-row items-center gap-1.5"> |
| 28 | {selectedProfile === null ? ( |
| 29 | "Create your first assistant" |
| 30 | ) : configLoading ? ( |
| 31 | <span className="text-description flex flex-row items-center"> |
| 32 | <ArrowPathIcon |
| 33 | className={cn( |
| 34 | "text-description mr-1.5 h-3 w-3", |
| 35 | configLoading && "animate-spin-slow", |
| 36 | )} |
| 37 | /> |
| 38 | Loading |
| 39 | </span> |
| 40 | ) : ( |
| 41 | <> |
| 42 | <div className="h-3 w-3 flex-shrink-0 select-none"> |
| 43 | <AssistantIcon size={3} assistant={selectedProfile} /> |
| 44 | </div> |
| 45 | <span |
| 46 | className={`line-clamp-1 select-none break-all ${isToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`} |
| 47 | > |
| 48 | {selectedProfile.title} |
| 49 | </span> |
| 50 | </> |
| 51 | )} |
| 52 | </div> |
| 53 | <ChevronDownIcon |
| 54 | className="h-2 w-2 flex-shrink-0 select-none" |
| 55 | aria-hidden="true" |
| 56 | /> |
| 57 | </ListboxButton> |
| 58 | ); |
| 59 | } |