|
468 | 468 | const [isReadingMode, setIsReadingMode] = useState(false); |
469 | 469 | const [showReadingCoachmark, setShowReadingCoachmark] = useState(false); |
470 | 470 | const viewerRef = useRef<HTMLDivElement>(null); |
| 471 | + const [urlStatus, setUrlStatus] = useState<"checking" | "ok" | "error">("checking"); |
| 472 | + |
| 473 | + useEffect(() => { |
| 474 | + let isMounted = true; |
| 475 | + fetch(url, { method: "HEAD" }) |
| 476 | + .then(res => { |
| 477 | + if (isMounted) setUrlStatus(res.ok ? "ok" : "error"); |
| 478 | + }) |
| 479 | + .catch(() => { |
| 480 | + if (isMounted) setUrlStatus("error"); |
| 481 | + }); |
| 482 | + return () => { isMounted = false; }; |
| 483 | + }, [url]); |
471 | 484 | const effectiveBackgroundColor = |
472 | 485 | backgroundColor ?? (resolvedTheme === "light" ? "#F3F5FF" : "#070114"); |
473 | 486 | const loaderTextColor = |
|
569 | 582 | }), |
570 | 583 | ], [url, name]); |
571 | 584 |
|
572 | | - if (isLoading || !engine) { |
| 585 | + if (urlStatus === "error") { |
| 586 | + return ( |
| 587 | + <div className="flex h-dvh w-full flex-col items-center justify-center gap-2" style={{ backgroundColor: effectiveBackgroundColor, color: loaderTextColor }}> |
| 588 | + <BookOpenText size={48} className="opacity-50 mb-2" /> |
| 589 | + <span className="text-lg font-medium">Paper Not Found</span> |
| 590 | + <span className="text-sm opacity-70 text-center max-w-[250px]"> |
| 591 | + This paper has been deleted or is missing from the server. |
| 592 | + </span> |
| 593 | + </div> |
| 594 | + ); |
| 595 | + } |
| 596 | + |
| 597 | + if (isLoading || !engine || urlStatus === "checking") { |
573 | 598 | return ( |
574 | 599 | <Loader |
575 | 600 | backgroundColor={effectiveBackgroundColor} |
|
653 | 678 | dismissReadingCoachmark={dismissReadingCoachmark} |
654 | 679 | />} |
655 | 680 | <DocumentContent documentId={activeDocumentId}> |
656 | | - {({ isLoaded }) => ( |
| 681 | + {({ isLoaded, isError }) => ( |
657 | 682 | <> |
658 | 683 | <div |
659 | 684 | className="absolute inset-0 z-50 flex items-center justify-center bg-[#070114]" |
|
664 | 689 | backgroundColor: effectiveBackgroundColor, |
665 | 690 | }} |
666 | 691 | > |
667 | | - <Loader |
668 | | - backgroundColor={effectiveBackgroundColor} |
669 | | - textColor={loaderTextColor} |
670 | | - /> |
| 692 | + {isError ? ( |
| 693 | + <div className="flex flex-col items-center gap-2" style={{ color: loaderTextColor }}> |
| 694 | + <BookOpenText size={48} className="opacity-50 mb-2" /> |
| 695 | + <span className="text-lg font-medium">Paper Not Found</span> |
| 696 | + <span className="text-sm opacity-70 text-center max-w-[250px]"> |
| 697 | + This paper has been deleted or is missing from the server. |
| 698 | + </span> |
| 699 | + </div> |
| 700 | + ) : ( |
| 701 | + <Loader |
| 702 | + backgroundColor={effectiveBackgroundColor} |
| 703 | + textColor={loaderTextColor} |
| 704 | + /> |
| 705 | + )} |
671 | 706 | </div> |
672 | 707 | <Viewport |
673 | 708 | documentId={activeDocumentId} |
|
0 commit comments