refactor: remove initial loader state and related logic from PDFViewerPage
This commit is contained in:
parent
9038562971
commit
059efed253
1 changed files with 5 additions and 21 deletions
|
|
@ -39,7 +39,6 @@ const PDFViewer = dynamic(
|
||||||
);
|
);
|
||||||
|
|
||||||
const PARSE_LOADER_EXPAND_DELAY_MS = 320;
|
const PARSE_LOADER_EXPAND_DELAY_MS = 320;
|
||||||
const INITIAL_LOADER_DELAY_MS = 180;
|
|
||||||
|
|
||||||
export default function PDFViewerPage() {
|
export default function PDFViewerPage() {
|
||||||
const canExportAudiobook = useFeatureFlag('enableAudiobookExport');
|
const canExportAudiobook = useFeatureFlag('enableAudiobookExport');
|
||||||
|
|
@ -71,7 +70,6 @@ export default function PDFViewerPage() {
|
||||||
const [activeSidebar, setActiveSidebar] = useState<null | 'settings' | 'audiobook' | 'segments'>(null);
|
const [activeSidebar, setActiveSidebar] = useState<null | 'settings' | 'audiobook' | 'segments'>(null);
|
||||||
const [showForceReparseConfirm, setShowForceReparseConfirm] = useState(false);
|
const [showForceReparseConfirm, setShowForceReparseConfirm] = useState(false);
|
||||||
const [showDetailedParseLoader, setShowDetailedParseLoader] = useState(false);
|
const [showDetailedParseLoader, setShowDetailedParseLoader] = useState(false);
|
||||||
const [showInitialLoader, setShowInitialLoader] = useState(false);
|
|
||||||
const [containerHeight, setContainerHeight] = useState<string>('auto');
|
const [containerHeight, setContainerHeight] = useState<string>('auto');
|
||||||
const inFlightDocIdRef = useRef<string | null>(null);
|
const inFlightDocIdRef = useRef<string | null>(null);
|
||||||
const loadedDocIdRef = useRef<string | null>(null);
|
const loadedDocIdRef = useRef<string | null>(null);
|
||||||
|
|
@ -92,7 +90,6 @@ export default function PDFViewerPage() {
|
||||||
setIsPdfViewerReady(false);
|
setIsPdfViewerReady(false);
|
||||||
setError(null);
|
setError(null);
|
||||||
setActiveSidebar(null);
|
setActiveSidebar(null);
|
||||||
setShowInitialLoader(false);
|
|
||||||
inFlightDocIdRef.current = null;
|
inFlightDocIdRef.current = null;
|
||||||
loadedDocIdRef.current = null;
|
loadedDocIdRef.current = null;
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
@ -158,17 +155,6 @@ export default function PDFViewerPage() {
|
||||||
|
|
||||||
useUnmountCleanupRef(clearCurrDoc);
|
useUnmountCleanupRef(clearCurrDoc);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isLoading) {
|
|
||||||
setShowInitialLoader(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const timeout = window.setTimeout(() => {
|
|
||||||
setShowInitialLoader(true);
|
|
||||||
}, INITIAL_LOADER_DELAY_MS);
|
|
||||||
return () => window.clearTimeout(timeout);
|
|
||||||
}, [isLoading, id]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
if (isParseReady) return;
|
if (isParseReady) return;
|
||||||
|
|
@ -295,7 +281,6 @@ export default function PDFViewerPage() {
|
||||||
: 0;
|
: 0;
|
||||||
const hasMeasuredProgress = totalPages > 0;
|
const hasMeasuredProgress = totalPages > 0;
|
||||||
const isMerging = parseProgress?.phase === 'merge';
|
const isMerging = parseProgress?.phase === 'merge';
|
||||||
const compactProgressWidth = hasMeasuredProgress ? `${progressPercent}%` : '24%';
|
|
||||||
|
|
||||||
let statusText = 'Loading PDF...';
|
let statusText = 'Loading PDF...';
|
||||||
let statusSubText = 'Initializing document renderer';
|
let statusSubText = 'Initializing document renderer';
|
||||||
|
|
@ -380,11 +365,10 @@ export default function PDFViewerPage() {
|
||||||
<LoadingSpinner className="h-3.5 w-3.5 text-accent" />
|
<LoadingSpinner className="h-3.5 w-3.5 text-accent" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-3 h-1.5 overflow-hidden rounded-full bg-surface-solid">
|
<div className="mt-3 grid grid-cols-3 gap-1.5">
|
||||||
<div
|
<span className="h-1.5 rounded-full bg-accent-wash animate-pulse" />
|
||||||
className={`h-full rounded-full bg-accent transition duration-slow ease-standard ${hasMeasuredProgress ? '' : 'animate-pulse'}`}
|
<span className="h-1.5 rounded-full bg-accent-wash animate-pulse [animation-delay:120ms]" />
|
||||||
style={{ width: compactProgressWidth }}
|
<span className="h-1.5 rounded-full bg-accent-wash animate-pulse [animation-delay:220ms]" />
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -439,7 +423,7 @@ export default function PDFViewerPage() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{(!isLoading || showInitialLoader) && (isLoading || !isParseReady || !isPdfViewerReady) ? (
|
{isLoading || !isParseReady || !isPdfViewerReady ? (
|
||||||
<div className="absolute inset-0 z-10" data-testid="pdf-status-loader">
|
<div className="absolute inset-0 z-10" data-testid="pdf-status-loader">
|
||||||
{renderPdfStatusLoader()}
|
{renderPdfStatusLoader()}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue