Skip to content

Commit 706d5b9

Browse files
committed
feat: enhance PDF viewer and report panel with public access handling and UI updates
1 parent e2cd055 commit 706d5b9

4 files changed

Lines changed: 37 additions & 23 deletions

File tree

surfsense_web/components/report-panel/pdf-viewer.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
1515

1616
interface PdfViewerProps {
1717
pdfUrl: string;
18+
isPublic?: boolean;
1819
}
1920

2021
const ZOOM_STEP = 0.15;
2122
const MIN_ZOOM = 0.5;
2223
const MAX_ZOOM = 3;
2324
const PAGE_GAP = 12;
2425

25-
export function PdfViewer({ pdfUrl }: PdfViewerProps) {
26+
export function PdfViewer({ pdfUrl, isPublic = false }: PdfViewerProps) {
2627
const [numPages, setNumPages] = useState(0);
2728
const [scale, setScale] = useState(1);
2829
const [loading, setLoading] = useState(true);
@@ -192,7 +193,7 @@ export function PdfViewer({ pdfUrl }: PdfViewerProps) {
192193
return (
193194
<div className="flex flex-col h-full">
194195
{numPages > 0 && (
195-
<div className="flex items-center justify-center gap-2 px-4 py-2 border-b bg-sidebar shrink-0">
196+
<div className={`flex items-center justify-center gap-2 px-4 py-2 border-b shrink-0 ${isPublic ? "bg-main-panel" : "bg-sidebar"}`}>
196197
{numPages > 1 && (
197198
<>
198199
<span className="text-xs text-muted-foreground tabular-nums min-w-[60px] text-center">
@@ -215,10 +216,10 @@ export function PdfViewer({ pdfUrl }: PdfViewerProps) {
215216

216217
<div
217218
ref={scrollContainerRef}
218-
className="relative flex-1 overflow-auto bg-sidebar"
219+
className={`relative flex-1 overflow-auto ${isPublic ? "bg-main-panel" : "bg-sidebar"}`}
219220
>
220221
{loading ? (
221-
<div className="absolute inset-0 flex items-center justify-center text-sidebar-foreground">
222+
<div className={`absolute inset-0 flex items-center justify-center ${isPublic ? "text-foreground" : "text-sidebar-foreground"}`}>
222223
<Spinner size="md" />
223224
</div>
224225
) : (

surfsense_web/components/report-panel/report-panel.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,26 @@ export function ReportPanelContent({
286286
}, [activeReportId, currentMarkdown]);
287287

288288
const activeVersionIndex = versions.findIndex((v) => v.id === activeReportId);
289+
const isPublic = !!shareToken;
290+
const btnBg = isPublic ? "bg-main-panel" : "bg-sidebar";
289291

290292
return (
291293
<>
292294
{/* Action bar — always visible; buttons are disabled while loading */}
293295
<div className="flex items-center justify-between px-4 py-2 shrink-0">
294296
<div className="flex items-center gap-2">
295-
{/* Copy button */}
296-
<Button
297-
variant="outline"
298-
size="sm"
299-
onClick={handleCopy}
300-
disabled={isLoading || !reportContent?.content}
301-
className="h-8 min-w-[80px] px-3.5 py-4 text-[15px] bg-sidebar select-none"
302-
>
303-
{copied ? "Copied" : "Copy"}
304-
</Button>
297+
{/* Copy button — hidden for Typst (resume) */}
298+
{reportContent?.content_type !== "typst" && (
299+
<Button
300+
variant="outline"
301+
size="sm"
302+
onClick={handleCopy}
303+
disabled={isLoading || !reportContent?.content}
304+
className={`h-8 min-w-[80px] px-3.5 py-4 text-[15px] ${btnBg} select-none`}
305+
>
306+
{copied ? "Copied" : "Copy"}
307+
</Button>
308+
)}
305309

306310
{/* Export dropdown */}
307311
<DropdownMenu modal={insideDrawer ? false : undefined}>
@@ -310,7 +314,7 @@ export function ReportPanelContent({
310314
variant="outline"
311315
size="sm"
312316
disabled={isLoading || !reportContent?.content}
313-
className="h-8 px-3.5 py-4 text-[15px] gap-1.5 bg-sidebar select-none"
317+
className={`h-8 px-3.5 py-4 text-[15px] gap-1.5 ${btnBg} select-none`}
314318
>
315319
Export
316320
<ChevronDownIcon className="size-3" />
@@ -336,7 +340,7 @@ export function ReportPanelContent({
336340
<Button
337341
variant="outline"
338342
size="sm"
339-
className="h-8 px-3.5 py-4 text-[15px] gap-1.5 bg-sidebar select-none"
343+
className={`h-8 px-3.5 py-4 text-[15px] gap-1.5 ${btnBg} select-none`}
340344
>
341345
v{activeVersionIndex + 1}
342346
<ChevronDownIcon className="size-3" />
@@ -381,6 +385,7 @@ export function ReportPanelContent({
381385
) : reportContent.content_type === "typst" ? (
382386
<PdfViewer
383387
pdfUrl={`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}${shareToken ? `/api/v1/public/${shareToken}/reports/${activeReportId}/preview` : `/api/v1/reports/${activeReportId}/preview`}`}
388+
isPublic={isPublic}
384389
/>
385390
) : reportContent.content ? (
386391
isReadOnly ? (
@@ -432,10 +437,12 @@ function DesktopReportPanel() {
432437

433438
if (!panelState.isOpen || !panelState.reportId) return null;
434439

440+
const isPublic = !!panelState.shareToken;
441+
435442
return (
436443
<div
437444
ref={panelRef}
438-
className="flex w-[50%] max-w-[700px] min-w-[380px] flex-col border-l bg-sidebar text-sidebar-foreground animate-in slide-in-from-right-4 duration-300 ease-out"
445+
className={`flex w-[50%] max-w-[700px] min-w-[380px] flex-col border-l animate-in slide-in-from-right-4 duration-300 ease-out ${isPublic ? "bg-main-panel text-foreground" : "bg-sidebar text-sidebar-foreground"}`}
439446
>
440447
<ReportPanelContent
441448
reportId={panelState.reportId}
@@ -456,6 +463,8 @@ function MobileReportDrawer() {
456463

457464
if (!panelState.reportId) return null;
458465

466+
const isPublic = !!panelState.shareToken;
467+
459468
return (
460469
<Drawer
461470
open={panelState.isOpen}
@@ -465,7 +474,7 @@ function MobileReportDrawer() {
465474
shouldScaleBackground={false}
466475
>
467476
<DrawerContent
468-
className="h-[90vh] max-h-[90vh] z-80 bg-sidebar overflow-hidden"
477+
className={`h-[90vh] max-h-[90vh] z-80 overflow-hidden ${isPublic ? "bg-main-panel" : "bg-sidebar"}`}
469478
overlayClassName="z-80"
470479
>
471480
<DrawerHandle />

surfsense_web/components/tool-ui/generate-report.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ function ReportErrorState({ title, error }: { title: string; error: string }) {
9696
</div>
9797
<div className="mx-5 h-px bg-border/50" />
9898
<div className="px-5 py-4">
99-
<p className="text-sm font-medium text-foreground line-clamp-2">{title}</p>
100-
<p className="text-sm text-muted-foreground mt-1">{error}</p>
99+
{title && title !== "Report" && (
100+
<p className="text-sm font-medium text-foreground line-clamp-2">{title}</p>
101+
)}
102+
<p className={`text-sm text-muted-foreground${title && title !== "Report" ? " mt-1" : ""}`}>{error}</p>
101103
</div>
102104
</div>
103105
);

surfsense_web/components/tool-ui/generate-resume.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ function ResumeErrorState({ title, error }: { title: string; error: string }) {
6767
</div>
6868
<div className="mx-5 h-px bg-border/50" />
6969
<div className="px-5 py-4">
70-
<p className="text-sm font-medium text-foreground line-clamp-2">{title}</p>
71-
<p className="text-sm text-muted-foreground mt-1">{error}</p>
70+
{title && title !== "Resume" && (
71+
<p className="text-sm font-medium text-foreground line-clamp-2">{title}</p>
72+
)}
73+
<p className={`text-sm text-muted-foreground${title && title !== "Resume" ? " mt-1" : ""}`}>{error}</p>
7274
</div>
7375
</div>
7476
);
@@ -231,7 +233,7 @@ function ResumeCard({
231233
<div className="px-5 pt-3 pb-4">
232234
{thumbState === "loading" && <ThumbnailSkeleton />}
233235
{thumbState === "error" && (
234-
<p className="text-sm text-muted-foreground italic">Preview unavailable</p>
236+
<p className="text-sm text-muted-foreground">Preview unavailable</p>
235237
)}
236238
{pdfUrl && (
237239
<div

0 commit comments

Comments
 (0)