Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7893cc984c |
No files matched your search
@@ -24,7 +24,6 @@ interface Props {
|
||||
url: string;
|
||||
displayUrl?: string | undefined;
|
||||
loading: boolean;
|
||||
loadProgress: number;
|
||||
canGoBack: boolean;
|
||||
canGoForward: boolean;
|
||||
refreshDisabled: boolean;
|
||||
@@ -59,11 +58,33 @@ interface Props {
|
||||
|
||||
const NOOP = () => {};
|
||||
|
||||
function useFocusPreviewUrlInput(
|
||||
inputRef: React.RefObject<HTMLInputElement | null>,
|
||||
focusUrlNonce: number | undefined,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
if (focusUrlNonce == null) return;
|
||||
inputRef.current?.focus();
|
||||
}, [focusUrlNonce, inputRef]);
|
||||
}
|
||||
|
||||
function PreviewLoadingProgress({ loading }: { loading: boolean }) {
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none absolute bottom-0 left-0 z-10 h-0.5 w-full origin-left rounded-r-full bg-primary",
|
||||
loading ? "preview-loading-progress-active" : "preview-loading-progress-idle",
|
||||
)}
|
||||
style={{ boxShadow: "0 0 6px 1px var(--color-ring)" }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function PreviewChromeRow({
|
||||
url,
|
||||
displayUrl,
|
||||
loading,
|
||||
loadProgress,
|
||||
canGoBack,
|
||||
canGoForward,
|
||||
refreshDisabled,
|
||||
@@ -86,13 +107,7 @@ export function PreviewChromeRow({
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [draft, setDraft] = useState(url);
|
||||
const [inputFocused, setInputFocused] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (focusUrlNonce == null) return;
|
||||
const node = inputRef.current;
|
||||
if (!node) return;
|
||||
node.focus();
|
||||
}, [focusUrlNonce]);
|
||||
useFocusPreviewUrlInput(inputRef, focusUrlNonce);
|
||||
|
||||
const submit = (event?: FormEvent | KeyboardEvent) => {
|
||||
event?.preventDefault();
|
||||
@@ -276,16 +291,7 @@ export function PreviewChromeRow({
|
||||
) : null}
|
||||
{trailingActions}
|
||||
</form>
|
||||
{loadProgress > 0 ? (
|
||||
<div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute bottom-0 left-0 z-10 h-0.5 rounded-r-full bg-primary transition-all duration-150 ease-out"
|
||||
style={{
|
||||
width: `${loadProgress}%`,
|
||||
boxShadow: "0 0 6px 1px var(--color-ring)",
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<PreviewLoadingProgress loading={loading} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -39,7 +39,6 @@ import { revealInFileExplorerLabel } from "./fileExplorerLabel";
|
||||
import { shouldShowPreviewEmptyState } from "./previewEmptyStateLogic";
|
||||
import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
|
||||
import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore";
|
||||
import { useLoadingProgress } from "./useLoadingProgress";
|
||||
import { usePreviewSession } from "./usePreviewSession";
|
||||
import { ZoomIndicator } from "./ZoomIndicator";
|
||||
import { AgentBrowserCursor } from "./AgentBrowserCursor";
|
||||
@@ -98,7 +97,6 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls,
|
||||
const isUnreachable = navStatus._tag === "LoadFailed";
|
||||
const showEmptyState = shouldShowPreviewEmptyState(snapshot);
|
||||
const controller = desktopOverlay?.controller ?? "none";
|
||||
const loadProgress = useLoadingProgress(loading);
|
||||
const displayUrl =
|
||||
url && environment && environmentHttpBaseUrl
|
||||
? (formatPreviewUrl({
|
||||
@@ -564,7 +562,6 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls,
|
||||
url={url}
|
||||
displayUrl={displayUrl}
|
||||
loading={loading}
|
||||
loadProgress={loadProgress}
|
||||
canGoBack={canGoBack}
|
||||
canGoForward={canGoForward}
|
||||
refreshDisabled={refreshDisabled}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
const TICK_INTERVAL_MS = 120;
|
||||
const FADE_OUT_DELAY_MS = 220;
|
||||
const SEED_PERCENT = 4;
|
||||
const ASYMPTOTE_PERCENT = 90;
|
||||
const APPROACH_FACTOR = 0.08;
|
||||
const MIN_INCREMENT = 0.5;
|
||||
|
||||
/**
|
||||
* Indeterminate progress simulator for the preview chrome's loading bar.
|
||||
* Animates 0 → 90% asymptotically while `loading` is true, snaps to 100%
|
||||
* on release, then resets after a short pause.
|
||||
*
|
||||
* Uses a ref to thread the latest progress through interval ticks without
|
||||
* needing `loading` to retrigger the effect, which sidesteps the stale-
|
||||
* closure pitfalls of reading `progress` directly.
|
||||
*/
|
||||
export function useLoadingProgress(loading: boolean): number {
|
||||
const [progress, setProgress] = useState(0);
|
||||
const progressRef = useRef(0);
|
||||
progressRef.current = progress;
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
if (progressRef.current === 0) return;
|
||||
setProgress(100);
|
||||
const timer = window.setTimeout(() => setProgress(0), FADE_OUT_DELAY_MS);
|
||||
return () => window.clearTimeout(timer);
|
||||
}
|
||||
|
||||
setProgress((value) => (value > 0 && value < 95 ? value : SEED_PERCENT));
|
||||
const interval = window.setInterval(() => {
|
||||
const current = progressRef.current;
|
||||
if (current >= ASYMPTOTE_PERCENT) return;
|
||||
const remaining = ASYMPTOTE_PERCENT - current;
|
||||
const increment = Math.max(MIN_INCREMENT, remaining * APPROACH_FACTOR);
|
||||
setProgress(Math.min(ASYMPTOTE_PERCENT, current + increment));
|
||||
}, TICK_INTERVAL_MS);
|
||||
|
||||
return () => window.clearInterval(interval);
|
||||
}, [loading]);
|
||||
|
||||
return progress;
|
||||
}
|
||||
@@ -891,3 +891,33 @@ label:has(> select#reasoning-effort) select {
|
||||
.dark .model-picker-list::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
@keyframes preview-loading-progress {
|
||||
from {
|
||||
transform: scaleX(0.04);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: scaleX(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
.preview-loading-progress-active {
|
||||
opacity: 1;
|
||||
animation: preview-loading-progress 10s cubic-bezier(0.1, 0.5, 0.2, 1) forwards;
|
||||
}
|
||||
|
||||
.preview-loading-progress-idle {
|
||||
opacity: 0;
|
||||
transform: scaleX(1);
|
||||
transition:
|
||||
transform 150ms ease-out,
|
||||
opacity 150ms ease-out 220ms;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.preview-loading-progress-active {
|
||||
transform: scaleX(0.9);
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user