GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): PDFs in the desktop file panel can be saved again (#38749) · HNRow/r3code@e48d6f3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/files
    • BrowserDocumentFrame.tsx
    • FilePreviewPanel.tsx
    • PdfViewer.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/files/BrowserDocumentFrame.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/BrowserDocumentFrame.tsx
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "@t3tools/shared/keybindings";
2929
import {
3030
lazy,
31+
type ReactNode,
3132
Suspense,
3233
useEffect,
3334
useEffectEvent,
@@ -79,7 +80,12 @@ export const isPdfPreviewFile = (path: string): boolean =>
7980
const PdfViewer = lazy(() => import("./PdfViewer"));
8081

8182
// The document stays mounted while each revision gets a fresh PDF.js document.
82-
function PdfDocument(props: { src: string; title: string; documentKey: string }) {
83+
function PdfDocument(props: {
84+
src: string;
85+
title: string;
86+
documentKey: string;
87+
actions?: ReactNode;
88+
}) {
8389
const [view, setView] = useState<PdfViewState>({ page: 0, offset: 0, zoom: null, left: 0 });
8490
return (
8591
<PdfDocumentRevision
@@ -89,6 +95,7 @@ function PdfDocument(props: { src: string; title: string; documentKey: string })
8995
positionKey={props.documentKey}
9096
initialView={view}
9197
onViewChange={setView}
98+
actions={props.actions}
9299
/>
93100
);
94101
}
@@ -100,6 +107,7 @@ function PdfDocumentRevision(props: {
100107
positionKey: string;
101108
initialView: PdfViewState;
102109
onViewChange: (view: PdfViewState) => void;
110+
actions?: ReactNode;
103111
}) {
104112
const [src] = useState(props.src);
105113
// The Electron shell does not enable PDF plugins. WebKit embeds on iOS
@@ -124,6 +132,7 @@ function PdfDocumentRevision(props: {
124132
positionKey={props.positionKey}
125133
initialView={props.initialView}
126134
onViewChange={props.onViewChange}
135+
actions={props.actions}
127136
/>
128137
</Suspense>
129138
);
@@ -143,6 +152,8 @@ export function BrowserDocumentFrame(props: {
143152
readonly documentKey?: string | undefined;
144153
/** Resource identity without its revision, so PDF reloads can retain the reading position. */
145154
readonly documentId?: string | undefined;
155+
/** Toolbar actions for the in-app PDF viewer; Chromium's own viewer brings its own. */
156+
readonly pdfActions?: ReactNode;
146157
}) {
147158
const key = props.documentKey ?? props.src;
148159
return props.pdf ? (
@@ -151,6 +162,7 @@ export function BrowserDocumentFrame(props: {
151162
documentKey={key}
152163
src={props.src}
153164
title={props.title}
165+
actions={props.pdfActions}
154166
/>
155167
) : props.htmlRender ? (
156168
<HtmlRenderDocument
Collapse file

‎apps/web/src/components/files/FilePreviewPanel.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.tsx
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { m, type MessageResolver } from "~/i18n/messages";
55
import { namedClipboardTarget, useCopyToClipboard } from "~/hooks/useCopyToClipboard";
66
import { Spinner } from "~/components/ui/spinner";
77
import {
8+
type AssetResource,
89
AuthPreviewOperateScope,
910
type EditorId,
1011
type EnvironmentId,
@@ -296,10 +297,59 @@ export function WorkspaceBrowserPreview(props: {
296297
documentId={`${props.environmentId}:${resource._tag}:${props.threadRef.threadId}:${props.absolutePath}`}
297298
title={props.title}
298299
pdf={pdf}
300+
pdfActions={
301+
<WorkspacePdfSaveAction
302+
environmentId={props.environmentId}
303+
resource={resource}
304+
name={props.title}
305+
/>
306+
}
299307
/>
300308
);
301309
}
302310

311+
function WorkspacePdfSaveAction(props: {
312+
readonly environmentId: EnvironmentId;
313+
readonly resource: AssetResource;
314+
readonly name: string;
315+
}) {
316+
const gt = useGT();
317+
const [saving, setSaving] = useState(false);
318+
const refreshAssetUrl = useAssetUrlRefresh(props.environmentId, props.resource);
319+
return (
320+
<FileSurfaceAction
321+
label={saving ? gt("Preparing file…") : gt("Save file")}
322+
disabled={saving}
323+
onPress={() => {
324+
setSaving(true);
325+
void (async () => {
326+
const url = await refreshAssetUrl();
327+
if (!url) throw new Error(gt("Reconnect to the environment and try again."));
328+
const response = await fetch(url);
329+
if (!response.ok) throw new Error(gt("The file could not be loaded. Try again."));
330+
// Blob downloads keep desktop's custom app scheme from navigating to an external browser.
331+
const downloadUrl = URL.createObjectURL(await response.blob());
332+
setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);
333+
const anchor = document.createElement("a");
334+
anchor.href = downloadUrl;
335+
anchor.download = props.name.split(/[\\/]/).at(-1) || props.name;
336+
anchor.click();
337+
})()
338+
.catch((cause: unknown) =>
339+
toastManager.add({
340+
type: "error",
341+
title: gt("Could not save file"),
342+
description: thrownErrorMessage(cause, m) ?? gt("Please try again."),
343+
}),
344+
)
345+
.finally(() => setSaving(false));
346+
}}
347+
>
348+
<DownloadIcon className="size-3.5" />
349+
</FileSurfaceAction>
350+
);
351+
}
352+
303353
function WorkspaceVideoPreview(props: {
304354
readonly environmentId: EnvironmentId;
305355
readonly threadRef: ScopedThreadRef;
Collapse file

‎apps/web/src/components/files/PdfViewer.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/PdfViewer.tsx
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useRef,
77
useState,
88
type CSSProperties,
9+
type ReactNode,
910
} from "react";
1011
import { TextLayer, type PDFDocumentProxy } from "pdfjs-dist";
1112
import { msg, useGT } from "gt-react";
@@ -144,6 +145,7 @@ export default function PdfViewer(props: {
144145
positionKey?: string;
145146
initialView?: PdfViewState;
146147
onViewChange?: (view: PdfViewState) => void;
148+
actions?: ReactNode;
147149
}) {
148150
const gt = useGT();
149151
const [savedPosition] = useState(() =>
@@ -448,6 +450,7 @@ export default function PdfViewer(props: {
448450
</FileSurfaceAction>
449451
</>
450452
) : null}
453+
{props.actions}
451454
</div>
452455
<div
453456
ref={scroll}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.