fix(webui): reuse preview tabs for resolved file aliases
This commit is contained in:
1 parent
0869c928a2
commit
61666c495a
5 files changed
+95
-4
No files matched your search
@@ -10,6 +10,7 @@ interface FilePreviewPanelProps {
|
||||
loadPreview?: (path: string) => Promise<FilePreviewPayload>;
|
||||
initialPreview?: FilePreviewPayload;
|
||||
onOpenFilePreview?: (path: string) => void;
|
||||
onResolvePath?: (path: string, canonicalPath: string) => void;
|
||||
}
|
||||
|
||||
export function FilePreviewPanel({
|
||||
@@ -19,6 +20,7 @@ export function FilePreviewPanel({
|
||||
loadPreview,
|
||||
initialPreview,
|
||||
onOpenFilePreview,
|
||||
onResolvePath,
|
||||
}: FilePreviewPanelProps) {
|
||||
const [state, setState] = useState<FilePreviewPanelState>(() => initialPreview
|
||||
? { status: "ready", payload: initialPreview } : { status: "loading" });
|
||||
@@ -30,6 +32,8 @@ export function FilePreviewPanel({
|
||||
// when a session/path/loader change actually starts another request.
|
||||
const tokenRef = useRef(token);
|
||||
tokenRef.current = token;
|
||||
const onResolvePathRef = useRef(onResolvePath);
|
||||
onResolvePathRef.current = onResolvePath;
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
@@ -40,8 +44,10 @@ export function FilePreviewPanel({
|
||||
: (previous.status === "loading" ? previous : { status: "loading" }));
|
||||
(loadPreview?.(path) ?? fetchFilePreview(tokenRef.current, sessionKey, path))
|
||||
.then((payload) => {
|
||||
if (!cancelled) setState(previous => previous.status === "ready" && previous.payload === payload
|
||||
if (cancelled) return;
|
||||
setState(previous => previous.status === "ready" && previous.payload === payload
|
||||
? previous : { status: "ready", payload });
|
||||
onResolvePathRef.current?.(path, payload.path);
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
if (!cancelled) setState({ status: "error",
|
||||
|
||||
Reference in new issue
Block a user