|
1 | 1 | import { api } from "@/api/api"; |
2 | | -import { useRef, useState } from "react"; |
| 2 | +import { lazy, useRef, useState } from "react"; |
3 | 3 | import { Document, Page, pdfjs } from "react-pdf"; |
4 | 4 |
|
5 | 5 | import Modal from "./Modal"; |
@@ -43,8 +43,7 @@ const Preview = ({ id, lengthType }) => { |
43 | 43 | const showThreshold = lengthType === "SHORT" ? 2 : 4; |
44 | 44 |
|
45 | 45 | // for Responsive design |
46 | | - const totalRevealedPages = |
47 | | - width >= 1280 ? 5 : width >= 768 ? 3 : !isSmallMobile ? 2 : 1; |
| 46 | + const totalRevealedPages = width >= 1280 ? 5 : width >= 768 ? 3 : !isSmallMobile ? 2 : 1; |
48 | 47 |
|
49 | 48 | useRequest(async () => { |
50 | 49 | try { |
@@ -120,82 +119,58 @@ const Preview = ({ id, lengthType }) => { |
120 | 119 | {/* 썸네일로 상위 5개 페이지 표시 */} |
121 | 120 | {/* showThreshold까지만 pdf를 가져옴, 이후 페이지는 마지막 페이지를 복사하도록*/} |
122 | 121 | {numPages && ( |
123 | | - <div |
124 | | - className="flex flex-row gap-[20px] j-content-start" |
125 | | - id="wrap" |
126 | | - > |
127 | | - {Array.from( |
128 | | - new Array(Math.min(totalPages, totalRevealedPages)), |
129 | | - (_, index) => { |
130 | | - const isShort = lengthType === "SHORT"; |
131 | | - |
132 | | - let isPageAvailable = true; |
133 | | - if (lengthType === "SHORT") { |
134 | | - // showThreshold까지의 모든 페이지 활성화 |
| 122 | + <div className="flex flex-row gap-[20px] j-content-start" id="wrap"> |
| 123 | + {Array.from(new Array(Math.min(totalPages, totalRevealedPages)), (_, index) => { |
| 124 | + const isShort = lengthType === "SHORT"; |
| 125 | + |
| 126 | + let isPageAvailable = true; |
| 127 | + if (lengthType === "SHORT") { |
| 128 | + // showThreshold까지의 모든 페이지 활성화 |
| 129 | + isPageAvailable = index + 1 <= showThreshold; |
| 130 | + } else { |
| 131 | + // lengthType === "LONG" |
| 132 | + if (width >= 1280) { |
135 | 133 | isPageAvailable = index + 1 <= showThreshold; |
| 134 | + } else if (!isSmallMobile) { |
| 135 | + isPageAvailable = index + 1 < totalRevealedPages; |
136 | 136 | } else { |
137 | | - // lengthType === "LONG" |
138 | | - if (width >= 1280) { |
139 | | - isPageAvailable = index + 1 <= showThreshold; |
140 | | - } else if (!isSmallMobile) { |
141 | | - isPageAvailable = index + 1 < totalRevealedPages; |
142 | | - } else { |
143 | | - isPageAvailable = 1; |
144 | | - } |
| 137 | + isPageAvailable = 1; |
145 | 138 | } |
| 139 | + } |
146 | 140 |
|
147 | | - return ( |
148 | | - <div |
149 | | - key={index + 1} |
150 | | - className={` c-pointer no-drag ${ |
151 | | - !isPageAvailable ? "content-disabled" : "" |
152 | | - }`} |
153 | | - id="thumbnail-content" |
154 | | - onClick={() => { |
155 | | - if (isPageAvailable) { |
156 | | - onClickPage( |
157 | | - isShort |
158 | | - ? Math.min(index + 1, showThreshold) |
159 | | - : index + 1 |
160 | | - ); |
161 | | - } |
162 | | - }} |
163 | | - > |
164 | | - {!isPageAvailable && <div id="shadow-box"></div>} |
165 | | - <div id={!isPageAvailable ? "blur" : undefined}> |
166 | | - <Page |
167 | | - renderMode="canvas" |
168 | | - pageNumber={ |
169 | | - isPageAvailable ? index + 1 : showThreshold |
170 | | - } |
171 | | - width={210} |
172 | | - /> |
173 | | - </div> |
174 | | - <p |
175 | | - className="p-small-regular t-align-center" |
176 | | - id="page-number" |
177 | | - > |
178 | | - {index + 1} |
179 | | - </p> |
180 | | - {index + 1 === totalRevealedPages && ( |
181 | | - <p |
182 | | - className="p-large-regular c-white" |
183 | | - id="last-number" |
184 | | - > |
185 | | - {totalPages - totalRevealedPages} + |
186 | | - </p> |
187 | | - )} |
188 | | - {isPageAvailable && ( |
189 | | - <img |
190 | | - src={previewGlass} |
191 | | - alt="Preview Glass" |
192 | | - id="preview-glass" |
193 | | - /> |
194 | | - )} |
| 141 | + return ( |
| 142 | + <div |
| 143 | + key={index + 1} |
| 144 | + className={` c-pointer no-drag ${!isPageAvailable ? "content-disabled" : ""}`} |
| 145 | + id="thumbnail-content" |
| 146 | + onClick={() => { |
| 147 | + if (isPageAvailable) { |
| 148 | + onClickPage(isShort ? Math.min(index + 1, showThreshold) : index + 1); |
| 149 | + } |
| 150 | + }} |
| 151 | + > |
| 152 | + {!isPageAvailable && <div id="shadow-box"></div>} |
| 153 | + <div id={!isPageAvailable ? "blur" : undefined}> |
| 154 | + <Page |
| 155 | + renderMode="canvas" |
| 156 | + pageNumber={isPageAvailable ? index + 1 : showThreshold} |
| 157 | + width={210} |
| 158 | + /> |
195 | 159 | </div> |
196 | | - ); |
197 | | - } |
198 | | - )} |
| 160 | + <p className="p-small-regular t-align-center" id="page-number"> |
| 161 | + {index + 1} |
| 162 | + </p> |
| 163 | + {index + 1 === totalRevealedPages && ( |
| 164 | + <p className="p-large-regular c-white" id="last-number"> |
| 165 | + {totalPages - totalRevealedPages} + |
| 166 | + </p> |
| 167 | + )} |
| 168 | + {isPageAvailable && ( |
| 169 | + <img src={previewGlass} alt="Preview Glass" id="preview-glass" /> |
| 170 | + )} |
| 171 | + </div> |
| 172 | + ); |
| 173 | + })} |
199 | 174 | </div> |
200 | 175 | )} |
201 | 176 |
|
|
0 commit comments