fix(webui): preserve previews during credential renewal
This commit is contained in:
1 parent
b555164a17
commit
c2edd5632e
8 files changed
+89
-11
No files matched your search
@@ -35,13 +35,17 @@ export function FilePreviewPanel({
|
||||
// Cache aging must not restart an already open preview on unrelated rerenders.
|
||||
const initialPreviewRef = useRef(initialPreview);
|
||||
initialPreviewRef.current = initialPreview;
|
||||
// Credential renewal is not a new file selection. Read the current token only
|
||||
// when a session/path/loader change actually starts another request.
|
||||
const tokenRef = useRef(token);
|
||||
tokenRef.current = token;
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setImageOpen(false);
|
||||
const cached = initialPreviewRef.current;
|
||||
setState(cached ? { status: "ready", payload: cached } : { status: "loading" });
|
||||
(loadPreview?.(path) ?? fetchFilePreview(token, sessionKey, path))
|
||||
(loadPreview?.(path) ?? fetchFilePreview(tokenRef.current, sessionKey, path))
|
||||
.then((payload) => {
|
||||
if (!cancelled) setState({ status: "ready", payload });
|
||||
})
|
||||
@@ -51,7 +55,7 @@ export function FilePreviewPanel({
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [path, sessionKey, token, loadPreview]);
|
||||
}, [path, sessionKey, loadPreview]);
|
||||
|
||||
const displayPath = state.status === "ready" ? state.payload.display_path : path;
|
||||
const { name } = splitFilePath(displayPath);
|
||||
|
||||
@@ -453,6 +453,7 @@ function InlineLinkPreviewRow({ link }: { link: InlineLinkPreview }) {
|
||||
|
||||
return (
|
||||
<WebLink
|
||||
layout="row"
|
||||
href={link.href}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
|
||||
@@ -5,10 +5,11 @@ import { useTranslation } from "react-i18next";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { parseWebLink } from "@/lib/web-preview";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const WebPreviewContext = createContext<((url: string) => void) | undefined>(undefined);
|
||||
|
||||
export function WebLink({ href = "", children, ...props }: ComponentPropsWithoutRef<"a">) {
|
||||
export function WebLink({ href = "", children, layout = "inline", className, ...props }: ComponentPropsWithoutRef<"a"> & { layout?: "inline" | "row" }) {
|
||||
const { t } = useTranslation();
|
||||
const openPreview = useContext(WebPreviewContext);
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -19,7 +20,7 @@ export function WebLink({ href = "", children, ...props }: ComponentPropsWithout
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [feedback]);
|
||||
const url = parseWebLink(href);
|
||||
const anchor = <a {...props} href={href} target="_blank" rel="noreferrer noopener">{children}</a>;
|
||||
const anchor = <a {...props} className={cn(className, layout === "row" && "min-w-0 flex-1")} href={href} target="_blank" rel="noreferrer noopener">{children}</a>;
|
||||
if (!url) {
|
||||
// Keep the renderer's relative media/document and mail links unchanged.
|
||||
const relative = !/^[a-z][a-z\d+.-]*:/i.test(href)
|
||||
@@ -28,7 +29,7 @@ export function WebLink({ href = "", children, ...props }: ComponentPropsWithout
|
||||
}
|
||||
return (
|
||||
<DropdownMenu open={open} onOpenChange={setOpen}>
|
||||
<span className="inline max-w-full" onContextMenu={(event) => {
|
||||
<span className={cn("max-w-full", layout === "row" ? "inline-flex w-full min-w-0 items-center" : "inline")} onContextMenu={(event) => {
|
||||
event.preventDefault(); event.stopPropagation(); setOpen(true);
|
||||
}} onKeyDown={(event) => {
|
||||
if ((event.shiftKey && event.key === "F10") || event.key === "ContextMenu") {
|
||||
@@ -38,7 +39,7 @@ export function WebLink({ href = "", children, ...props }: ComponentPropsWithout
|
||||
{anchor}
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button type="button" aria-label={t("webPreview.actions")} title={t("webPreview.actions")}
|
||||
className="ml-0.5 inline-flex h-6 w-6 items-center justify-center rounded-md align-middle text-muted-foreground/70 hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
className="ml-0.5 inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md align-middle text-muted-foreground/70 hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<MoreHorizontal className="h-3.5 w-3.5" aria-hidden />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
@@ -1556,7 +1556,7 @@ export function ThreadShell({
|
||||
if (!previewSessionKey) return Promise.reject(new Error("No active session"));
|
||||
return temporary ? loadTemporaryFilePreview(path) : fetchFilePreview(getToken(), previewSessionKey, path);
|
||||
}, [previewSessionKey, temporary, loadTemporaryFilePreview, getToken]);
|
||||
const filePreviews = useMemo(() => createFilePreviewResource(loadFilePreview), [loadFilePreview, token]);
|
||||
const filePreviews = useMemo(() => createFilePreviewResource(loadFilePreview), [loadFilePreview]);
|
||||
const fileActions = useMemo(() => ({
|
||||
resolveMetadata: resolveFileMetadata,
|
||||
loadPreview: filePreviews.load,
|
||||
|
||||
Reference in new issue
Block a user