-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from nimit9/feat/notes-download
feat: downloading notes
- Loading branch information
Showing
7 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NotionAPI } from 'notion-client'; | ||
import db from '@/db'; | ||
const notion = new NotionAPI(); | ||
import PrintNotes from '@/components/print/PrintNotes'; | ||
|
||
export default async function PrintNotion({ | ||
params: { contentId }, | ||
}: { | ||
params: { contentId: string }; | ||
}) { | ||
const notionMetadata = await db.notionMetadata.findFirst({ | ||
where: { | ||
contentId: parseInt(contentId, 10), | ||
}, | ||
}); | ||
|
||
if (notionMetadata?.notionId) { | ||
const recordMap = await notion.getPage(notionMetadata?.notionId); | ||
return <PrintNotes recordMap={recordMap} />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use client'; | ||
import { useEffect } from 'react'; | ||
|
||
export function Print() { | ||
// Some hack for strict mode | ||
let opened = false; | ||
useEffect(() => { | ||
if (opened) return; | ||
|
||
// Adjusting padding and margins for print | ||
document.querySelectorAll('details').forEach((e) => (e.open = true)); | ||
document.querySelectorAll('header').forEach((e) => { | ||
e.style.display = 'none'; | ||
}); | ||
document.querySelectorAll('main').forEach((e) => { | ||
e.style.padding = '0px'; | ||
e.style.margin = '0px'; | ||
}); | ||
document.querySelectorAll('.notion-title').forEach((e: any) => { | ||
e.style.marginBottom = '0px'; | ||
}); | ||
|
||
setTimeout(() => { | ||
print(); | ||
opened = true; | ||
window.close(); | ||
}, 2000); | ||
}, []); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { NotionRenderer as NotionRendererLib } from 'react-notion-x'; | ||
import 'react-notion-x/src/styles.css'; | ||
import dynamic from 'next/dynamic'; | ||
|
||
const Code = dynamic(() => | ||
import('react-notion-x/build/third-party/code').then((m) => m.Code), | ||
); | ||
const Equation = dynamic(() => | ||
import('react-notion-x/build/third-party/equation').then((m) => m.Equation), | ||
); | ||
|
||
// used for code syntax highlighting (optional) | ||
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(); | ||
|
||
if (!mounted) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<NotionRendererLib | ||
recordMap={recordMap} | ||
fullPage={true} | ||
darkMode={false} | ||
className="z-10" | ||
components={{ | ||
Code, | ||
Equation, | ||
}} | ||
/> | ||
<Print /> | ||
</> | ||
); | ||
}; | ||
|
||
export default PrintNotes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
const useMountStatus = () => { | ||
const [mounted, setMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
|
||
return mounted; | ||
}; | ||
|
||
export default useMountStatus; |