Alleinzellgaenger commited on
Commit
2f3ecea
·
1 Parent(s): 1e2a2f3

fix zooming out

Browse files
frontend/src/components/UploadPage.jsx CHANGED
@@ -31,9 +31,10 @@ function UploadPage() {
31
  setCurrentPage(newPage);
32
  }
33
 
34
- // Track visible pages (current + adjacent for smooth scrolling)
35
  const newVisiblePages = new Set();
36
- for (let i = Math.max(1, newPage - 1); i <= Math.min(numPages, newPage + 1); i++) {
 
37
  newVisiblePages.add(i);
38
  }
39
 
@@ -50,7 +51,8 @@ function UploadPage() {
50
 
51
  // Update visible pages immediately for target page
52
  const newVisiblePages = new Set();
53
- for (let i = Math.max(1, pageNumber - 1); i <= Math.min(numPages, pageNumber + 1); i++) {
 
54
  newVisiblePages.add(i);
55
  }
56
  setVisiblePages(newVisiblePages);
@@ -107,29 +109,31 @@ function UploadPage() {
107
  {/* PDF container with scrolling */}
108
  <div
109
  ref={pdfContainerRef}
110
- className="flex-1 overflow-auto flex justify-center items-start bg-gray-100"
111
  onScroll={handleScroll}
112
  >
113
- <Document
114
- file={selectedFile}
115
- onLoadSuccess={({ numPages }) => setNumPages(numPages)}
116
- >
117
- {/* Render all pages continuously */}
118
- {numPages && Array.from(new Array(numPages), (_, index) => {
119
- const pageNum = index + 1;
120
- const isVisible = visiblePages.has(pageNum);
121
- const currentZoom = isVisible ? zoomLevel : 1; // Only zoom visible pages
122
-
123
- return (
124
- <div key={pageNum} className="mb-4">
125
- <Page
126
- pageNumber={pageNum}
127
- width={typeof window !== 'undefined' ? window.innerWidth * 0.66 * 0.9 * currentZoom : 600 * currentZoom}
128
- />
129
- </div>
130
- );
131
- })}
132
- </Document>
 
 
133
  </div>
134
  {/* Pagination overlay - floating pill */}
135
  {numPages && (
 
31
  setCurrentPage(newPage);
32
  }
33
 
34
+ // Track visible pages based on zoom level (more pages visible when zoomed out)
35
  const newVisiblePages = new Set();
36
+ const visibleRange = Math.max(1, Math.ceil(2 / zoomLevel)); // More pages when zoomed out
37
+ for (let i = Math.max(1, newPage - visibleRange); i <= Math.min(numPages, newPage + visibleRange); i++) {
38
  newVisiblePages.add(i);
39
  }
40
 
 
51
 
52
  // Update visible pages immediately for target page
53
  const newVisiblePages = new Set();
54
+ const visibleRange = Math.max(1, Math.ceil(2 / zoomLevel)); // More pages when zoomed out
55
+ for (let i = Math.max(1, pageNumber - visibleRange); i <= Math.min(numPages, pageNumber + visibleRange); i++) {
56
  newVisiblePages.add(i);
57
  }
58
  setVisiblePages(newVisiblePages);
 
109
  {/* PDF container with scrolling */}
110
  <div
111
  ref={pdfContainerRef}
112
+ className="flex-1 overflow-auto flex justify-center bg-gray-100"
113
  onScroll={handleScroll}
114
  >
115
+ <div className="py-4">
116
+ <Document
117
+ file={selectedFile}
118
+ onLoadSuccess={({ numPages }) => setNumPages(numPages)}
119
+ >
120
+ {/* Render all pages continuously */}
121
+ {numPages && Array.from(new Array(numPages), (_, index) => {
122
+ const pageNum = index + 1;
123
+ const isVisible = visiblePages.has(pageNum);
124
+ const currentZoom = isVisible ? zoomLevel : 1; // Only zoom visible pages
125
+
126
+ return (
127
+ <div key={pageNum} className="mb-4 flex justify-center">
128
+ <Page
129
+ pageNumber={pageNum}
130
+ width={typeof window !== 'undefined' ? window.innerWidth * 0.66 * 0.9 * currentZoom : 600 * currentZoom}
131
+ />
132
+ </div>
133
+ );
134
+ })}
135
+ </Document>
136
+ </div>
137
  </div>
138
  {/* Pagination overlay - floating pill */}
139
  {numPages && (