diff --git a/src/app/db/loaders.ts b/src/app/db/loaders.ts new file mode 100644 index 0000000..4f9f58a --- /dev/null +++ b/src/app/db/loaders.ts @@ -0,0 +1,33 @@ +import { Document } from './data' + +// export const loadDocument(id: string): Promise | undefined => { + +// } +export const loadAllDocuments = (): Promise<{ [key: string]: Document }> => { + return new Promise((resolve, reject) => { + if (typeof Worker !== 'undefined') { + const worker = new Worker( + new URL('./workers/documentLoader.worker.ts', import.meta.url), + { type: 'module' } + ) + + worker.onmessage = (e: MessageEvent<{ [key: string]: Document }>) => { + resolve(e.data) + worker.terminate() + } + + worker.onerror = (error) => { + reject(error) + worker.terminate() + } + + worker.postMessage('LOAD') + } else { + reject( + new Error( + 'Web Workers are not supported in this environment. Please avoid using a prehistoric browser.' + ) + ) + } + }) +} diff --git a/src/app/db/workers/documentLoader.worker.ts b/src/app/db/workers/documentLoader.worker.ts new file mode 100644 index 0000000..e19ff6f --- /dev/null +++ b/src/app/db/workers/documentLoader.worker.ts @@ -0,0 +1,7 @@ +import { documents } from '../data' + +onmessage = (e) => { + if (e.data === 'LOAD') { + self.postMessage({ documents }) + } +} diff --git a/src/app/document/view/[slug]/DocumentViewer.tsx b/src/app/document/view/[slug]/DocumentViewer.tsx new file mode 100644 index 0000000..a523bb0 --- /dev/null +++ b/src/app/document/view/[slug]/DocumentViewer.tsx @@ -0,0 +1,101 @@ +import { DocumentType, Document } from '@/app/db/data' +import { Zilla_Slab } from 'next/font/google' +import { epoch2datestring } from '@/app/utils/epoch2datestring' +import { + Code, + References, + Topics, + Authors, + Reviewers, +} from '@/app/components/DataDisplay' +import { ItemBadge, Status } from '@/app/components/Badges' +import Link from 'next/link' + +const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500', '700'] }) + +export default function DocumentViewer({ + doc, + slug, +}: Readonly<{ doc: Document; slug: string }>) { + const { manifest, abstract, file, citation } = doc + const { + title, + authors, + topics, + dates, + references, + code, + type, + latest, + reviewers, + status, + } = manifest + + return ( +
+

+ {title} +

+

+ +

+

+ Latest revision published{' '} + + {epoch2datestring(dates[dates.length - 1])} + +

+ + + + Revision {latest} + +
+

Abstract

+

+ {abstract} +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ Cite as: + {citation ? <>{citation} : <>eeXiv:{slug}} +

+ + + +
+ ) +}