Skip to content

Commit 8fafe23

Browse files
Merge pull request #509 from Gslmao-s-Org/Gslmao/fixShareButton
Fix: Share dialog invisible in fullscreen mode
2 parents dd49428 + c6ce2e7 commit 8fafe23

3 files changed

Lines changed: 73 additions & 62 deletions

File tree

src/components/ShareButton.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import React, { useEffect, useState } from "react";
44
import {
55
Dialog,
6-
DialogContent,
76
DialogDescription,
87
DialogHeader,
98
DialogTitle,
109
DialogTrigger,
10+
DialogContent,
1111
} from "./ui/dialog";
1212
import { Copy } from "lucide-react";
1313
import toast from "react-hot-toast";
@@ -16,47 +16,53 @@ import QR from "./qr";
1616
import { Button } from "./ui/button";
1717
import { usePathname } from "next/navigation";
1818

19-
export default function ShareButton() {
19+
interface ShareButtonProps {
20+
isFullscreen: boolean;
21+
viewerRef: React.RefObject<HTMLDivElement>;
22+
}
23+
24+
export default function ShareButton({ isFullscreen, viewerRef }: ShareButtonProps) {
2025
const [origin, setOrigin] = useState("");
26+
const pathname = usePathname();
2127

2228
useEffect(() => {
23-
if (typeof window !== "undefined") {
24-
setOrigin(window.location.origin);
25-
}
29+
setOrigin(window.location.origin);
2630
}, []);
2731

28-
const pathname = usePathname();
2932
const paperPath = origin + pathname;
3033
return (
3134
<Dialog>
3235
<DialogTrigger asChild>
33-
<Button className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]" title="Share this paper">
36+
<Button
37+
className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]"
38+
title="Share this paper"
39+
>
3440
<FaShare />
3541
</Button>
3642
</DialogTrigger>
37-
<DialogContent className="max-w-96">
43+
<DialogContent
44+
container={isFullscreen ? viewerRef.current : document.body}
45+
className="max-w-96"
46+
>
3847
<DialogHeader>
3948
<DialogTitle>Share Papers with your friends!</DialogTitle>
4049
<DialogDescription>
4150
Either scan the QR or copy the link and share
4251
</DialogDescription>
4352
</DialogHeader>
4453
<div className="flex flex-col items-center justify-center gap-5">
45-
<QR url={paperPath}></QR>
54+
<QR url={paperPath} />
4655
<Button
47-
type="submit"
56+
type="button"
4857
size="sm"
4958
className="flex w-fit items-center justify-between gap-5 px-3"
5059
title="Copy link to clipboard"
5160
onClick={async () => {
52-
await toast.promise(
53-
navigator.clipboard.writeText(paperPath), // This is a promise
54-
{
55-
success: "Link copied successfully",
56-
loading: "Copying link...",
57-
error: "Error copying link",
58-
},
59-
);
61+
await toast.promise(navigator.clipboard.writeText(paperPath), {
62+
success: "Link copied successfully",
63+
loading: "Copying link...",
64+
error: "Error copying link",
65+
});
6066
}}
6167
>
6268
<p>Copy Link To Clipboard</p>
@@ -66,4 +72,4 @@ export default function ShareButton() {
6672
</DialogContent>
6773
</Dialog>
6874
);
69-
}
75+
}

src/components/newPdfViewer.tsx

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface ControlProps {
2525
forceMobile?: boolean;
2626
isMobile: boolean;
2727
isSmall: boolean;
28+
viewerRef: React.RefObject<HTMLDivElement>;
2829
}
2930

