From f76b10c40e86fdd51ab893333427a3c10f6fb555 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 23 Mar 2025 22:49:28 -0700 Subject: [PATCH 1/3] various fixes --- .../Lump/BlockSettingsTopToolbar.tsx | 58 +++++++++---------- .../platform/AssistantSelect.tsx | 20 +++++-- .../platform/AssistantSelectOptions.tsx | 14 ++--- gui/src/pages/config/KeyboardShortcuts.tsx | 49 +++++++--------- gui/src/pages/config/index.tsx | 18 +++--- gui/src/pages/gui/Chat.tsx | 2 +- 6 files changed, 83 insertions(+), 78 deletions(-) diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx index f6abe9e85..a561d2e1c 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx @@ -98,38 +98,38 @@ export function BlockSettingsTopToolbar(props: BlockSettingsTopToolbarProps) { }; return ( -
-
- -
-
- {sections.map((section) => ( - - props.setSelectedSection( - props.selectedSection === section.id ? null : section.id, - ) - } - /> - ))} +
+
+
+ +
+
+ {sections.map((section) => ( + + props.setSelectedSection( + props.selectedSection === section.id ? null : section.id, + ) + } + /> + ))} +
-
- -
+
); } diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 43caa02a9..214b1b495 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -5,19 +5,24 @@ import { useContext, useEffect, useRef } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { cycleProfile } from "../../../redux"; -import { useAppDispatch } from "../../../redux/hooks"; +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; import { fontSize, isMetaEquivalentKeyPressed } from "../../../util"; import PopoverTransition from "../../mainInput/InputToolbar/bottom/PopoverTransition"; import AssistantIcon from "./AssistantIcon"; import { AssistantSelectOptions } from "./AssistantSelectOptions"; function AssistantSelectButton(props: { selectedProfile: ProfileDescription }) { + const isLumpToolbarExpanded = useAppSelector( + (state) => state.ui.isBlockSettingsToolbarExpanded, + ); return (
- +
- + {props.selectedProfile.title} Create your first assistant @@ -89,7 +94,12 @@ export default function AssistantSelect() { - + { if (buttonRef.current) { diff --git a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx index c7b9caa80..a33bccc19 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -48,7 +48,7 @@ export function AssistantSelectOptions({ } return ( -
+
{profiles.map((profile, idx) => { return ( @@ -68,13 +68,13 @@ export function AssistantSelectOptions({ onClose(); }} > -
-
+
+
{profile.title} @@ -90,10 +90,10 @@ export function AssistantSelectOptions({ onClick={session ? onNewAssistant : () => login(false)} >
- + New Assistant
diff --git a/gui/src/pages/config/KeyboardShortcuts.tsx b/gui/src/pages/config/KeyboardShortcuts.tsx index 072223453..d393f43a8 100644 --- a/gui/src/pages/config/KeyboardShortcuts.tsx +++ b/gui/src/pages/config/KeyboardShortcuts.tsx @@ -1,3 +1,4 @@ +import { useMemo } from "react"; import styled from "styled-components"; import { defaultBorderRadius, @@ -7,16 +8,6 @@ import { import { ToolTip } from "../../components/gui/Tooltip"; import { getPlatform, isJetBrains } from "../../util"; -const GridDiv = styled.div` - display: grid; - grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); - grid-gap: 1rem; - padding: 1rem 0; - justify-items: center; - align-items: center; - overflow-x: hidden; -`; - const StyledKeyDiv = styled.div` border: 0.5px solid ${lightGray}; border-radius: ${defaultBorderRadius}; @@ -64,9 +55,9 @@ interface KeyboardShortcutProps { function KeyboardShortcut(props: KeyboardShortcutProps) { const shortcut = getPlatform() === "mac" ? props.mac : props.windows; return ( -
- {props.description} -
+
+ {props.description}: +
{shortcut.split(" ").map((key, i) => { return ; })} @@ -201,23 +192,25 @@ const jetbrainsShortcuts: KeyboardShortcutProps[] = [ ]; function KeyboardShortcuts() { + const shortcuts = useMemo(() => { + return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts; + }, []); + return ( -
+

Keyboard shortcuts

- - {(isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts).map( - (shortcut, i) => { - return ( - - ); - }, - )} - +
+ {shortcuts.map((shortcut, i) => { + return ( + + ); + })} +
); } diff --git a/gui/src/pages/config/index.tsx b/gui/src/pages/config/index.tsx index a336cb69c..d4d50103e 100644 --- a/gui/src/pages/config/index.tsx +++ b/gui/src/pages/config/index.tsx @@ -32,30 +32,32 @@ function ConfigPage() { id: "settings", label: "Settings", component: , - icon: , + icon: , }, { id: "indexing", label: "Indexing", component: , - icon: , + icon: , }, { id: "help", label: "Help", component: , - icon: , + icon: ( + + ), }, { id: "shortcuts", label: "Shortcuts", component: , - icon: , + icon: , }, ]; return ( -
+
{/* Tab Headers */} -
+
{tabs.map((tab) => (
setActiveTab(tab.id)} @@ -85,7 +87,7 @@ function ConfigPage() {
{/* Tab Content */} -
+
{tabs.find((tab) => tab.id === activeTab)?.component}
diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index c75256813..653efcd3d 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -292,7 +292,7 @@ export function Chat() { 0 ? "flex-1" : ""}`} + className={`mt-[2px] overflow-y-scroll ${showPageHeader ? "" : "pt-[8px]"} ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`} > {highlights} {history.map((item, index: number) => ( From c285a9582da7c3cbf81667f7b7e42ce357120a47 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 24 Mar 2025 02:39:57 -0700 Subject: [PATCH 2/3] diff checker --- gui/src/components/mainInput/InputToolbar.tsx | 8 +- .../components/modelSelection/ModeSelect.tsx | 23 ++- .../components/modelSelection/ModelSelect.tsx | 175 +++++++--------- .../platform/AssistantSelect.tsx | 6 +- gui/src/components/usePopoverPosition.ts | 193 ++++++++++++++++++ 5 files changed, 292 insertions(+), 113 deletions(-) create mode 100644 gui/src/components/usePopoverPosition.ts diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index f3a8b975f..c4044dc5b 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -28,7 +28,7 @@ import { isMetaEquivalentKeyPressed, } from "../../util"; import { ToolTip } from "../gui/Tooltip"; -import ModelSelect from "../modelSelection/ModelSelect"; +import ExampleListbox from "../Listbox"; import ModeSelect from "../modelSelection/ModeSelect"; import HoverItem from "./InputToolbar/bottom/HoverItem"; @@ -116,7 +116,11 @@ function InputToolbar(props: InputToolbarProps) { >
- + + {/*
+ + +
*/}
{props.toolbarOptions?.hideImageUpload || (supportsImages && ( diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index afc0588fa..efb670ae6 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -9,7 +9,7 @@ import { } from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; -import { useEffect } from "react"; +import { useEffect, useMemo } from "react"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscInputBackground } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; @@ -25,6 +25,7 @@ import { getMetaKeyLabel, isJetBrains, } from "../../util"; +import Shortcut from "../gui/Shortcut"; const StyledListboxButton = styled(Listbox.Button)` font-family: inherit; @@ -81,7 +82,13 @@ function ModeSelect() { const mode = useAppSelector(selectCurrentMode); const selectedModel = useAppSelector(selectDefaultModel); const agentModeSupported = selectedModel && modelSupportsTools(selectedModel); - const jetbrains = isJetBrains(); + + const jetbrains = useMemo(() => { + return isJetBrains(); + }, []); + const metaKeyLabel = useMemo(() => { + return getMetaKeyLabel(); + }, []); const getModeIcon = (mode: MessageModes) => { switch (mode) { @@ -133,7 +140,9 @@ function ModeSelect() { className="flex items-center gap-1 rounded-full px-2 py-0.5 text-gray-400 transition-colors duration-200" > {getModeIcon(mode)} - {mode.charAt(0).toUpperCase() + mode.slice(1)} + + {mode.charAt(0).toUpperCase() + mode.slice(1)} +
diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 437e2304f..00ed5fec3 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -1,4 +1,4 @@ -import { Listbox } from "@headlessui/react"; +import { Listbox, Transition } from "@headlessui/react"; import { CheckIcon, ChevronDownIcon, @@ -9,7 +9,7 @@ import { import { useContext, useEffect, useRef, useState } from "react"; import { useDispatch } from "react-redux"; import styled from "styled-components"; -import { defaultBorderRadius, lightGray, vscInputBackground } from ".."; +import { defaultBorderRadius, lightGray } from ".."; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; @@ -36,8 +36,6 @@ interface Option { apiKey?: string; } -const MAX_HEIGHT_PX = 300; - const StyledListboxButton = styled(Listbox.Button)` font-family: inherit; display: flex; @@ -53,30 +51,6 @@ const StyledListboxButton = styled(Listbox.Button)` } `; -const StyledListboxOptions = styled(Listbox.Options)<{ $showabove: boolean }>` - margin-top: 4px; - position: absolute; - list-style: none; - padding: 0px; - white-space: nowrap; - cursor: default; - - display: flex; - flex-direction: column; - - font-size: ${fontSize(-3)}; - border-radius: ${defaultBorderRadius}; - border: 0.5px solid ${lightGray}; - background-color: ${vscInputBackground}; - - max-height: ${MAX_HEIGHT_PX}px; - overflow-y: scroll; - - scrollbar-width: none; - - ${(props) => (props.$showabove ? "bottom: 100%;" : "top: 100%;")} -`; - const StyledListboxOption = styled(Listbox.Option)<{ isDisabled?: boolean }>` border-radius: ${defaultBorderRadius}; padding: 4px 12px; @@ -216,12 +190,6 @@ function ModelSelect() { ); }, [allModels]); - useEffect(() => { - const handleResize = () => calculatePosition(); - window.addEventListener("resize", handleResize); - return () => window.removeEventListener("resize", handleResize); - }, []); - useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "'" && isMetaEquivalentKeyPressed(event as any)) { @@ -242,18 +210,6 @@ function ModelSelect() { }; }, [options, defaultModel]); - function calculatePosition() { - if (!buttonRef.current) { - return; - } - const rect = buttonRef.current.getBoundingClientRect(); - const spaceBelow = window.innerHeight - rect.bottom; - const spaceAbove = rect.top; - const dropdownHeight = MAX_HEIGHT_PX; - - setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); - } - function onClickAddModel(e: MouseEvent) { e.stopPropagation(); e.preventDefault(); @@ -281,68 +237,83 @@ function ModelSelect() { dispatch(setDefaultModel({ title: val })); }} > -
- -
- - {modelSelectTitle(defaultModel) || "Select model"}{" "} - -
-
- -
( +
+ - {sortedOptions.map((option, idx) => ( - + + {modelSelectTitle(defaultModel) || "Select model"}{" "} + +
+
+ + + +
+ {sortedOptions.map((option, idx) => ( + + ))} +
-
- +
+ - {selectedProfile?.profileType === "local" && ( - <> - -
- - Add Chat model -
-
- - )} + {selectedProfile?.profileType === "local" && ( + <> + +
+ + Add Chat model +
+
+ + )} - + - - meta ' to toggle model - -
- -
+ + meta ' to toggle model + +
+ + +
+ )} ); } diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 214b1b495..f5ed3105f 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -95,9 +95,11 @@ export default function AssistantSelect() { , +// // popoverRef: RefObject, +// // defaultHorizontalAlign: "left" | "right", +// // defaultVerticalAlign: "bottom" | "top", +// // ) => { +// // // const defaultSizes = useMemo(() => { +// // // return { +// // // minHeight: defaults?.minHeight ?? DEFAULT_POPOVER_MIN_HEIGHT, +// // // maxHeight: defaults?.maxHeight ?? DEFAULT_POPOVER_MAX_HEIGHT, +// // // minWidth: defaults?.minWidth ?? DEFAULT_POPOVER_MIN_WIDTH, +// // // maxWidth: defaults?.maxWidth ?? DEFAULT_POPOVER_MAX_WIDTH, +// // // }; +// // // }, [defaults]); + +// // const [styles, setStyles] = useState({ +// // top: defaultVerticalAlign === "top" ? "100%" : undefined, +// // bottom: defaultVerticalAlign === "bottom" ? "100%" : undefined, +// // right: defaultHorizontalAlign === "right" ? 0 : undefined, +// // left: defaultHorizontalAlign === "left" ? undefined : 0, +// // }); + +// // const calculatePosition = useCallback(() => { +// // if (!containerRef?.current || !popoverRef?.current) { +// // return; +// // } +// // const containerRect = containerRef.current.getBoundingClientRect(); +// // const popoverRect = popoverRef.current.getBoundingClientRect(); + +// // // Decide to show popup above or below and determine min/max height +// // const spaceBelow = window.innerHeight - rect.bottom; +// // const spaceAbove = rect.top; +// // const showBelow = spaceBelow > spaceAbove; +// // const verticalSpace = showBelow ? spaceBelow : spaceAbove; +// // // const maxHeight = Math.min(defaultSizes.maxHeight, verticalSpace); +// // // const minHeight = Math.min(defaultSizes.minHeight, verticalSpace); + +// // // Decide to show popup aligned left/right/left window/right window +// // const minWidth = Math.min(window.innerWidth, defaultSizes.minWidth); +// // const maxWidth = Math.min(window.innerWidth, defaultSizes.maxWidth); + +// // // const spaceRight = window.innerWidth - rect.left; // including container +// // // const spaceLeft = rect.right; // including container + +// // // const alignLeft = spaceRight > spaceLeft; + +// // // // TODO fix this optimization +// // // const horizontalSpace = alignLeft ? spaceRight : spaceLeft; +// // // const showCenter = horizontalSpace < defaultSizes.minWidth; + +// // const distanceToEdge = defaultAlign === "right" ? rect.right : window.innerWidth - rect.left; +// // const useAlign = distanceToEdge > maxWidth +// // // const aligne + +// // setStyles({ +// // top: showBelow ? "100%" : undefined, +// // bottom: showBelow ? undefined : "100%", +// // right: defaultAlign === "right" ? (useAlign ? 0 : undefined): undefined, +// // left: rect.right > maxWidth ? undefined : -rect.left, +// // }); + +// // // setPositionClass( +// // // `${showBelow ? "top-full" : "bottom-full"} ${align === "right" ? "right-0" : align === "left" ? "left-0" : "left-1/2 -translate-x-1/2"} `, +// // // ); +// // }, [containerRef.current, popoverRef.current, defaultHorizontalAlign, defaultVerticalAlign]); + +// // useEffect(() => { +// // calculatePosition(); + +// // if(!containerRef.current || popoverRef.current) { +// // return; +// // } + +// // const handleResize = () => calculatePosition(); +// // window.addEventListener("resize", handleResize); + +// // if(containerRef) +// // const containerObserver = new ResizeObserver((entries) => { +// // calculatePosition(); +// // }); +// // containerObserver.observe(containerRef.current); + +// // return () => { +// // observer.disconnect(); +// // }; + +// // const resizeObserver = new ResizeObserver() +// // containerRef.current?.addEventListener("resize") + +// // return () => window.removeEventListener("resize", handleResize); + +// // }, [calculatePosition, popoverRef.current,containerRef.current ]); + +// // const reCalculate = useCallback(() => { +// // calculatePosition(); +// // }, [calculatePosition]); + +// // return { styles, reCalculate }; +// // }; + +// import { RefObject, useEffect, useState } from "react"; + +// export const usePopoverPosition = ( +// containerRef: RefObject, +// popoverRef: RefObject, +// defaultHorizontalAlign: "left" | "right", +// defaultVerticalAlign: "bottom" | "top", +// ) => { +// const [styles, setStyles] = useState<{ [key: string]: number | string }>({}); + +// useEffect(() => { +// console.log(containerRef, popoverRef); +// const calculatePosition = () => { +// if (!containerRef.current || !popoverRef.current) return; + +// const containerRect = containerRef.current.getBoundingClientRect(); +// const popoverRect = popoverRef.current.getBoundingClientRect(); +// const windowWidth = window.innerWidth; +// const windowHeight = window.innerHeight; + +// // Calculate horizontal position +// let left: number | undefined; +// let right: number | undefined; + +// if (defaultHorizontalAlign === "left") { +// if (containerRect.left + popoverRect.width <= windowWidth) { +// left = containerRect.left; +// } else { +// right = windowWidth - containerRect.right; +// } +// } else { +// if (containerRect.right - popoverRect.width >= 0) { +// right = windowWidth - containerRect.right; +// } else { +// left = 0; +// } +// } + +// // Calculate vertical position +// let top: number | string | undefined; +// let bottom: number | string | undefined; + +// if (defaultVerticalAlign === "bottom") { +// if (containerRect.bottom + popoverRect.height <= windowHeight) { +// top = "100%"; +// } else { +// bottom = "100%"; +// } +// } else { +// if (containerRect.top - popoverRect.height >= 0) { +// bottom = "100%"; +// } else { +// top = "100%"; +// } +// } + +// setStyles({ +// ...(left !== undefined && { left }), +// ...(right !== undefined && { right }), +// ...(top !== undefined && { top }), +// ...(bottom !== undefined && { bottom }), +// // position: "fixed", +// }); +// }; + +// calculatePosition(); +// window.addEventListener("resize", calculatePosition); +// return () => window.removeEventListener("resize", calculatePosition); +// }, [containerRef, popoverRef, defaultHorizontalAlign, defaultVerticalAlign]); + +// return styles; +// }; From 2a0bfc19107bf1a143ed8ce7a902c83317f0633f Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 24 Mar 2025 02:42:53 -0700 Subject: [PATCH 3/3] revert half baked changes --- gui/src/components/mainInput/InputToolbar.tsx | 8 +- .../components/modelSelection/ModelSelect.tsx | 175 +++++++++------- .../platform/AssistantSelectOptions.tsx | 14 +- gui/src/components/usePopoverPosition.ts | 193 ------------------ 4 files changed, 111 insertions(+), 279 deletions(-) delete mode 100644 gui/src/components/usePopoverPosition.ts diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index c4044dc5b..f3a8b975f 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -28,7 +28,7 @@ import { isMetaEquivalentKeyPressed, } from "../../util"; import { ToolTip } from "../gui/Tooltip"; -import ExampleListbox from "../Listbox"; +import ModelSelect from "../modelSelection/ModelSelect"; import ModeSelect from "../modelSelection/ModeSelect"; import HoverItem from "./InputToolbar/bottom/HoverItem"; @@ -116,11 +116,7 @@ function InputToolbar(props: InputToolbarProps) { >
- - {/*
- - -
*/} +
{props.toolbarOptions?.hideImageUpload || (supportsImages && ( diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 00ed5fec3..437e2304f 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -1,4 +1,4 @@ -import { Listbox, Transition } from "@headlessui/react"; +import { Listbox } from "@headlessui/react"; import { CheckIcon, ChevronDownIcon, @@ -9,7 +9,7 @@ import { import { useContext, useEffect, useRef, useState } from "react"; import { useDispatch } from "react-redux"; import styled from "styled-components"; -import { defaultBorderRadius, lightGray } from ".."; +import { defaultBorderRadius, lightGray, vscInputBackground } from ".."; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; @@ -36,6 +36,8 @@ interface Option { apiKey?: string; } +const MAX_HEIGHT_PX = 300; + const StyledListboxButton = styled(Listbox.Button)` font-family: inherit; display: flex; @@ -51,6 +53,30 @@ const StyledListboxButton = styled(Listbox.Button)` } `; +const StyledListboxOptions = styled(Listbox.Options)<{ $showabove: boolean }>` + margin-top: 4px; + position: absolute; + list-style: none; + padding: 0px; + white-space: nowrap; + cursor: default; + + display: flex; + flex-direction: column; + + font-size: ${fontSize(-3)}; + border-radius: ${defaultBorderRadius}; + border: 0.5px solid ${lightGray}; + background-color: ${vscInputBackground}; + + max-height: ${MAX_HEIGHT_PX}px; + overflow-y: scroll; + + scrollbar-width: none; + + ${(props) => (props.$showabove ? "bottom: 100%;" : "top: 100%;")} +`; + const StyledListboxOption = styled(Listbox.Option)<{ isDisabled?: boolean }>` border-radius: ${defaultBorderRadius}; padding: 4px 12px; @@ -190,6 +216,12 @@ function ModelSelect() { ); }, [allModels]); + useEffect(() => { + const handleResize = () => calculatePosition(); + window.addEventListener("resize", handleResize); + return () => window.removeEventListener("resize", handleResize); + }, []); + useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "'" && isMetaEquivalentKeyPressed(event as any)) { @@ -210,6 +242,18 @@ function ModelSelect() { }; }, [options, defaultModel]); + function calculatePosition() { + if (!buttonRef.current) { + return; + } + const rect = buttonRef.current.getBoundingClientRect(); + const spaceBelow = window.innerHeight - rect.bottom; + const spaceAbove = rect.top; + const dropdownHeight = MAX_HEIGHT_PX; + + setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); + } + function onClickAddModel(e: MouseEvent) { e.stopPropagation(); e.preventDefault(); @@ -237,83 +281,68 @@ function ModelSelect() { dispatch(setDefaultModel({ title: val })); }} > - {({ open }) => ( -
- + +
+ + {modelSelectTitle(defaultModel) || "Select model"}{" "} + +
+
+ +
-
- - {modelSelectTitle(defaultModel) || "Select model"}{" "} - -
- - - -
- {sortedOptions.map((option, idx) => ( - - ))} -
+ ))} +
-
- +
+ - {selectedProfile?.profileType === "local" && ( - <> - -
- - Add Chat model -
-
- - )} + {selectedProfile?.profileType === "local" && ( + <> + +
+ + Add Chat model +
+
+ + )} - + - - meta ' to toggle model - -
- - -
- )} + + meta ' to toggle model + +
+ +
); } diff --git a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx index a33bccc19..c7b9caa80 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -48,7 +48,7 @@ export function AssistantSelectOptions({ } return ( -
+
{profiles.map((profile, idx) => { return ( @@ -68,13 +68,13 @@ export function AssistantSelectOptions({ onClose(); }} > -
-
+
+
{profile.title} @@ -90,10 +90,10 @@ export function AssistantSelectOptions({ onClick={session ? onNewAssistant : () => login(false)} >
- + New Assistant
diff --git a/gui/src/components/usePopoverPosition.ts b/gui/src/components/usePopoverPosition.ts deleted file mode 100644 index 33471b7b4..000000000 --- a/gui/src/components/usePopoverPosition.ts +++ /dev/null @@ -1,193 +0,0 @@ -// // import { RefObject, useCallback, useEffect, useMemo, useState } from "react"; - -// // interface PopoverSizes { -// // maxHeight: number; -// // minHeight: number; -// // minWidth: number; -// // maxWidth: number; -// // } - -// // interface PopoverStyles { -// // right?: number; -// // left?: number; -// // top?: string; -// // bottom?: string; -// // } - -// // const DEFAULT_POPOVER_MAX_HEIGHT = 300; -// // const DEFAULT_POPOVER_MIN_HEIGHT = 100; -// // const DEFAULT_POPOVER_MIN_WIDTH = 100; -// // const DEFAULT_POPOVER_MAX_WIDTH = 400; - -// // export const usePopoverPosition = ( -// // containerRef: RefObject, -// // popoverRef: RefObject, -// // defaultHorizontalAlign: "left" | "right", -// // defaultVerticalAlign: "bottom" | "top", -// // ) => { -// // // const defaultSizes = useMemo(() => { -// // // return { -// // // minHeight: defaults?.minHeight ?? DEFAULT_POPOVER_MIN_HEIGHT, -// // // maxHeight: defaults?.maxHeight ?? DEFAULT_POPOVER_MAX_HEIGHT, -// // // minWidth: defaults?.minWidth ?? DEFAULT_POPOVER_MIN_WIDTH, -// // // maxWidth: defaults?.maxWidth ?? DEFAULT_POPOVER_MAX_WIDTH, -// // // }; -// // // }, [defaults]); - -// // const [styles, setStyles] = useState({ -// // top: defaultVerticalAlign === "top" ? "100%" : undefined, -// // bottom: defaultVerticalAlign === "bottom" ? "100%" : undefined, -// // right: defaultHorizontalAlign === "right" ? 0 : undefined, -// // left: defaultHorizontalAlign === "left" ? undefined : 0, -// // }); - -// // const calculatePosition = useCallback(() => { -// // if (!containerRef?.current || !popoverRef?.current) { -// // return; -// // } -// // const containerRect = containerRef.current.getBoundingClientRect(); -// // const popoverRect = popoverRef.current.getBoundingClientRect(); - -// // // Decide to show popup above or below and determine min/max height -// // const spaceBelow = window.innerHeight - rect.bottom; -// // const spaceAbove = rect.top; -// // const showBelow = spaceBelow > spaceAbove; -// // const verticalSpace = showBelow ? spaceBelow : spaceAbove; -// // // const maxHeight = Math.min(defaultSizes.maxHeight, verticalSpace); -// // // const minHeight = Math.min(defaultSizes.minHeight, verticalSpace); - -// // // Decide to show popup aligned left/right/left window/right window -// // const minWidth = Math.min(window.innerWidth, defaultSizes.minWidth); -// // const maxWidth = Math.min(window.innerWidth, defaultSizes.maxWidth); - -// // // const spaceRight = window.innerWidth - rect.left; // including container -// // // const spaceLeft = rect.right; // including container - -// // // const alignLeft = spaceRight > spaceLeft; - -// // // // TODO fix this optimization -// // // const horizontalSpace = alignLeft ? spaceRight : spaceLeft; -// // // const showCenter = horizontalSpace < defaultSizes.minWidth; - -// // const distanceToEdge = defaultAlign === "right" ? rect.right : window.innerWidth - rect.left; -// // const useAlign = distanceToEdge > maxWidth -// // // const aligne - -// // setStyles({ -// // top: showBelow ? "100%" : undefined, -// // bottom: showBelow ? undefined : "100%", -// // right: defaultAlign === "right" ? (useAlign ? 0 : undefined): undefined, -// // left: rect.right > maxWidth ? undefined : -rect.left, -// // }); - -// // // setPositionClass( -// // // `${showBelow ? "top-full" : "bottom-full"} ${align === "right" ? "right-0" : align === "left" ? "left-0" : "left-1/2 -translate-x-1/2"} `, -// // // ); -// // }, [containerRef.current, popoverRef.current, defaultHorizontalAlign, defaultVerticalAlign]); - -// // useEffect(() => { -// // calculatePosition(); - -// // if(!containerRef.current || popoverRef.current) { -// // return; -// // } - -// // const handleResize = () => calculatePosition(); -// // window.addEventListener("resize", handleResize); - -// // if(containerRef) -// // const containerObserver = new ResizeObserver((entries) => { -// // calculatePosition(); -// // }); -// // containerObserver.observe(containerRef.current); - -// // return () => { -// // observer.disconnect(); -// // }; - -// // const resizeObserver = new ResizeObserver() -// // containerRef.current?.addEventListener("resize") - -// // return () => window.removeEventListener("resize", handleResize); - -// // }, [calculatePosition, popoverRef.current,containerRef.current ]); - -// // const reCalculate = useCallback(() => { -// // calculatePosition(); -// // }, [calculatePosition]); - -// // return { styles, reCalculate }; -// // }; - -// import { RefObject, useEffect, useState } from "react"; - -// export const usePopoverPosition = ( -// containerRef: RefObject, -// popoverRef: RefObject, -// defaultHorizontalAlign: "left" | "right", -// defaultVerticalAlign: "bottom" | "top", -// ) => { -// const [styles, setStyles] = useState<{ [key: string]: number | string }>({}); - -// useEffect(() => { -// console.log(containerRef, popoverRef); -// const calculatePosition = () => { -// if (!containerRef.current || !popoverRef.current) return; - -// const containerRect = containerRef.current.getBoundingClientRect(); -// const popoverRect = popoverRef.current.getBoundingClientRect(); -// const windowWidth = window.innerWidth; -// const windowHeight = window.innerHeight; - -// // Calculate horizontal position -// let left: number | undefined; -// let right: number | undefined; - -// if (defaultHorizontalAlign === "left") { -// if (containerRect.left + popoverRect.width <= windowWidth) { -// left = containerRect.left; -// } else { -// right = windowWidth - containerRect.right; -// } -// } else { -// if (containerRect.right - popoverRect.width >= 0) { -// right = windowWidth - containerRect.right; -// } else { -// left = 0; -// } -// } - -// // Calculate vertical position -// let top: number | string | undefined; -// let bottom: number | string | undefined; - -// if (defaultVerticalAlign === "bottom") { -// if (containerRect.bottom + popoverRect.height <= windowHeight) { -// top = "100%"; -// } else { -// bottom = "100%"; -// } -// } else { -// if (containerRect.top - popoverRect.height >= 0) { -// bottom = "100%"; -// } else { -// top = "100%"; -// } -// } - -// setStyles({ -// ...(left !== undefined && { left }), -// ...(right !== undefined && { right }), -// ...(top !== undefined && { top }), -// ...(bottom !== undefined && { bottom }), -// // position: "fixed", -// }); -// }; - -// calculatePosition(); -// window.addEventListener("resize", calculatePosition); -// return () => window.removeEventListener("resize", calculatePosition); -// }, [containerRef, popoverRef, defaultHorizontalAlign, defaultVerticalAlign]); - -// return styles; -// };