Skip to content

Commit 9e9fe97

Browse files
author
Joyal KS
committed
feat(App.tsx): Add file input ref and improve PDF upload UX
1 parent 85b8ac6 commit 9e9fe97

1 file changed

Lines changed: 32 additions & 26 deletions

File tree

App.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const App: React.FC = () => {
4343
const viewportRef = useRef<HTMLDivElement>(null);
4444
const [isDraggingCanvas, setIsDraggingCanvas] = useState(false);
4545
const dragStartRef = useRef<{ x: number, y: number } | null>(null);
46+
const fileInputRef = useRef<HTMLInputElement>(null);
4647

4748
// Keyboard shortcuts for deletion and tool toggling
4849
useEffect(() => {
@@ -335,7 +336,7 @@ const App: React.FC = () => {
335336
<p className="mb-1 text-sm text-slate-400"><span className="font-semibold">Click to select PDF</span></p>
336337
<p className="text-xs text-slate-500">PDF files only</p>
337338
</div>
338-
<input type="file" className="hidden" accept="application/pdf" onChange={onFileChange} />
339+
<input ref={fileInputRef} type="file" className="hidden" accept="application/pdf" onChange={onFileChange} />
339340
</label>
340341
</div>
341342
)}
@@ -492,28 +493,30 @@ const App: React.FC = () => {
492493
</div>
493494

494495
{/* Footer Action */}
495-
<div className="p-4 border-t border-slate-800 bg-slate-900">
496-
<button
497-
onClick={handleSave}
498-
disabled={!file || annotations.length === 0 || isSaving}
499-
className={`flex items-center justify-center w-full py-2.5 px-4 rounded-lg font-medium text-sm transition-all shadow-lg ${!file || annotations.length === 0
500-
? 'bg-slate-800 text-slate-500 cursor-not-allowed'
501-
: 'bg-indigo-600 hover:bg-indigo-500 text-white hover:shadow-indigo-500/25'
502-
}`}
503-
>
504-
{isSaving ? (
505-
<span className="flex items-center space-x-2">
506-
<span className="w-4 h-4 border-2 border-white/20 border-t-white rounded-full animate-spin"></span>
507-
<span>Processing...</span>
508-
</span>
509-
) : (
510-
<span className="flex items-center space-x-2">
511-
<Download className="w-4 h-4" />
512-
<span>Download PDF</span>
513-
</span>
514-
)}
515-
</button>
516-
</div>
496+
{file && (
497+
<div className="p-4 border-t border-slate-800 bg-slate-900">
498+
<button
499+
onClick={handleSave}
500+
disabled={annotations.length === 0 || isSaving}
501+
className={`flex items-center justify-center w-full py-2.5 px-4 rounded-lg font-medium text-sm transition-all shadow-lg ${annotations.length === 0
502+
? 'bg-slate-800 text-slate-500 cursor-not-allowed'
503+
: 'bg-indigo-600 hover:bg-indigo-500 text-white hover:shadow-indigo-500/25'
504+
}`}
505+
>
506+
{isSaving ? (
507+
<span className="flex items-center space-x-2">
508+
<span className="w-4 h-4 border-2 border-white/20 border-t-white rounded-full animate-spin"></span>
509+
<span>Processing...</span>
510+
</span>
511+
) : (
512+
<span className="flex items-center space-x-2">
513+
<Download className="w-4 h-4" />
514+
<span>Download annotated PDF</span>
515+
</span>
516+
)}
517+
</button>
518+
</div>
519+
)}
517520
</aside>
518521

519522
{/* Main Content Area (Infinite Canvas) */}
@@ -603,11 +606,14 @@ const App: React.FC = () => {
603606
`}
604607
>
605608
{!file ? (
606-
<div className="flex flex-col items-center justify-center text-slate-600 pointer-events-none">
607-
<div className="w-24 h-24 bg-slate-900 rounded-2xl border-2 border-dashed border-slate-800 flex items-center justify-center mb-4">
609+
<div
610+
className="flex flex-col items-center justify-center text-slate-600 cursor-pointer hover:text-slate-500 transition-colors"
611+
onClick={() => fileInputRef.current?.click()}
612+
>
613+
<div className="w-24 h-24 bg-slate-900 rounded-2xl border-2 border-dashed border-slate-800 flex items-center justify-center mb-4 hover:border-slate-700 hover:bg-slate-800/50 transition-all">
608614
<FileText className="w-10 h-10 opacity-20" />
609615
</div>
610-
<p>Upload a PDF to begin</p>
616+
<p>Select a PDF to begin</p>
611617
</div>
612618
) : (
613619
<div

0 commit comments

Comments
 (0)