diff --git a/src/app/db/loaders.ts b/src/app/db/loaders.ts index 7f5ecea..563e4ea 100644 --- a/src/app/db/loaders.ts +++ b/src/app/db/loaders.ts @@ -88,7 +88,7 @@ export const loadAllAuthors = (): Promise<{ [key: string]: Author }> => { }) } -export const loadAuthor = (id: string): Promise => { +export const loadAuthors = (authorIds: string[]): Promise => { return new Promise((resolve, reject) => { if (typeof Worker !== 'undefined') { const worker = new Worker( diff --git a/src/app/db/workers/authorLoader.worker.ts b/src/app/db/workers/authorLoader.worker.ts index 4ec63fe..99fd243 100644 --- a/src/app/db/workers/authorLoader.worker.ts +++ b/src/app/db/workers/authorLoader.worker.ts @@ -1,7 +1,18 @@ -import { authors } from '../data' +import { authors, Author } from '../data' + +const checkIsStringArray = (data: unknown): data is string[] => { + if (Array.isArray(data)) { + return data.every((d) => typeof d === 'string') + } + return false +} onmessage = (e) => { - if (e.data === 'LOAD') { - self.postMessage(authors) - } + let authorIds: string[] = [] + let authors = [] + checkIsStringArray(e.data) && (authorIds = e.data as string[]) + + authorIds.forEach(id => { + + }) } diff --git a/src/app/document/view/[slug]/VersionChooser.tsx b/src/app/document/view/[slug]/VersionChooser.tsx index e9c7757..70f532e 100644 --- a/src/app/document/view/[slug]/VersionChooser.tsx +++ b/src/app/document/view/[slug]/VersionChooser.tsx @@ -1,5 +1,5 @@ 'use client' -import { useState } from 'react' +import { useState, useEffect } from 'react' import { Document } from '@/app/db/data' import Link from 'next/link' import { loadAllAuthors } from '@/app/db/loaders' @@ -18,8 +18,10 @@ const VersionChooser = ({ }, }) if (error) throw error - - let authorList = data + + useEffect(() => { + console.log(data) + }, [data]) const { file } = doc const { authors, latest } = doc.manifest @@ -52,7 +54,7 @@ const VersionChooser = ({ const bibtex = `@article{ author={${authors .map((a: string, i) => { - const author = authorList[a].name.first + ' ' + authorList[a].name.last + const author = data[a].name.first + ' ' + data[a].name.last if (i === 0) return author else if (i === authors.length - 1) return ` and ${author}` else return `, ${author}`