Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added PDF Download option for Notes #1535

Closed
wants to merge 2 commits into from
Closed
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
148 changes: 85 additions & 63 deletions src/components/BreadCrumbComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import {
BreadcrumbSeparator,
} from '@/components/ui/breadcrumb';
import { FullCourseContent } from '@/db/course';
import { Home } from 'lucide-react';
import { Download, Home } from 'lucide-react';
import Link from 'next/link';
import { useMemo } from 'react';
import { Button } from './ui/button';

export default function BreadCrumbComponent({
rest,
course,
fullCourseContent,
courseContent,
contentType,
isNotion = false,
}: {
fullCourseContent: FullCourseContent[];
rest: string[];
course: any;
contentType: any;
courseContent: any;
isNotion?: boolean;
}) {
const findChildContent = (contents: any, childId: any) => {
for (const content of contents) {
Expand Down Expand Up @@ -56,71 +59,90 @@ export default function BreadCrumbComponent({
}, [rest, fullCourseContent, courseContent, contentType]);

return (
<>
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink className="text-sm text-blue-600" asChild>
<Link href={'/'}>
<Home className="size-4" />
</Link>
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
{generateBreadcrumbs.length > 0 ? (
<BreadcrumbLink className="text-blue-600" asChild>
<Link
href={`/courses/${course.id}`}
className="text-sm font-semibold capitalize text-primary/60"
>
{course.title}
<div className="space-y-4 sm:space-y-0">
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink className="text-sm text-blue-600" asChild>
<Link href={'/'}>
<Home className="size-4" />
</Link>
</BreadcrumbLink>
) : (
<BreadcrumbPage className="text-sm font-semibold capitalize text-primary">
{course.title}
</BreadcrumbPage>
)}
</BreadcrumbItem>
<BreadcrumbSeparator />
{generateBreadcrumbs.map((breadcrumb, index, array) => {
const indexofBreadCrumbId = rest.indexOf(breadcrumb.id.toString());
let finalRouteArray: any[] = [];
if (indexofBreadCrumbId !== -1) {
finalRouteArray = rest.slice(0, indexofBreadCrumbId + 1);
} else {
finalRouteArray = [...rest];
}
return (
<>
{index !== array.length - 1 ? (
<>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
{generateBreadcrumbs.length > 0 ? (
<BreadcrumbLink className="text-blue-600" asChild>
<Link
href={`/courses/${course.id}`}
className="text-sm font-semibold capitalize text-primary/60"
>
{course.title}
</Link>
</BreadcrumbLink>
) : (
<BreadcrumbPage className="text-sm font-semibold capitalize text-primary">
{course.title}
</BreadcrumbPage>
)}
</BreadcrumbItem>
<BreadcrumbSeparator />
{generateBreadcrumbs.map((breadcrumb, index, array) => {
const indexofBreadCrumbId = rest.indexOf(
breadcrumb.id.toString(),
);
let finalRouteArray: any[] = [];
if (indexofBreadCrumbId !== -1) {
finalRouteArray = rest.slice(0, indexofBreadCrumbId + 1);
} else {
finalRouteArray = [...rest];
}
return (
<>
{index !== array.length - 1 ? (
<>
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link
href={`/courses/${course.id}/${finalRouteArray.join('/')}`}
className="text-sm font-semibold capitalize text-primary/60"
>
{breadcrumb?.title}
</Link>
</BreadcrumbLink>
</BreadcrumbItem>
{index + 1 < array.length && <BreadcrumbSeparator />}
</>
) : (
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link
href={`/courses/${course.id}/${finalRouteArray.join('/')}`}
className="text-sm font-semibold capitalize text-primary/60"
>
{breadcrumb?.title}
</Link>
</BreadcrumbLink>
<BreadcrumbPage className="text-sm font-semibold capitalize text-primary">
{breadcrumb.title}
</BreadcrumbPage>
</BreadcrumbItem>
{/* <BreadcrumbSeparator /> */}
{index + 1 < array.length && <BreadcrumbSeparator />}
</>
) : (
<BreadcrumbItem>
<BreadcrumbPage className="text-sm font-semibold capitalize text-primary">
{breadcrumb.title}
</BreadcrumbPage>
</BreadcrumbItem>
)}
</>
);
})}
</BreadcrumbList>
</Breadcrumb>
</>
)}
</>
);
})}
</BreadcrumbList>
</Breadcrumb>

{isNotion && (
<div className="sm:ml-auto">
<Button
size="sm"
variant="outline"
onClick={() =>
window.open(`/pdf/${rest[rest.length - 1]}`, '_blank')
}
className="w-full gap-2 sm:w-auto"
>
Download PDF
<Download className="size-4" />
</Button>
</div>
)}
</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/components/CourseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const CourseView = ({
courseContent={courseContent}
fullCourseContent={fullCourseContent}
rest={rest}
isNotion={!courseContent?.folder && courseContent?.value.type === 'notion'}
/>
</div>

Expand Down
9 changes: 0 additions & 9 deletions src/components/NotionRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import 'prismjs/themes/prism-tomorrow.css';
// used for rendering equations (optional)
import 'katex/dist/katex.min.css';
import { Loader } from './Loader';
// import Link from 'next/link';
// import { Button } from './ui/button';
// import { Download } from 'lucide-react';
import { useTheme } from 'next-themes';
import CodeBlock from './CodeBlock';

Expand All @@ -45,12 +42,6 @@ export const NotionRenderer = ({ id }: { id: string }) => {

return (
<div>
{/* <Link href={`/pdf/${id}`} target="_blank">
<Button size={'lg'} className="gap-2">
Download
<Download className="size-4" />
</Button>
</Link> */}
<div>
<style>
{`
Expand Down
32 changes: 25 additions & 7 deletions src/components/print/PrintNotes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use client';

import useMountStatus from '@/hooks/useMountStatus';
import dynamic from 'next/dynamic';
import { useMemo } from 'react';
import { NotionRenderer as NotionRendererLib } from 'react-notion-x';
import 'react-notion-x/src/styles.css';
import dynamic from 'next/dynamic';
import { Print } from './Print';

const Code = dynamic(() =>
import('react-notion-x/build/third-party/code').then((m) => m.Code),
Expand All @@ -16,28 +19,43 @@ import 'prismjs/themes/prism-tomorrow.css';

// used for rendering equations (optional)
import 'katex/dist/katex.min.css';
import { Print } from './Print';
import useMountStatus from '@/hooks/useMountStatus';

const PrintNotes = ({ recordMap }: { recordMap: any }) => {
const mounted = useMountStatus();

const customComponents = useMemo(() => ({ Code, Equation }), []);

if (!mounted) {
return null;
}

return (
<>
<style jsx global>{`
.notion-code {
font-size: 85% !important;
padding: 1rem !important;
background-color: #f6f8fa !important;
border: 1px solid #e1e4e8 !important;
border-radius: 6px !important;
margin: 1.5em 0 !important;
}
.notion-code-copy-button {
display: none !important;
}
@media print {
.notion-code {
break-inside: avoid;
}
}
`}</style>
<NotionRendererLib
recordMap={recordMap}
fullPage={true}
darkMode={false}
className="z-10"
disableHeader={true}
components={{
Code,
Equation,
}}
components={customComponents}
/>
<Print />
</>
Expand Down
Loading