Merge branch 'better-documents'

This commit is contained in:
Youwen Wu 2024-02-15 02:43:59 -08:00
commit 76decf8237
3 changed files with 25 additions and 11 deletions

View file

@ -23,10 +23,18 @@ export default function News() {
</div>
<ul className='text-slate-50 px-6 list-disc'>
<li key={1}>
eeXiv 2.1 has been released! Documents are now statically generated
for instant loading speeds.{' '}
eeXiv 2.2 has been released! You can now select document version and
export as BibTex.{' '}
</li>
<li key={2}>
We are working on becoming a{' '}
<a
href='https://www.doi.org/the-foundation/about-us/'
target='_blank'
>
ISO 26324 DOI registry!
</a>
</li>
<li key={2}>Mobile support is currently in beta.</li>
<li key={3}>
eeXiv is currently under active development! There may be major
updates, breaking changes, or weird bugs. Report bugs, suggest new

View file

@ -1,5 +1,11 @@
import { Document, Author, Affiliation, Topic, Nationality } from './data'
/**
* Loads a document with the given ID using a web worker if available, and returns a promise that resolves with the document.
*
* @param {string} id - The ID of the document to load
* @return {Promise<Document>} A promise that resolves with the loaded document, or rejects with an error
*/
export const loadDocument = (id: string): Promise<Document> => {
return new Promise((resolve, reject) => {
if (typeof Worker !== 'undefined') {
@ -8,13 +14,12 @@ export const loadDocument = (id: string): Promise<Document> => {
{ type: 'module' }
)
worker.onmessage = (e: MessageEvent<{ [key: string]: Document }>) => {
worker.onmessage = (e: MessageEvent<Document | undefined>) => {
const data = e.data
const doc: Document | undefined = data[id]
if (!doc) {
if (!data) {
return reject(new Error('404'))
} else {
resolve(doc)
resolve(data)
}
worker.terminate()
}
@ -24,7 +29,7 @@ export const loadDocument = (id: string): Promise<Document> => {
worker.terminate()
}
worker.postMessage('LOAD')
worker.postMessage(id)
} else {
reject(
new Error(
@ -34,6 +39,9 @@ export const loadDocument = (id: string): Promise<Document> => {
}
})
}
/**
* @deprecated This function doesn't improve efficiency and shouldn't be used
*/
export const loadAllDocuments = (): Promise<{ [key: string]: Document }> => {
return new Promise((resolve, reject) => {
if (typeof Worker !== 'undefined') {

View file

@ -1,7 +1,5 @@
import { documents } from '../data'
onmessage = (e) => {
if (e.data === 'LOAD') {
self.postMessage(documents)
}
typeof e.data === 'string' && postMessage(documents[e.data])
}