fix(webui): hide exhausted history hints at rest
Refs NAN-300
This commit is contained in:
1 parent
e44ebb164d
commit
f80956966b
5 files changed
+145
-28
No files matched your search
@@ -301,6 +301,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
const composerDockHeightRef = useRef(0);
|
||||
const [atBottom, setAtBottom] = useState(true);
|
||||
const [atHistoryTop, setAtHistoryTop] = useState(false);
|
||||
const [historyFeedbackActive, setHistoryFeedbackActive] = useState(false);
|
||||
const historyInputRef = useRef<"touch" | "other">("other");
|
||||
const historyTouchRef = useRef<{
|
||||
lastY: number; startX: number; startY: number; pulling: boolean; horizontal: boolean;
|
||||
@@ -310,6 +311,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
const historySpringRef = useRef<ThreadHistorySpring | null>(null);
|
||||
if (historySpringRef.current === null) {
|
||||
historySpringRef.current = new ThreadHistorySpring({
|
||||
onFeedbackChange: setHistoryFeedbackActive,
|
||||
onUpdate: (distance) => {
|
||||
// Presentation travel never becomes a scrollTop destination or an anchor correction.
|
||||
historyDistanceRef.current = distance;
|
||||
@@ -396,6 +398,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
[messages, visibleMessageCount],
|
||||
);
|
||||
const hiddenMessageCount = messages.length - visibleMessages.length;
|
||||
const historyExhausted = !hasMoreBefore && hiddenMessageCount === 0;
|
||||
const hiddenUserMessageCount =
|
||||
userMessageOffset
|
||||
+ (hiddenMessageCount > 0
|
||||
@@ -1156,11 +1159,11 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
</div>
|
||||
{navigation && (navigation.loading || navigation.error) ? (
|
||||
<ThreadHistoryStatus ref={setHistoryStatus} loading={navigation.loading} error={navigation.error} onRetry={navigation.retry} />
|
||||
) : messages.length > 0 && conversationReady && (atHistoryTop || loadingOlder || olderError) ? (
|
||||
) : messages.length > 0 && conversationReady && ((atHistoryTop && (!historyExhausted || historyFeedbackActive)) || loadingOlder || olderError) ? (
|
||||
<ThreadHistoryStatus
|
||||
ref={setHistoryStatus}
|
||||
loading={loadingOlder}
|
||||
exhausted={!hasMoreBefore && hiddenMessageCount === 0}
|
||||
exhausted={historyExhausted}
|
||||
error={olderError}
|
||||
onRetry={loadEarlierMessages}
|
||||
/>
|
||||
|
||||
@@ -9,6 +9,7 @@ const DAMPING_RATIO = 0.78;
|
||||
|
||||
interface HistorySpringOptions {
|
||||
onUpdate: (distance: number) => void;
|
||||
onFeedbackChange: (active: boolean) => void;
|
||||
scheduler?: ThreadCameraScheduler;
|
||||
prefersReducedMotion?: () => boolean;
|
||||
}
|
||||
@@ -26,6 +27,7 @@ export class ThreadHistorySpring {
|
||||
private dragging = false;
|
||||
private travel = 0;
|
||||
private wheelLatched = false;
|
||||
private feedbackActive = false;
|
||||
|
||||
constructor(options: HistorySpringOptions) {
|
||||
this.options = options;
|
||||
@@ -49,6 +51,7 @@ export class ThreadHistorySpring {
|
||||
if (this.dragging) return false;
|
||||
const first = !this.wheelLatched && travel > 0;
|
||||
this.wheelLatched = true;
|
||||
if (travel > 0) this.setFeedbackActive(true);
|
||||
// Wheel packets add pressure to one live spring, without a position jump.
|
||||
const speed = FREQUENCY * (travel > 0
|
||||
? HISTORY_PULL_LIMIT_PX - Math.max(0, this.distance)
|
||||
@@ -61,6 +64,7 @@ export class ThreadHistorySpring {
|
||||
startTouch(): void {
|
||||
this.stopFrame();
|
||||
this.dragging = true;
|
||||
this.setFeedbackActive(true);
|
||||
this.velocity = 0;
|
||||
this.travel = -RESISTANCE_LENGTH_PX
|
||||
* Math.log(Math.max(Number.EPSILON, 1 - Math.max(0, this.distance) / HISTORY_PULL_LIMIT_PX));
|
||||
@@ -85,6 +89,7 @@ export class ThreadHistorySpring {
|
||||
this.loading = false;
|
||||
this.dragging = false;
|
||||
this.wheelLatched = false;
|
||||
this.setFeedbackActive(false);
|
||||
this.animate();
|
||||
}
|
||||
|
||||
@@ -96,10 +101,18 @@ export class ThreadHistorySpring {
|
||||
this.loading = false;
|
||||
this.dragging = false;
|
||||
this.wheelLatched = false;
|
||||
this.setFeedbackActive(false);
|
||||
this.publish();
|
||||
}
|
||||
|
||||
private setFeedbackActive(active: boolean): void {
|
||||
if (this.feedbackActive === active) return;
|
||||
this.feedbackActive = active;
|
||||
this.options.onFeedbackChange(active);
|
||||
}
|
||||
|
||||
private publish(): void {
|
||||
// Reduced motion suppresses travel, not the input/settlement lifecycle.
|
||||
this.options.onUpdate(this.reducedMotion() ? 0 : Math.max(0, this.distance));
|
||||
}
|
||||
|
||||
@@ -110,16 +123,12 @@ export class ThreadHistorySpring {
|
||||
}
|
||||
|
||||
private animate(): void {
|
||||
if (this.reducedMotion()) {
|
||||
this.distance = 0;
|
||||
this.velocity = 0;
|
||||
this.stopFrame();
|
||||
this.publish();
|
||||
return;
|
||||
}
|
||||
if (this.frame !== null) return;
|
||||
if (this.distance === (this.loading ? LOADING_POCKET_PX : 0) && this.velocity === 0) {
|
||||
if (!this.loading) this.wheelLatched = false;
|
||||
if (!this.loading) {
|
||||
this.wheelLatched = false;
|
||||
this.setFeedbackActive(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.timestamp = this.scheduler.now();
|
||||
@@ -128,13 +137,6 @@ export class ThreadHistorySpring {
|
||||
|
||||
private readonly advance = (timestamp: number): void => {
|
||||
this.frame = null;
|
||||
if (this.reducedMotion()) {
|
||||
this.distance = 0;
|
||||
this.velocity = 0;
|
||||
this.timestamp = null;
|
||||
this.publish();
|
||||
return;
|
||||
}
|
||||
const seconds = Math.max(0, timestamp - (this.timestamp ?? timestamp)) / 1000;
|
||||
this.timestamp = timestamp;
|
||||
const target = this.loading ? LOADING_POCKET_PX : 0;
|
||||
@@ -155,7 +157,10 @@ export class ThreadHistorySpring {
|
||||
this.distance = target;
|
||||
this.velocity = 0;
|
||||
this.timestamp = null;
|
||||
if (!this.loading) this.wheelLatched = false;
|
||||
if (!this.loading) {
|
||||
this.wheelLatched = false;
|
||||
this.setFeedbackActive(false);
|
||||
}
|
||||
}
|
||||
this.publish();
|
||||
if (!settled) this.frame = this.scheduler.request(this.advance);
|
||||
|
||||
@@ -11,8 +11,9 @@ function harness(reduced = false) {
|
||||
request: vi.fn((callback: FrameRequestCallback) => { frames.set(++nextId, callback); return nextId; }),
|
||||
cancel: (id: number) => { frames.delete(id); },
|
||||
};
|
||||
const feedback = vi.fn();
|
||||
const spring = new ThreadHistorySpring({ scheduler, prefersReducedMotion: () => reduced,
|
||||
onUpdate: (next) => { distance = next; } });
|
||||
onFeedbackChange: feedback, onUpdate: (next) => { distance = next; } });
|
||||
const advance = (milliseconds = 16) => {
|
||||
now += milliseconds;
|
||||
const callbacks = [...frames.values()];
|
||||
@@ -21,7 +22,7 @@ function harness(reduced = false) {
|
||||
return distance;
|
||||
};
|
||||
const settle = () => { for (let i = 0; i < 100 && frames.size; i++) advance(); };
|
||||
return { spring, scheduler, advance, settle, frames, distance: () => distance };
|
||||
return { spring, scheduler, advance, settle, frames, feedback, distance: () => distance };
|
||||
}
|
||||
|
||||
describe("history boundary spring", () => {
|
||||
@@ -70,9 +71,11 @@ describe("history boundary spring", () => {
|
||||
h.advance();
|
||||
}
|
||||
expect(requests).toBe(1);
|
||||
expect(h.feedback.mock.calls).toEqual([[true]]);
|
||||
expect(h.distance()).toBeLessThan(HISTORY_PULL_LIMIT_PX);
|
||||
h.settle();
|
||||
expect(h.distance()).toBe(0);
|
||||
expect(h.feedback.mock.calls).toEqual([[true], [false]]);
|
||||
expect(h.spring.wheel(100)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -93,7 +96,16 @@ describe("history boundary spring", () => {
|
||||
expect(h.distance()).toBe(0);
|
||||
expect(h.spring.endTouch()).toBe(true);
|
||||
h.spring.setLoading(true);
|
||||
expect(h.frames.size).toBe(0);
|
||||
expect(h.distance()).toBe(0);
|
||||
h.settle();
|
||||
expect(h.frames.size).toBe(0);
|
||||
h.spring.setLoading(false);
|
||||
h.settle();
|
||||
expect(h.feedback.mock.calls).toEqual([[true], [false]]);
|
||||
h.spring.wheel(100);
|
||||
expect(h.feedback).toHaveBeenLastCalledWith(true);
|
||||
h.settle();
|
||||
expect(h.distance()).toBe(0);
|
||||
expect(h.feedback).toHaveBeenLastCalledWith(false);
|
||||
});
|
||||
});
|
||||
@@ -1857,14 +1857,24 @@ describe("ThreadViewport", () => {
|
||||
expect(onRender).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows the confirmed start of conversation with boundary feedback", async () => {
|
||||
it("shows the confirmed start only during boundary feedback and clears it on conversation changes", async () => {
|
||||
const onLoadOlder = vi.fn();
|
||||
const { container } = render(<ThreadViewport messages={messages} isStreaming={false}
|
||||
onLoadOlder={onLoadOlder} />);
|
||||
fireEvent.wheel(getScroller(container), { deltaY: -100 });
|
||||
const props = { messages, isStreaming: false, onLoadOlder };
|
||||
const { container, rerender } = render(<ThreadViewport {...props} conversationKey="a" />);
|
||||
const scroller = getScroller(container);
|
||||
expect(screen.queryByText("No earlier messages")).not.toBeInTheDocument();
|
||||
fireEvent.wheel(scroller, { deltaY: -100 });
|
||||
expect(screen.getByText("hello")).toBeVisible();
|
||||
expect(screen.getByText("No earlier messages")).toBeVisible();
|
||||
await waitFor(() => expect(historyPull(getScroller(container))).toBeGreaterThan(0));
|
||||
await waitFor(() => expect(historyPull(scroller)).toBeGreaterThan(0));
|
||||
await waitFor(() => expect(screen.queryByText("No earlier messages")).not.toBeInTheDocument());
|
||||
expect(historyPull(scroller)).toBe(0);
|
||||
expect(scroller.scrollTop).toBe(0);
|
||||
fireEvent.wheel(scroller, { deltaY: -100 });
|
||||
expect(screen.getByText("No earlier messages")).toBeVisible();
|
||||
rerender(<ThreadViewport {...props} conversationKey="b" />);
|
||||
expect(screen.queryByText("No earlier messages")).not.toBeInTheDocument();
|
||||
expect(historyPull(scroller)).toBe(0);
|
||||
expect(onLoadOlder).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user