Skip to content

Commit 74f39eb

Browse files
authored
Merge pull request #500 from CodeChefVIT/temp_update_staging
Temp update staging
2 parents 9833bcc + 8087d92 commit 74f39eb

4 files changed

Lines changed: 163 additions & 65 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Our top maintainers, making sure the database of papers is maintained and upto-d
106106
<img src="https://github.com/AqViolet.png?size=200" width="140" height="140" alt="~Heet avatar" />
107107
</a>
108108
<br />
109-
<b>Heet Jatnia</b>
109+
<b>Heet Jatania</b>
110110
<br />
111111
<a href="https://github.com/AqViolet" title="GitHub: AqViolet">
112112
<img src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg" width="24" height="24" alt="GitHub icon" />

src/app/layout.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,17 @@ export default function RootLayout({
102102
/>
103103
<head>
104104
<Script
105-
id="google-tag-manager"
106-
strategy="afterInteractive"
107-
dangerouslySetInnerHTML={{
108-
__html: `
109-
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
110-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
111-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
112-
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
113-
})(window,document,'script','dataLayer','GTM-P32GFLD5');
114-
`,
115-
}}
116-
/>
105+
async
106+
src="https://www.googletagmanager.com/gtag/js?id=G-J5CD036GJP"
107+
></Script>
108+
<Script id="google-analytics">
109+
{`window.dataLayer = window.dataLayer || [];
110+
function gtag(){dataLayer.push(arguments);}
111+
gtag('js', new Date());
112+
gtag('config', 'G-J5CD036GJP');`}
113+
</Script>
117114
</head>
118115
<body>
119-
<noscript>
120-
<iframe
121-
src={`https://www.googletagmanager.com/ns.html?id=GTM-P32GFLD5`}
122-
height="0"
123-
width="0"
124-
style={{display: 'none', visibility: 'hidden'}}
125-
/>
126-
</noscript>
127116
<ThemeProvider
128117
attribute="class"
129118
defaultTheme="dark"

src/components/Card.tsx

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import React from "react";
44
import { type IPaper } from "@/interface";
55
import Image from "next/image";
6-
import { X } from "lucide-react";
7-
import { Eye, Download, Check } from "lucide-react";
6+
import { X, Eye, Download, Check } from "lucide-react";
87
import {
98
extractBracketContent,
109
extractWithoutBracketContent,
@@ -16,6 +15,8 @@ import {
1615
} from "@/lib/utils/download";
1716
import { Capsule } from "@/components/ui/capsule";
1817
import { cn } from "@/lib/utils";
18+
import PDFViewer from "@/components/newPdfViewer";
19+
import { PaperProvider } from "@/context/PaperContext";
1920

2021
interface CardProps {
2122
paper: IPaper;
@@ -26,7 +27,18 @@ interface CardProps {
2627

2728
const Card = ({ paper, onSelect, isSelected, isShow=true }: CardProps) => {
2829
const [previewOpen, setPreviewOpen] = React.useState(false);
29-
const [iframeLoading, setIframeLoading] = React.useState(true);
30+
31+
React.useEffect(() => {
32+
if (!previewOpen) return;
33+
34+
const originalOverflow = document.body.style.overflow;
35+
document.body.style.overflow = "hidden";
36+
37+
return () => {
38+
document.body.style.overflow = originalOverflow;
39+
};
40+
}, [previewOpen]);
41+
3042
const handleDownload = async (paper: IPaper) => {
3143
await downloadFile(getSecureUrl(paper.file_url), generateFileName(paper));
3244
};
@@ -86,7 +98,6 @@ const Card = ({ paper, onSelect, isSelected, isShow=true }: CardProps) => {
8698
className="cursor-pointer transition-all duration-200 ease-out hover:scale-110"
8799
onClick={(e) => {
88100
e.stopPropagation();
89-
setIframeLoading(true);
90101
setPreviewOpen(true);
91102
}}
92103
/>
@@ -127,31 +138,42 @@ const Card = ({ paper, onSelect, isSelected, isShow=true }: CardProps) => {
127138

128139
{previewOpen && (
129140
<div
130-
className="fixed inset-0 z-50 flex items-center justify-center bg-black/80"
141+
className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 px-6 py-8"
131142
onClick={() => setPreviewOpen(false)}
132143
>
133144
<div
134-
className="relative w-[95%] max-w-5xl h-[90vh] rounded-lg bg-white p-2 dark:bg-[#171720]"
135-
onClick={(e) => e.stopPropagation()}
145+
className="relative h-full w-full max-w-5xl"
136146
>
137147
<div
138-
className={`absolute inset-0 z-50 flex items-center justify-center bg-[#070114] transition-opacity duration-300 ${
139-
iframeLoading ? "opacity-100" : "opacity-0 pointer-events-none"
140-
}`}
148+
className="relative mx-auto h-full max-w-[760px]"
141149
>
142-
<div className="w-7 h-7 rounded-full border-2 border-white/20 border-t-white animate-spin" />
143-
</div>
144-
<button
145-
className="absolute top-3 left-6 z-50 p-2 rounded-full bg-black/60 text-white hover:bg-black transition"
146-
onClick={() => setPreviewOpen(false)}
147-
>
148-
<X size={18} />
149-
</button>
150-
<iframe
151-
src={`${getSecureUrl(paper.file_url)}#toolbar=0`}
152-
className="w-full h-full rounded-md"
153-
onLoad={() => setIframeLoading(false)}
154-
/>
150+
<PaperProvider
151+
value={{
152+
paperId: paper._id,
153+
subject: paper.subject,
154+
exam: paper.exam,
155+
slot: paper.slot,
156+
year: paper.year,
157+
}}
158+
>
159+
<button
160+
className="fixed right-4 top-4 z-[60] rounded-full border border-black/10 bg-white/95 p-2 text-black shadow-md transition hover:bg-white"
161+
onClick={() => setPreviewOpen(false)}
162+
aria-label="Close preview"
163+
>
164+
<X size={18} />
165+
</button>
166+
<PDFViewer
167+
url={getSecureUrl(paper.file_url)}
168+
name={generateFileName(paper).replace(/\.[^.]+$/, "")}
169+
className="h-full overflow-hidden"
170+
height="100%"
171+
hideControls={true}
172+
backgroundColor="transparent"
173+
hideScrollbar={true}
174+
/>
175+
</PaperProvider>
176+
</div>
155177
</div>
156178
</div>
157179
)}

src/components/newPdfViewer.tsx

Lines changed: 108 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { downloadFile } from "../lib/utils/download";
1515
import { Button } from "./ui/button";
1616
import ShareButton from "./ShareButton";
1717
import ReportButton from "./ReportButton";
18+
import { useTheme } from "next-themes";
1819

1920
interface ControlProps {
2021
documentId: string;
@@ -29,6 +30,12 @@ interface ControlProps {
2930
interface PdfViewerProps {
3031
url: string;
3132
name: string;
33+
className?: string;
34+
height?: string;
35+
hideControls?: boolean;
36+
backgroundColor?: string;
37+
hideScrollbar?: boolean;
38+
isolateFromTheme?: boolean;
3239
}
3340

3441
interface WheelZoomProps {
@@ -328,25 +335,48 @@ const LOADING_MESSAGES = [
328335
"Almost there",
329336
];
330337

331-
export function Loader() {
338+
export function Loader({
339+
backgroundColor = "#070114",
340+
textColor = "rgba(255,255,255,0.5)",
341+
}: {
342+
backgroundColor?: string;
343+
textColor?: string;
344+
}) {
332345
const { message, visible } = useLoadingMessage(LOADING_MESSAGES);
333346
return (
334-
<div className="flex flex-col items-center justify-center gap-3 h-dvh w-full bg-[#070114]">
347+
<div
348+
className="flex h-dvh w-full flex-col items-center justify-center gap-3"
349+
style={{ backgroundColor }}
350+
>
335351
<div className="w-7 h-7 rounded-full border-2 border-white/10 border-t-white animate-spin" />
336352
<span
337-
className="text-white/50 text-sm tracking-wide transition-opacity duration-400"
338-
style={{ opacity: visible ? 1 : 0 }}
353+
className="text-sm tracking-wide transition-opacity duration-400"
354+
style={{ opacity: visible ? 1 : 0, color: textColor }}
339355
>
340356
{message}
341357
</span>
342358
</div>
343359
);
344360
}
345-
export default function PDFViewer({ url, name }: PdfViewerProps) {
361+
export default function PDFViewer({
362+
url,
363+
name,
364+
className,
365+
height = "100dvh",
366+
hideControls = false,
367+
backgroundColor,
368+
hideScrollbar = false,
369+
isolateFromTheme = true,
370+
}: PdfViewerProps) {
346371
const { engine, isLoading } = usePdfiumEngine();
347-
const {isMobile, isSmall} = useBreakpoint();
372+
const { isMobile, isSmall } = useBreakpoint();
373+
const { resolvedTheme } = useTheme();
348374
const [isFullscreen, setIsFullscreen] = useState(false);
349375
const viewerRef = useRef<HTMLDivElement>(null);
376+
const effectiveBackgroundColor =
377+
backgroundColor ?? (resolvedTheme === "light" ? "#F3F5FF" : "#070114");
378+
const loaderTextColor =
379+
resolvedTheme === "light" ? "rgba(17,24,39,0.6)" : "rgba(255,255,255,0.5)";
350380

351381
const handleDownload = useCallback(async () => {
352382
window.dataLayer?.push({
@@ -389,21 +419,67 @@ export default function PDFViewer({ url, name }: PdfViewerProps) {
389419

390420
if (isLoading || !engine) {
391421
return (
392-
<Loader />
422+
<Loader
423+
backgroundColor={effectiveBackgroundColor}
424+
textColor={loaderTextColor}
425+
/>
393426
);
394427
}
395428

396429
return (
397-
<div
398-
ref={viewerRef}
399-
style={{ height: "100dvh", width: "100%", position: "relative", backgroundColor: "#070114", display: "flex", flexDirection: "column" }}
400-
>
401-
<EmbedPDF engine={engine} plugins={plugins}>
430+
<>
431+
{hideScrollbar && (
432+
<style jsx global>{`
433+
[data-pdf-viewer-scrollbars="hidden"] *,
434+
[data-pdf-viewer-scrollbars="hidden"] {
435+
scrollbar-width: none;
436+
-ms-overflow-style: none;
437+
}
438+
439+
[data-pdf-viewer-scrollbars="hidden"] ::-webkit-scrollbar {
440+
display: none;
441+
width: 0;
442+
height: 0;
443+
}
444+
`}</style>
445+
)}
446+
{isolateFromTheme && (
447+
<style jsx global>{`
448+
[data-pdf-viewer-theme="light"] {
449+
color-scheme: light;
450+
forced-color-adjust: none;
451+
}
452+
453+
[data-pdf-viewer-theme="light"] canvas,
454+
[data-pdf-viewer-theme="light"] img,
455+
[data-pdf-viewer-theme="light"] svg {
456+
filter: none !important;
457+
forced-color-adjust: none;
458+
}
459+
`}</style>
460+
)}
461+
<div
462+
ref={viewerRef}
463+
data-pdf-viewer-theme={isolateFromTheme ? "light" : "inherited"}
464+
data-pdf-viewer-scrollbars={hideScrollbar ? "hidden" : "visible"}
465+
className={className}
466+
style={{
467+
height,
468+
width: "100%",
469+
position: "relative",
470+
backgroundColor: effectiveBackgroundColor,
471+
display: "flex",
472+
flexDirection: "column",
473+
colorScheme: isolateFromTheme ? "light" : undefined,
474+
forcedColorAdjust: isolateFromTheme ? "none" : undefined,
475+
}}
476+
>
477+
<EmbedPDF engine={engine} plugins={plugins}>
402478
{({ activeDocumentId }) =>
403479
activeDocumentId && (
404480
<>
405481
<WheelZoom documentId={activeDocumentId} viewerRef={viewerRef} />
406-
{(isMobile && !isFullscreen) &&
482+
{!hideControls && (isMobile && !isFullscreen) &&
407483
<Controls
408484
documentId={activeDocumentId}
409485
toggleFullscreen={toggleFullscreen}
@@ -421,19 +497,29 @@ if (isLoading || !engine) {
421497
style={{
422498
opacity: isLoaded ? 0 : 1,
423499
pointerEvents: isLoaded ? "none" : "auto",
424-
transition: "opacity 0.3s"
500+
transition: "opacity 0.3s",
501+
backgroundColor: effectiveBackgroundColor,
425502
}}
426503
>
427-
<Loader />
504+
<Loader
505+
backgroundColor={effectiveBackgroundColor}
506+
textColor={loaderTextColor}
507+
/>
428508
</div>
429509
<Viewport
430510
documentId={activeDocumentId}
431-
style={{ backgroundColor: "#070114", visibility: isLoaded ? "visible" : "hidden" }}
511+
style={{
512+
backgroundColor: effectiveBackgroundColor,
513+
visibility: isLoaded ? "visible" : "hidden",
514+
}}
432515
>
433516
<Scroller
434517
documentId={activeDocumentId}
435518
renderPage={({ width, height, pageIndex }) => (
436-
<div style={{ width, height }}>
519+
<div
520+
style={{ width, height }}
521+
onClick={(e) => e.stopPropagation()}
522+
>
437523
<RenderLayer documentId={activeDocumentId} pageIndex={pageIndex} />
438524
</div>
439525
)}
@@ -443,7 +529,7 @@ if (isLoading || !engine) {
443529
)}
444530
</DocumentContent>
445531

446-
{(!isMobile || isFullscreen) && (
532+
{!hideControls && (!isMobile || isFullscreen) && (
447533
<Controls
448534
documentId={activeDocumentId}
449535
toggleFullscreen={toggleFullscreen}
@@ -457,7 +543,8 @@ if (isLoading || !engine) {
457543
</>
458544
)
459545
}
460-
</EmbedPDF>
461-
</div>
546+
</EmbedPDF>
547+
</div>
548+
</>
462549
);
463-
}
550+
}

0 commit comments

Comments
 (0)