mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 11:49:39 +08:00
Ship folder-based workspaces and data migration, daily practice, redesigned provider and model settings, and streaming conversation improvements. Synchronize README translations and document the archive/permanent-delete upgrade behavior in assets/releases/ver1-6-9.md. Reduce initial JavaScript by deduplicating English resources and loading animation features after hydration. Keep the existing route size budgets. Update regression fixtures and browser audits for scoped URLs and the new settings and learning interfaces.
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import {
|
|
useCallback,
|
|
useEffect,
|
|
useRef,
|
|
useState,
|
|
type FocusEvent,
|
|
} from "react";
|
|
|
|
/**
|
|
* Expansion state for the collapse-to-icon toolbar selectors (persona /
|
|
* model). Expands on hover, focus or while the menu is open; on leave or
|
|
* close it LINGERS for ~1.2s before collapsing, so the user can read the
|
|
* (possibly just-changed) selection instead of having it snap shut.
|
|
*
|
|
* ``pinned`` opts out of collapsing altogether: on the composer rail the
|
|
* chips sit outside the input card, where width is no longer scarce, so the
|
|
* selection stays readable without a hover. The collapsing behaviour is kept
|
|
* for the surfaces that still host these selectors inside a cramped row.
|
|
*/
|
|
export function useLingerExpand(
|
|
open: boolean,
|
|
lingerMs = 1200,
|
|
pinned = false,
|
|
) {
|
|
const [hovered, setHovered] = useState(false);
|
|
const [keyboardFocused, setKeyboardFocused] = useState(false);
|
|
const [lingering, setLingering] = useState(false);
|
|
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
|
|
const clearTimer = useCallback(() => {
|
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
timerRef.current = null;
|
|
}, []);
|
|
|
|
/**
|
|
* Hold the expanded state for ``lingerMs`` before collapsing. Fired by
|
|
* mouse-leave automatically; menu owners should also call it wherever
|
|
* they close the menu (selection / outside click) so the just-changed
|
|
* label stays readable for a beat.
|
|
*/
|
|
const linger = useCallback(() => {
|
|
clearTimer();
|
|
setLingering(true);
|
|
timerRef.current = setTimeout(() => setLingering(false), lingerMs);
|
|
}, [clearTimer, lingerMs]);
|
|
|
|
useEffect(() => clearTimer, [clearTimer]);
|
|
|
|
const onMouseEnter = useCallback(() => {
|
|
clearTimer();
|
|
setLingering(false);
|
|
setHovered(true);
|
|
}, [clearTimer]);
|
|
|
|
const onMouseLeave = useCallback(() => {
|
|
setHovered(false);
|
|
linger();
|
|
}, [linger]);
|
|
|
|
return {
|
|
expanded: pinned || hovered || keyboardFocused || open || lingering,
|
|
linger,
|
|
triggerProps: {
|
|
onMouseEnter,
|
|
onMouseLeave,
|
|
onFocus: (event: FocusEvent<HTMLElement>) => {
|
|
setKeyboardFocused(event.currentTarget.matches(":focus-visible"));
|
|
},
|
|
onBlur: () => {
|
|
setKeyboardFocused(false);
|
|
linger();
|
|
},
|
|
},
|
|
};
|
|
}
|