3031
interface PdfViewerProps {
@@ -57,7 +58,7 @@ function useBreakpoint() {
5758
}
5859

5960
const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscreen, onDownload,
60-
forceMobile, isMobile, isSmall}: ControlProps) {
61+
forceMobile, isMobile, isSmall, viewerRef}: ControlProps) {
6162

6263
const { provides: zoomProv, state: zoomState } = useZoom(documentId);
6364
const { provides: scrollProv, state: scrollState } = useScroll(documentId);
@@ -127,7 +128,7 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr
127128
<Download size={24} />
128129
</Button>
129130

130-
<ShareButton />
131+
<ShareButton isFullscreen={isFullscreen} viewerRef={viewerRef} />
131132

132133
<Button
133134
onClick={zoomOut}
@@ -492,47 +493,48 @@ if (isLoading || !engine) {
492493
forceMobile={true}
493494
isMobile={isMobile}
494495
isSmall={isSmall}
496+
viewerRef={viewerRef}
495497
/>}
496498
<DocumentContent documentId={activeDocumentId}>
497-
{({ isLoaded }) => (
498-
<>
499-
<div
500-
className="absolute inset-0 z-50 flex items-center justify-center bg-[#070114]"
501-
style={{
502-
opacity: isLoaded ? 0 : 1,
503-
pointerEvents: isLoaded ? "none" : "auto",
504-
transition: "opacity 0.3s",
505-
backgroundColor: effectiveBackgroundColor,
506-
}}
507-
>
508-
<Loader
509-
backgroundColor={effectiveBackgroundColor}
510-
textColor={loaderTextColor}
511-
/>
512-
</div>
513-
<Viewport
514-
documentId={activeDocumentId}
515-
style={{
516-
backgroundColor: effectiveBackgroundColor,
517-
visibility: isLoaded ? "visible" : "hidden",
518-
}}
519-
>
520-
<Scroller
521-
documentId={activeDocumentId}
522-
renderPage={({ width, height, pageIndex }) => (
523-
<div
524-
style={{ width, height }}
525-
onClick={(e) => e.stopPropagation()}
526-
>
527-
<RenderLayer documentId={activeDocumentId} pageIndex={pageIndex} />
528-
</div>
529-
)}
530-
/>
531-
</Viewport>
532-
</>
533-
)}
534-
</DocumentContent>
535-
499+
{({ isLoaded }) => (
500+
<>
501+
<div
502+
className="absolute inset-0 z-50 flex items-center justify-center bg-[#070114]"
503+
style={{
504+
opacity: isLoaded ? 0 : 1,
505+
pointerEvents: isLoaded ? "none" : "auto",
506+
transition: "opacity 0.3s",
507+
backgroundColor: effectiveBackgroundColor,
508+
}}
509+
>
510+
<Loader
511+
backgroundColor={effectiveBackgroundColor}
512+
textColor={loaderTextColor}
513+
/>
514+
</div>
515+
<Viewport
516+
documentId={activeDocumentId}
517+
style={{
518+
backgroundColor: effectiveBackgroundColor,
519+
visibility: isLoaded ? "visible" : "hidden",
520+
}}
521+
>
522+
<Scroller
523+
documentId={activeDocumentId}
524+
renderPage={({ width, height, pageIndex }) => (
525+
<div
526+
style={{ width, height }}
527+
onClick={(e) => e.stopPropagation()}
528+
>
529+
<RenderLayer documentId={activeDocumentId} pageIndex={pageIndex} />
530+
</div>
531+
)}
532+
/>
533+
</Viewport>
534+
</>
535+
)}
536+
</DocumentContent>
537+
536538
{!hideControls && (!isMobile || isFullscreen) && (
537539
<Controls
538540
documentId={activeDocumentId}
@@ -542,6 +544,7 @@ if (isLoading || !engine) {
542544
forceMobile={false}
543545
isMobile={isMobile}
544546
isSmall={isSmall}
547+
viewerRef={viewerRef}
545548
/>
546549
)}
547550
</>

src/components/ui/dialog.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
3030

3131
const DialogContent = React.forwardRef<
3232
React.ElementRef<typeof DialogPrimitive.Content>,
33-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
33+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
34+
container?: HTMLElement | null
35+
}
3436
>(({ className, children, ...props }, ref) => (
35-
<DialogPortal>
37+
<DialogPortal container={props.container}>
3638
<DialogOverlay />
3739
<DialogPrimitive.Content
3840
ref={ref}

0 commit comments

Comments
 (0)