refactor: simplify expand chat input to 2-state with optimized button layout
- Remove 3-state logic (normal/50%/80%) - now only normal/expanded - Remove double-click detection and tooltips for simplicity - Remove platform-specific behavior (same UX for Electron and web) - Optimize button layout: reduce from 36px to 28px to fit 3 buttons - Position expand button above history buttons in vertical stack - Keep 15-line expanded height (360px, capped to available space) Per upstream dev feedback to keep it simple with one approach
This commit is contained in:
@@ -1,109 +1,29 @@
|
||||
import { createSignal, Show } from "solid-js"
|
||||
import { Show } from "solid-js"
|
||||
import { Maximize2, Minimize2 } from "lucide-solid"
|
||||
import { isElectronHost } from "../lib/runtime-env"
|
||||
|
||||
interface ExpandButtonProps {
|
||||
expandState: () => "normal" | "fifty" | "eighty" | "expanded"
|
||||
onToggleExpand: (nextState: "normal" | "fifty" | "eighty" | "expanded") => void
|
||||
expandState: () => "normal" | "expanded"
|
||||
onToggleExpand: (nextState: "normal" | "expanded") => void
|
||||
}
|
||||
|
||||
export default function ExpandButton(props: ExpandButtonProps) {
|
||||
const [clickTime, setClickTime] = createSignal<number>(0)
|
||||
const [clickTimer, setClickTimer] = createSignal<number | null>(null)
|
||||
const DOUBLE_CLICK_THRESHOLD = 300
|
||||
|
||||
// Check if we're in Electron (desktop app with 3-state support)
|
||||
const isDesktopApp = isElectronHost()
|
||||
|
||||
function handleClick() {
|
||||
const current = props.expandState()
|
||||
|
||||
if (!isDesktopApp) {
|
||||
// Web/Mobile: Simple 2-state toggle (instant, no delay)
|
||||
if (current === "normal") {
|
||||
props.onToggleExpand("expanded")
|
||||
} else {
|
||||
props.onToggleExpand("normal")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Electron: 3-state with double-click detection
|
||||
const now = Date.now()
|
||||
const lastClick = clickTime()
|
||||
const isDoubleClick = now - lastClick < DOUBLE_CLICK_THRESHOLD
|
||||
|
||||
// Clear any pending single-click timer
|
||||
const timer = clickTimer()
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer)
|
||||
setClickTimer(null)
|
||||
}
|
||||
|
||||
if (isDoubleClick) {
|
||||
// Double click behavior - execute immediately
|
||||
if (current === "normal") {
|
||||
props.onToggleExpand("eighty")
|
||||
} else if (current === "fifty") {
|
||||
props.onToggleExpand("eighty")
|
||||
} else {
|
||||
props.onToggleExpand("fifty")
|
||||
}
|
||||
// Reset click time to prevent triple-click issues
|
||||
setClickTime(0)
|
||||
} else {
|
||||
// Single click behavior - delay to wait for potential double-click
|
||||
setClickTime(now)
|
||||
|
||||
const newTimer = window.setTimeout(() => {
|
||||
const currentState = props.expandState()
|
||||
if (currentState === "normal") {
|
||||
props.onToggleExpand("fifty")
|
||||
} else {
|
||||
props.onToggleExpand("normal")
|
||||
}
|
||||
setClickTimer(null)
|
||||
}, DOUBLE_CLICK_THRESHOLD)
|
||||
|
||||
setClickTimer(newTimer)
|
||||
}
|
||||
}
|
||||
|
||||
const getTooltip = () => {
|
||||
// No tooltip for web/mobile - only Electron gets tooltips
|
||||
if (!isDesktopApp) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const current = props.expandState()
|
||||
if (current === "normal") {
|
||||
return "Click to expand (50%) • Double-click to expand further (80%)"
|
||||
} else if (current === "fifty") {
|
||||
return "Double-click to expand to 80% • Click to minimize"
|
||||
} else {
|
||||
return "Click to minimize • Double-click to reduce to 50%"
|
||||
}
|
||||
}
|
||||
|
||||
const isExpanded = () => {
|
||||
const state = props.expandState()
|
||||
return state !== "normal"
|
||||
props.onToggleExpand(current === "normal" ? "expanded" : "normal")
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
class={`prompt-expand-button ${isDesktopApp ? "desktop-mode" : "web-mode"}`}
|
||||
class="prompt-expand-button"
|
||||
onClick={handleClick}
|
||||
disabled={false}
|
||||
aria-label="Toggle chat input height"
|
||||
data-tooltip={getTooltip()}
|
||||
>
|
||||
<Show
|
||||
when={!isExpanded()}
|
||||
fallback={<Minimize2 class="h-5 w-5" aria-hidden="true" />}
|
||||
when={props.expandState() === "normal"}
|
||||
fallback={<Minimize2 class="h-4 w-4" aria-hidden="true" />}
|
||||
>
|
||||
<Maximize2 class="h-5 w-5" aria-hidden="true" />
|
||||
<Maximize2 class="h-4 w-4" aria-hidden="true" />
|
||||
</Show>
|
||||
</button>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user