Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/components/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import React, { useEffect, useState } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogContent,
} from "./ui/dialog";
import { Copy } from "lucide-react";
import toast from "react-hot-toast";
Expand All @@ -16,47 +16,53 @@ import QR from "./qr";
import { Button } from "./ui/button";
import { usePathname } from "next/navigation";

export default function ShareButton() {
interface ShareButtonProps {
isFullscreen: boolean;
viewerRef: React.RefObject<HTMLDivElement>;
}

export default function ShareButton({ isFullscreen, viewerRef }: ShareButtonProps) {
const [origin, setOrigin] = useState("");
const pathname = usePathname();

useEffect(() => {
if (typeof window !== "undefined") {
setOrigin(window.location.origin);
}
setOrigin(window.location.origin);
}, []);

const pathname = usePathname();
const paperPath = origin + pathname;
return (
<Dialog>
<DialogTrigger asChild>
<Button className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]" title="Share this paper">
<Button
className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]"
title="Share this paper"
>
<FaShare />
</Button>
</DialogTrigger>
<DialogContent className="max-w-96">
<DialogContent
container={isFullscreen ? viewerRef.current : document.body}
className="max-w-96"
>
<DialogHeader>
<DialogTitle>Share Papers with your friends!</DialogTitle>
<DialogDescription>
Either scan the QR or copy the link and share
</DialogDescription>
</DialogHeader>
<div className="flex flex-col items-center justify-center gap-5">
<QR url={paperPath}></QR>
<QR url={paperPath} />
<Button
type="submit"
type="button"
size="sm"
className="flex w-fit items-center justify-between gap-5 px-3"
title="Copy link to clipboard"
onClick={async () => {
await toast.promise(
navigator.clipboard.writeText(paperPath), // This is a promise
{
success: "Link copied successfully",
loading: "Copying link...",
error: "Error copying link",
},
);
await toast.promise(navigator.clipboard.writeText(paperPath), {
success: "Link copied successfully",
loading: "Copying link...",
error: "Error copying link",
});
}}
>
<p>Copy Link To Clipboard</p>
Expand All @@ -66,4 +72,4 @@ export default function ShareButton() {
</DialogContent>
</Dialog>
);
}
}
85 changes: 44 additions & 41 deletions src/components/newPdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ControlProps {
forceMobile?: boolean;
isMobile: boolean;
isSmall: boolean;
viewerRef: React.RefObject<HTMLDivElement>;
}

interface PdfViewerProps {
Expand Down Expand Up @@ -57,7 +58,7 @@ function useBreakpoint() {
}

const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscreen, onDownload,
forceMobile, isMobile, isSmall}: ControlProps) {
forceMobile, isMobile, isSmall, viewerRef}: ControlProps) {

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

<ShareButton />
<ShareButton isFullscreen={isFullscreen} viewerRef={viewerRef} />

<Button
onClick={zoomOut}
Expand Down Expand Up @@ -492,47 +493,48 @@ if (isLoading || !engine) {
forceMobile={true}
isMobile={isMobile}
isSmall={isSmall}
viewerRef={viewerRef}
/>}
<DocumentContent documentId={activeDocumentId}>
{({ isLoaded }) => (
<>
<div
className="absolute inset-0 z-50 flex items-center justify-center bg-[#070114]"
style={{
opacity: isLoaded ? 0 : 1,
pointerEvents: isLoaded ? "none" : "auto",
transition: "opacity 0.3s",
backgroundColor: effectiveBackgroundColor,
}}
>
<Loader
backgroundColor={effectiveBackgroundColor}
textColor={loaderTextColor}
/>
</div>
<Viewport
documentId={activeDocumentId}
style={{
backgroundColor: effectiveBackgroundColor,
visibility: isLoaded ? "visible" : "hidden",
}}
>
<Scroller
documentId={activeDocumentId}
renderPage={({ width, height, pageIndex }) => (
<div
style={{ width, height }}
onClick={(e) => e.stopPropagation()}
>
<RenderLayer documentId={activeDocumentId} pageIndex={pageIndex} />
</div>
)}
/>
</Viewport>
</>
)}
</DocumentContent>

{({ isLoaded }) => (
<>
<div
className="absolute inset-0 z-50 flex items-center justify-center bg-[#070114]"
style={{
opacity: isLoaded ? 0 : 1,
pointerEvents: isLoaded ? "none" : "auto",
transition: "opacity 0.3s",
backgroundColor: effectiveBackgroundColor,
}}
>
<Loader
backgroundColor={effectiveBackgroundColor}
textColor={loaderTextColor}
/>
</div>
<Viewport
documentId={activeDocumentId}
style={{
backgroundColor: effectiveBackgroundColor,
visibility: isLoaded ? "visible" : "hidden",
}}
>
<Scroller
documentId={activeDocumentId}
renderPage={({ width, height, pageIndex }) => (
<div
style={{ width, height }}
onClick={(e) => e.stopPropagation()}
>
<RenderLayer documentId={activeDocumentId} pageIndex={pageIndex} />
</div>
)}
/>
</Viewport>
</>
)}
</DocumentContent>
{!hideControls && (!isMobile || isFullscreen) && (
<Controls
documentId={activeDocumentId}
Expand All @@ -542,6 +544,7 @@ if (isLoading || !engine) {
forceMobile={false}
isMobile={isMobile}
isSmall={isSmall}
viewerRef={viewerRef}
/>
)}
</>
Expand Down
6 changes: 4 additions & 2 deletions src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
container?: HTMLElement | null
}
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogPortal container={props.container}>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
Expand Down
Loading