Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat(resume-export): wire the preview + settings panes into ExportPdfDialog and add a fit page/width preview control

Khuram Niaz889e6a35ec2d
diff --git a/src/components/profile/ExportPdfDialog.tsx b/src/components/profile/ExportPdfDialog.tsx
index 7c70ed8..9ea8326 100644
--- a/src/components/profile/ExportPdfDialog.tsx
+++ b/src/components/profile/ExportPdfDialog.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useState, type ReactNode } from "react";
+import { useEffect, useState } from "react";
import { FileDown, Loader } from "lucide-react";
import {
Dialog,
@@ -11,16 +11,20 @@ import {
DialogTitle,
} from "../ui/dialog";
import { Button } from "../ui/button";
-import { cn } from "@/lib/utils";
+import type { Resume } from "@/models/profile.model";
import {
- RESUME_LAYOUT_LABELS,
+ defaultResumeExportSettings,
type ResumeExportSettings,
- type ResumeLayout,
} from "@/models/resumeExport.model";
+import { ExportSettingsPanel } from "./export-pdf-dialog/ExportSettingsPanel";
+import { PdfPreviewPane } from "./export-pdf-dialog/PdfPreviewPane";
+import { canExportResume } from "./resume-container/useResumePdfExport";
+import { useResumePdfPreview } from "./resume-container/useResumePdfPreview";
type ExportPdfDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
+ resume: Resume;
isExporting: boolean;
onExport: (
settings: ResumeExportSettings,
@@ -28,159 +32,61 @@ type ExportPdfDialogProps = {
) => void;
};
-// Paper stays white in dark mode on purpose: the PDF page is white.
-function SkeletonPage({ children }: { children: ReactNode }) {
- return (
- <div className="flex aspect-[3/4] w-full flex-col gap-1.5 rounded-md border bg-white p-3">
- {children}
- </div>
- );
-}
-
-// Mirrors SimpleTemplate: header, then titled sections (label + black divider).
-function SimpleSkeleton() {
- return (
- <SkeletonPage>
- {/* Header */}
- <div className="flex flex-col gap-1.5">
- <div className="h-2.5 w-2/5 rounded-full bg-gray-800" />
- <div className="h-1.5 w-1/3 rounded-full bg-gray-400" />
- <div className="h-1 w-3/5 rounded-full bg-gray-300" />
- </div>
- {/* Summary */}
- <div className="flex flex-col gap-1">
- <div className="h-1.5 w-1/4 rounded-full bg-gray-700" />
- <div className="h-px w-full bg-gray-800" />
- <div className="h-1.5 w-full rounded-full bg-gray-200" />
- <div className="h-1.5 w-11/12 rounded-full bg-gray-200" />
- </div>
- {/* Skills — category label + values rows */}
- <div className="flex flex-col gap-1">
- <div className="h-1.5 w-1/5 rounded-full bg-gray-700" />
- <div className="h-px w-full bg-gray-800" />
- {[0, 1].map((i) => (
- <div key={i} className="flex items-center gap-1.5">
- <div className="h-1.5 w-1/5 shrink-0 rounded-full bg-gray-400" />
- <div className="h-1.5 flex-1 rounded-full bg-gray-200" />
- </div>
- ))}
- </div>
- {/* Experience — entry title, meta, body */}
- <div className="flex flex-col gap-1">
- <div className="h-1.5 w-1/3 rounded-full bg-gray-700" />
- <div className="h-px w-full bg-gray-800" />
- <div className="h-1.5 w-1/2 rounded-full bg-gray-500" />
- <div className="h-1 w-2/5 rounded-full bg-gray-300" />
- <div className="h-1.5 w-full rounded-full bg-gray-200" />
- <div className="h-1.5 w-11/12 rounded-full bg-gray-200" />
- </div>
- </SkeletonPage>
- );
-}
-
-// Mirrors ProfessionalTemplate: accent headline/rules, heading-less summary,
-// two-column skill categories, entry rows with right-aligned dates.
-function ProfessionalSkeleton() {
- return (
- <SkeletonPage>
- {/* Header */}
- <div className="flex justify-between">
- <div className="flex w-1/2 flex-col gap-1.5">
- <div className="h-2.5 w-4/5 rounded-full bg-gray-800" />
- <div className="h-1.5 w-3/5 rounded-full bg-[#34506e]" />
- </div>
- <div className="flex w-1/3 flex-col items-end gap-1">
- <div className="h-1 w-4/5 rounded-full bg-gray-300" />
- <div className="h-1 w-3/5 rounded-full bg-gray-300" />
- <div className="h-1 w-2/5 rounded-full bg-gray-300" />
- </div>
- </div>
- {/* Thick rule */}
- <div className="h-0.5 w-full rounded-full bg-gray-900" />
- {/* Summary — no heading */}
- <div className="flex flex-col gap-1">
- <div className="h-1.5 w-full rounded-full bg-gray-200" />
- <div className="h-1.5 w-11/12 rounded-full bg-gray-200" />
- </div>
- {/* Skills — two-column categories */}
- <div className="flex flex-col gap-1">
- <div className="flex items-center gap-1">
- <div className="h-1.5 w-1/5 rounded-full bg-[#34506e]" />
- <div className="h-px flex-1 bg-[#34506e]" />
- </div>
- <div className="grid grid-cols-2 gap-x-2 gap-y-1">
- {[0, 1, 2, 3].map((i) => (
- <div key={i} className="flex flex-col gap-0.5">
- <div className="h-1 w-2/5 rounded-full bg-gray-400" />
- <div className="h-1.5 w-full rounded-full bg-gray-200" />
- </div>
- ))}
- </div>
- </div>
- {/* Experience — title + right-aligned date, meta, body */}
- <div className="flex flex-col gap-1">
- <div className="flex items-center gap-1">
- <div className="h-1.5 w-1/4 rounded-full bg-[#34506e]" />
- <div className="h-px flex-1 bg-[#34506e]" />
- </div>
- <div className="flex items-center justify-between">
- <div className="h-1.5 w-2/5 rounded-full bg-gray-500" />
- <div className="h-1 w-1/6 rounded-full bg-gray-300" />
- </div>
- <div className="h-1 w-1/3 rounded-full bg-gray-300" />
- <div className="h-1.5 w-full rounded-full bg-gray-200" />
- <div className="h-1.5 w-11/12 rounded-full bg-gray-200" />
- </div>
- </SkeletonPage>
- );
-}
-
export function ExportPdfDialog({
open,
onOpenChange,
+ resume,
isExporting,
onExport,
}: ExportPdfDialogProps) {
- const [selected, setSelected] = useState<ResumeLayout>("simple");
+ const [settings, setSettings] = useState<ResumeExportSettings>(
+ defaultResumeExportSettings,
+ );
- // Simple is the pre-selected default every time the dialog opens.
+ // Settings are not persisted: reset on close, so the next open already
+ // holds the defaults on its very first render.
useEffect(() => {
- if (open) setSelected("simple");
+ if (!open) setSettings(defaultResumeExportSettings);
}, [open]);
+ const canExport = canExportResume(resume);
+ const { blob, filename, isGenerating, error } = useResumePdfPreview(
+ resume,
+ settings,
+ open,
+ );
+
+ // Exporting mid-generation would download the template just switched away
+ // from, since Export reuses the previewed blob.
+ const exportDisabled = isExporting || !canExport || isGenerating;
+
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-lg">
+ {/* A fixed height, not a max: the pane fits pages to its own height, so
+ a content-driven one would feed back on itself. */}
+ <DialogContent className="flex h-[90vh] flex-col sm:max-w-5xl">
<DialogHeader>
<DialogTitle>Export to PDF</DialogTitle>
- <DialogDescription>Choose a template.</DialogDescription>
+ <DialogDescription>
+ Adjust the settings and preview the file before exporting.
+ </DialogDescription>
</DialogHeader>
- <div className="grid grid-cols-2 gap-4">
- {(["simple", "professional"] as ResumeLayout[]).map((layout) => (
- <button
- key={layout}
- type="button"
- aria-pressed={selected === layout}
- disabled={isExporting}
- onClick={() => setSelected(layout)}
- className={cn(
- "flex flex-col gap-2 rounded-lg border p-3 transition-colors",
- selected === layout
- ? "border-primary ring-2 ring-primary"
- : "hover:border-primary/50",
- )}
- >
- {layout === "simple" ? (
- <SimpleSkeleton />
- ) : (
- <ProfessionalSkeleton />
- )}
- <span className="text-center text-sm font-medium">
- {RESUME_LAYOUT_LABELS[layout]}
- </span>
- </button>
- ))}
+
+ <div className="flex min-h-0 flex-1 flex-col gap-4 md:flex-row">
+ <div className="order-2 h-[45vh] min-h-0 md:order-1 md:h-auto md:min-w-0 md:flex-1">
+ <PdfPreviewPane
+ blob={blob}
+ isGenerating={isGenerating}
+ hasError={!!error}
+ canExport={canExport}
+ className="h-full"
+ />
+ </div>
+ <div className="order-1 min-h-0 shrink-0 overflow-y-auto md:order-2 md:w-[34%]">
+ <ExportSettingsPanel settings={settings} onChange={setSettings} />
+ </div>
</div>
+
<DialogFooter>
<Button
type="button"
@@ -192,10 +98,13 @@ export function ExportPdfDialog({
</Button>
<Button
type="button"
- disabled={isExporting}
+ disabled={exportDisabled}
onClick={() => {
+ // The blob on screen is the artifact; a null one makes the hook
+ // fall back to generating, which covers a failed preview.
+ const prepared = blob && filename ? { blob, filename } : null;
onOpenChange(false);
- onExport({ template: selected });
+ onExport(settings, prepared);
}}
>
{isExporting ? (
diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsx
index e65ee7b..f910035 100644
--- a/src/components/profile/ResumeContainer.tsx
+++ b/src/components/profile/ResumeContainer.tsx
@@ -284,10 +284,11 @@ function ResumeContainer({
/>
)}
- {/* PDF EXPORT TEMPLATE PICKER */}
+ {/* PDF EXPORT PREVIEW + SETTINGS */}
<ExportPdfDialog
open={showExportDialog}
onOpenChange={setShowExportDialog}
+ resume={resume}
isExporting={isExporting}
onExport={handleExportPdf}
/>
diff --git a/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx b/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
index 0c8816c..4c31ba8 100644
--- a/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
+++ b/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
@@ -2,13 +2,21 @@
import { useEffect, useRef, useState } from "react";
import { Spinner } from "@/components/ui/spinner";
+import { Toggle } from "@/components/ui/toggle";
+import { APP_CONSTANTS } from "@/lib/constants";
import { cn } from "@/lib/utils";
+import {
+ getFromLocalStorage,
+ saveToLocalStorage,
+} from "@/utils/localstorage.utils";
const PREVIEW_RESIZE_DEBOUNCE_MS = 250;
const MAX_CANVAS_SCALE = 2;
const EMPTY_MESSAGE =
"Add your contact info and at least one section to preview.";
+type FitMode = "page" | "width";
+
type PdfPreviewPaneProps = {
blob: Blob | null;
isGenerating: boolean;
@@ -40,33 +48,63 @@ export function PdfPreviewPane({
const scrollRef = useRef<HTMLDivElement>(null);
const measureRef = useRef<HTMLDivElement>(null);
const pagesRef = useRef<HTMLDivElement>(null);
- const widthRef = useRef(0);
- const [width, setWidth] = useState(0);
+ const sizeRef = useRef({ width: 0, height: 0 });
+ const [size, setSize] = useState({ width: 0, height: 0 });
const [pageCount, setPageCount] = useState(0);
const [renderFailed, setRenderFailed] = useState(false);
+ const [fitMode, setFitMode] = useState<FitMode>("page");
+
+ // Read after mount: localStorage is unavailable during SSR, so seeding the
+ // initial state from it would cause a hydration mismatch.
+ useEffect(() => {
+ const saved = getFromLocalStorage(
+ APP_CONSTANTS.RESUME_PREVIEW_FIT_STORAGE_KEY,
+ null,
+ );
+ if (saved === "page" || saved === "width") setFitMode(saved);
+ }, []);
+
+ const onChangeFitMode = (mode: FitMode) => {
+ setFitMode(mode);
+ saveToLocalStorage(APP_CONSTANTS.RESUME_PREVIEW_FIT_STORAGE_KEY, mode);
+ };
useEffect(() => {
- const element = measureRef.current;
- if (!element) return;
+ const measure = measureRef.current;
+ const scroll = scrollRef.current;
+ if (!measure || !scroll) return;
let timer: ReturnType<typeof setTimeout> | undefined;
+ // Width caps the page; the scroll box's height is what decides whether a
+ // whole page fits, so both are measured.
const observer = new ResizeObserver((entries) => {
- const next = Math.floor(entries[0].contentRect.width);
- if (next <= 0 || next === widthRef.current) return;
+ let { width, height } = sizeRef.current;
+ for (const entry of entries) {
+ if (entry.target === measure) {
+ width = Math.floor(entry.contentRect.width);
+ } else {
+ height = Math.floor(entry.contentRect.height);
+ }
+ }
+ if (width <= 0 || height <= 0) return;
+ if (width === sizeRef.current.width && height === sizeRef.current.height) {
+ return;
+ }
+ const commit = () => {
+ sizeRef.current = { width, height };
+ setSize({ width, height });
+ };
// First measurement lands at once; later changes share the 250ms debounce.
- if (widthRef.current === 0) {
- widthRef.current = next;
- setWidth(next);
+ if (sizeRef.current.width === 0) {
+ commit();
return;
}
clearTimeout(timer);
- timer = setTimeout(() => {
- widthRef.current = next;
- setWidth(next);
- }, PREVIEW_RESIZE_DEBOUNCE_MS);
+ timer = setTimeout(commit, PREVIEW_RESIZE_DEBOUNCE_MS);
});
- observer.observe(element);
+ observer.observe(measure);
+ observer.observe(scroll);
return () => {
clearTimeout(timer);
observer.disconnect();
@@ -74,7 +112,8 @@ export function PdfPreviewPane({
}, []);
useEffect(() => {
- if (!blob || width <= 0) return;
+ const { width, height } = size;
+ if (!blob || width <= 0 || height <= 0) return;
let cancelled = false;
let renderTask: { cancel: () => void } | null = null;
@@ -105,8 +144,17 @@ export function PdfPreviewPane({
if (cancelled) return;
const unscaled = page.getViewport({ scale: 1 });
+ // Fit page also bounds by height, so a page is whole rather than
+ // cropped; fit width ignores height and lets the pane scroll.
+ const fitted =
+ fitMode === "width"
+ ? width
+ : Math.min(
+ width,
+ Math.floor(height * (unscaled.width / unscaled.height)),
+ );
const viewport = page.getViewport({
- scale: (width / unscaled.width) * dpr,
+ scale: (fitted / unscaled.width) * dpr,
});
// Detached canvases: the mounted set is swapped only once the whole
@@ -114,7 +162,8 @@ export function PdfPreviewPane({
const canvas = document.createElement("canvas");
canvas.width = Math.floor(viewport.width);
canvas.height = Math.floor(viewport.height);
- canvas.className = "block h-auto w-full bg-white shadow-sm";
+ canvas.style.width = `${fitted}px`;
+ canvas.className = "block h-auto bg-white shadow-sm";
const task = page.render({ canvas, viewport });
renderTask = task;
@@ -147,7 +196,7 @@ export function PdfPreviewPane({
// the call, so the rejection is swallowed rather than left floating.
void document_?.destroy().catch(() => {});
};
- }, [blob, width]);
+ }, [blob, size, fitMode]);
const hasPages = pageCount > 0;
const showEmpty = !canExport;
@@ -167,11 +216,35 @@ export function PdfPreviewPane({
return (
<div className={cn("flex min-h-0 flex-col gap-2", className)}>
- <div className="flex items-baseline justify-between">
+ <div className="flex items-center justify-between gap-2">
<span className="text-sm font-medium">Preview</span>
- <span className="text-xs text-muted-foreground">
- {hasPages ? pageLabel(pageCount) : ""}
- </span>
+ <div className="flex items-center gap-2">
+ {hasPages && (
+ <div className="flex items-center rounded-md border p-0.5">
+ <Toggle
+ size="sm"
+ pressed={fitMode === "page"}
+ onPressedChange={() => onChangeFitMode("page")}
+ aria-label="Fit whole page"
+ className="h-6 px-2 text-xs"
+ >
+ Fit page
+ </Toggle>
+ <Toggle
+ size="sm"
+ pressed={fitMode === "width"}
+ onPressedChange={() => onChangeFitMode("width")}
+ aria-label="Fit page width"
+ className="h-6 px-2 text-xs"
+ >
+ Fit width
+ </Toggle>
+ </div>
+ )}
+ <span className="text-xs text-muted-foreground">
+ {hasPages ? pageLabel(pageCount) : ""}
+ </span>
+ </div>
</div>
<div
@@ -186,7 +259,7 @@ export function PdfPreviewPane({
ref={pagesRef}
aria-hidden="true"
className={cn(
- "flex flex-col gap-4 transition-opacity",
+ "flex flex-col items-center gap-4 transition-opacity",
showOverlaySpinner && "opacity-50",
)}
/>
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 21b1066..ce15306 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -38,6 +38,7 @@ export const APP_CONSTANTS = {
LAST_JOB_LOCATION_STORAGE_KEY: "last-job-location",
LAST_JOB_SOURCE_STORAGE_KEY: "last-job-source",
JOBS_VIEW_MODE_STORAGE_KEY: "jobs-view-mode",
+ RESUME_PREVIEW_FIT_STORAGE_KEY: "resume-preview-fit",
SIDEBAR_DOM_ID: "app-sidebar",
// Paired so the rail width and its matching content offset can't drift.
SIDEBAR_WIDTH: {