Changesets · Branches · Tags · Compare
| Changeset | cd22093c507b599034a4e7f14ac6a6e1cfb1aeb8ca243d3255870d077226fd27 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-05-23 16:58 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-05-23 16:58 -07:00 |
| Parents | 4a5fab4dde7e |
8 files changed
modified gui/src/components/TabBar/TabBar.tsx +9 −4
| @@ -35,6 +35,8 @@ | ||
| 35 | 35 | border-bottom: none; |
| 36 | 36 | position: relative; |
| 37 | 37 | margin-top: 2px; |
| 38 | + max-height: 100px; | |
| 39 | + overflow: auto; | |
| 38 | 40 | |
| 39 | 41 | /* Hide scrollbar but keep functionality */ |
| 40 | 42 | scrollbar-width: none; |
| @@ -223,10 +225,13 @@ | ||
| 223 | 225 | } |
| 224 | 226 | }; |
| 225 | 227 | |
| 226 | - return tabs.length === 1 ? ( | |
| 227 | - <></> | |
| 228 | - ) : ( | |
| 229 | - <TabBarContainer ref={ref}> | |
| 228 | + return ( | |
| 229 | + <TabBarContainer | |
| 230 | + ref={ref} | |
| 231 | + style={{ | |
| 232 | + display: tabs.length === 1 ? "none" : "flex", | |
| 233 | + }} | |
| 234 | + > | |
| 230 | 235 | {tabs.map((tab) => ( |
| 231 | 236 | <Tab |
| 232 | 237 | key={tab.id} |
modified gui/src/components/find/FindWidget.tsx +22 −17
| @@ -3,7 +3,14 @@ | ||
| 3 | 3 | ArrowUpIcon, |
| 4 | 4 | XMarkIcon, |
| 5 | 5 | } from "@heroicons/react/24/outline"; |
| 6 | -import { RefObject, useCallback, useEffect, useMemo, useState } from "react"; | |
| 6 | +import { | |
| 7 | + RefObject, | |
| 8 | + useCallback, | |
| 9 | + useEffect, | |
| 10 | + useMemo, | |
| 11 | + useRef, | |
| 12 | + useState, | |
| 13 | +} from "react"; | |
| 7 | 14 | import { HeaderButton, Input } from ".."; |
| 8 | 15 | import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; |
| 9 | 16 | import { |
| @@ -11,8 +18,8 @@ | ||
| 11 | 18 | SearchMatch, |
| 12 | 19 | searchWithinContainer, |
| 13 | 20 | } from "./findWidgetSearch"; |
| 14 | -import { useDebouncedInput } from "./useDebouncedInput"; | |
| 15 | -import { useElementSize } from "./useElementDims"; | |
| 21 | +import useDebounceValue from "./useDebounce"; | |
| 22 | +import { useElementSize } from "./useElementSize"; | |
| 16 | 23 | |
| 17 | 24 | interface HighlightOverlayProps { |
| 18 | 25 | rectangle: Rectangle; |
| @@ -51,15 +58,12 @@ | ||
| 51 | 58 | export const useFindWidget = ( |
| 52 | 59 | searchRef: RefObject<HTMLDivElement>, |
| 53 | 60 | headerRef: RefObject<HTMLDivElement>, |
| 54 | - refreshDependencies: React.DependencyList, | |
| 55 | 61 | disabled: boolean, |
| 56 | 62 | ) => { |
| 57 | 63 | // Search input, debounced |
| 58 | - const { | |
| 59 | - inputRef, | |
| 60 | - debouncedValue: searchTerm, | |
| 61 | - currentValue, | |
| 62 | - } = useDebouncedInput(); | |
| 64 | + const inputRef = useRef<HTMLInputElement>(null); | |
| 65 | + const [currentValue, setCurrentValue] = useState<string>(""); | |
| 66 | + const searchTerm = useDebounceValue(currentValue, 300); | |
| 63 | 67 | |
| 64 | 68 | // Widget open/closed state |
| 65 | 69 | const [open, setOpen] = useState<boolean>(false); |
| @@ -134,14 +138,12 @@ | ||
| 134 | 138 | }, [inputRef, matches, nextMatch]); |
| 135 | 139 | |
| 136 | 140 | // Handle container resize changes - highlight positions must adjust |
| 137 | - const headerSize = useElementSize(headerRef); | |
| 138 | - const containerSize = useElementSize(searchRef); | |
| 141 | + const { clientHeight: headerHeight, isResizing: headerResizing } = | |
| 142 | + useElementSize(headerRef); | |
| 143 | + const { isResizing: containerResizing } = useElementSize(searchRef); | |
| 139 | 144 | const isResizing = useMemo(() => { |
| 140 | - return containerSize.isResizing || headerSize.isResizing; | |
| 141 | - }, [containerSize, headerSize]); | |
| 142 | - const headerHeight = useMemo(() => { | |
| 143 | - return headerSize.size.height; | |
| 144 | - }, [headerSize]); | |
| 145 | + return containerResizing || headerResizing; | |
| 146 | + }, [containerResizing, headerResizing]); | |
| 145 | 147 | |
| 146 | 148 | // Main function for finding matches and generating highlight overlays |
| 147 | 149 | const refreshSearch = useCallback( |
| @@ -192,7 +194,7 @@ | ||
| 192 | 194 | } else { |
| 193 | 195 | refreshSearch("closest"); |
| 194 | 196 | } |
| 195 | - }, [refreshSearch, open, disabled, isResizing, ...refreshDependencies]); | |
| 197 | + }, [refreshSearch, open, disabled, isResizing]); | |
| 196 | 198 | |
| 197 | 199 | // Clicks in search div can cause content changes that for some reason don't trigger resize |
| 198 | 200 | // Refresh clicking within container |
| @@ -220,6 +222,9 @@ | ||
| 220 | 222 | type="text" |
| 221 | 223 | ref={inputRef} |
| 222 | 224 | value={currentValue} |
| 225 | + onChange={(e) => { | |
| 226 | + setCurrentValue(e.target.value); | |
| 227 | + }} | |
| 223 | 228 | placeholder="Search..." |
| 224 | 229 | /> |
| 225 | 230 | <p className="xs:block hidden min-w-12 whitespace-nowrap px-1 text-center text-xs"> |
modified gui/src/components/find/findWidgetSearch.ts +4 −3
| @@ -87,9 +87,10 @@ | ||
| 87 | 87 | startIndex = endIndex; |
| 88 | 88 | |
| 89 | 89 | const top = |
| 90 | - rect.top + searchContainer.clientTop + searchContainer.scrollTop; | |
| 91 | - // - | |
| 92 | - // options.offsetHeight; | |
| 90 | + rect.top + | |
| 91 | + searchContainer.clientTop + | |
| 92 | + searchContainer.scrollTop - | |
| 93 | + options.offsetHeight; | |
| 93 | 94 | |
| 94 | 95 | const left = |
| 95 | 96 | rect.left + searchContainer.clientLeft + searchContainer.scrollLeft; |
added gui/src/components/find/useDebounce.ts +19 −0
| @@ -0,0 +1,19 @@ | ||
| 1 | +import { useEffect, useState } from "react"; | |
| 2 | + | |
| 3 | +function useDebounceValue<T>(value: T, delay: number = 500): T { | |
| 4 | + const [debouncedValue, setDebouncedValue] = useState<T>(value); | |
| 5 | + | |
| 6 | + useEffect(() => { | |
| 7 | + const timer = setTimeout(() => { | |
| 8 | + setDebouncedValue(value); | |
| 9 | + }, delay); | |
| 10 | + | |
| 11 | + return () => { | |
| 12 | + clearTimeout(timer); | |
| 13 | + }; | |
| 14 | + }, [value, delay]); | |
| 15 | + | |
| 16 | + return debouncedValue; | |
| 17 | +} | |
| 18 | + | |
| 19 | +export default useDebounceValue; |
deleted gui/src/components/find/useDebouncedInput.ts +0 −48
| @@ -1,48 +0,0 @@ | ||
| 1 | -import { debounce } from "lodash"; | |
| 2 | -import { useEffect, useRef, useState } from "react"; | |
| 3 | - | |
| 4 | -interface UseDebouncedInputResult { | |
| 5 | - inputRef: React.RefObject<HTMLInputElement>; | |
| 6 | - debouncedValue: string; | |
| 7 | - currentValue: string; | |
| 8 | -} | |
| 9 | - | |
| 10 | -export const useDebouncedInput = ( | |
| 11 | - debounceDelay: number = 300, | |
| 12 | -): UseDebouncedInputResult => { | |
| 13 | - const [debouncedValue, setDebouncedValue] = useState(""); | |
| 14 | - const [currentValue, setCurrentValue] = useState(""); | |
| 15 | - const inputRef = useRef<HTMLInputElement>(null); | |
| 16 | - | |
| 17 | - const debouncedSetValue = useRef( | |
| 18 | - debounce((value: string) => { | |
| 19 | - setDebouncedValue(value); | |
| 20 | - }, debounceDelay), | |
| 21 | - ).current; | |
| 22 | - | |
| 23 | - useEffect(() => { | |
| 24 | - debouncedSetValue(currentValue); | |
| 25 | - // Initial value is set immediately | |
| 26 | - if (currentValue === "") { | |
| 27 | - setDebouncedValue(""); | |
| 28 | - } | |
| 29 | - | |
| 30 | - return () => { | |
| 31 | - debouncedSetValue.cancel(); | |
| 32 | - }; | |
| 33 | - }, [currentValue, debouncedSetValue]); | |
| 34 | - | |
| 35 | - useEffect(() => { | |
| 36 | - const input = inputRef.current; | |
| 37 | - if (!input) return; | |
| 38 | - | |
| 39 | - const handleChange = (event: Event) => { | |
| 40 | - setCurrentValue((event.target as HTMLInputElement).value); | |
| 41 | - }; | |
| 42 | - | |
| 43 | - input.addEventListener("input", handleChange); | |
| 44 | - return () => input.removeEventListener("input", handleChange); | |
| 45 | - }, []); | |
| 46 | - | |
| 47 | - return { inputRef, debouncedValue, currentValue }; | |
| 48 | -}; |
deleted gui/src/components/find/useElementDims.ts +0 −42
| @@ -1,42 +0,0 @@ | ||
| 1 | -import { debounce } from "lodash"; | |
| 2 | -import { useEffect, useState } from "react"; | |
| 3 | - | |
| 4 | -export function useElementSize( | |
| 5 | - ref: React.RefObject<HTMLElement>, | |
| 6 | - resizeDebounce = 200, | |
| 7 | -) { | |
| 8 | - const [size, setSize] = useState({ | |
| 9 | - height: 0, | |
| 10 | - width: 0, | |
| 11 | - }); | |
| 12 | - const [isResizing, setIsResizing] = useState(false); | |
| 13 | - | |
| 14 | - useEffect(() => { | |
| 15 | - if (!ref.current) return; | |
| 16 | - | |
| 17 | - const element = ref.current; | |
| 18 | - const debouncedSetSize = debounce((entries: ResizeObserverEntry[]) => { | |
| 19 | - if (!entries.length) return; | |
| 20 | - | |
| 21 | - setIsResizing(false); | |
| 22 | - setSize({ | |
| 23 | - height: entries[0].contentRect.height, | |
| 24 | - width: entries[0].contentRect.width, | |
| 25 | - }); | |
| 26 | - }, resizeDebounce); | |
| 27 | - | |
| 28 | - const resizeObserver = new ResizeObserver((entries) => { | |
| 29 | - setIsResizing(true); | |
| 30 | - debouncedSetSize(entries); | |
| 31 | - }); | |
| 32 | - resizeObserver.observe(element); | |
| 33 | - | |
| 34 | - return () => { | |
| 35 | - debouncedSetSize.cancel(); | |
| 36 | - resizeObserver.unobserve(element); | |
| 37 | - resizeObserver.disconnect(); | |
| 38 | - }; | |
| 39 | - }, [ref, resizeDebounce]); | |
| 40 | - | |
| 41 | - return { ref, size, isResizing }; | |
| 42 | -} |
added gui/src/components/find/useElementSize.ts +81 −0
| @@ -0,0 +1,81 @@ | ||
| 1 | +import { RefObject, useCallback, useEffect, useState } from "react"; | |
| 2 | + | |
| 3 | +interface ElementSize { | |
| 4 | + clientWidth: number; | |
| 5 | + clientHeight: number; | |
| 6 | + scrollWidth: number; | |
| 7 | + scrollHeight: number; | |
| 8 | + isResizing: boolean; | |
| 9 | +} | |
| 10 | + | |
| 11 | +interface UseElementSizeOptions { | |
| 12 | + debounceMs?: number; | |
| 13 | +} | |
| 14 | + | |
| 15 | +export const useElementSize = ( | |
| 16 | + ref: RefObject<HTMLElement>, | |
| 17 | + debounceMs = 250, | |
| 18 | +): ElementSize => { | |
| 19 | + const [size, setSize] = useState<ElementSize>({ | |
| 20 | + clientWidth: 0, | |
| 21 | + clientHeight: 0, | |
| 22 | + scrollWidth: 0, | |
| 23 | + scrollHeight: 0, | |
| 24 | + isResizing: false, | |
| 25 | + }); | |
| 26 | + | |
| 27 | + // Debounced update function | |
| 28 | + const debouncedSetSize = useCallback( | |
| 29 | + (measurements: Omit<ElementSize, "isResizing">) => { | |
| 30 | + let timeoutId: NodeJS.Timeout; | |
| 31 | + | |
| 32 | + setSize((prev) => ({ ...prev, isResizing: true })); | |
| 33 | + | |
| 34 | + timeoutId = setTimeout(() => { | |
| 35 | + setSize({ | |
| 36 | + ...measurements, | |
| 37 | + isResizing: false, | |
| 38 | + }); | |
| 39 | + }, debounceMs); | |
| 40 | + | |
| 41 | + return () => clearTimeout(timeoutId); | |
| 42 | + }, | |
| 43 | + [debounceMs], | |
| 44 | + ); | |
| 45 | + | |
| 46 | + useEffect(() => { | |
| 47 | + if (!ref.current) return; | |
| 48 | + | |
| 49 | + const updateSize = () => { | |
| 50 | + const element = ref.current; | |
| 51 | + if (!element) return; | |
| 52 | + | |
| 53 | + const measurements = { | |
| 54 | + clientWidth: element.clientWidth, | |
| 55 | + clientHeight: element.clientHeight, | |
| 56 | + scrollWidth: element.scrollWidth, | |
| 57 | + scrollHeight: element.scrollHeight, | |
| 58 | + }; | |
| 59 | + | |
| 60 | + debouncedSetSize(measurements); | |
| 61 | + }; | |
| 62 | + | |
| 63 | + // Create ResizeObserver instance | |
| 64 | + const resizeObserver = new ResizeObserver(() => { | |
| 65 | + updateSize(); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + // Start observing the element | |
| 69 | + resizeObserver.observe(ref.current); | |
| 70 | + | |
| 71 | + // Initial size calculation | |
| 72 | + updateSize(); | |
| 73 | + | |
| 74 | + // Cleanup | |
| 75 | + return () => { | |
| 76 | + resizeObserver.disconnect(); | |
| 77 | + }; | |
| 78 | + }, [ref, debouncedSetSize]); | |
| 79 | + | |
| 80 | + return size; | |
| 81 | +}; |
modified gui/src/pages/gui/Chat.tsx +0 −1
| @@ -156,7 +156,6 @@ | ||
| 156 | 156 | const { widget, highlights } = useFindWidget( |
| 157 | 157 | stepsDivRef, |
| 158 | 158 | tabsRef, |
| 159 | - [history], | |
| 160 | 159 | isStreaming, |
| 161 | 160 | ); |
| 162 | 161 |