From 7e5649c648a74cb5472d514112b28dbf1224d3f3 Mon Sep 17 00:00:00 2001 From: Team 1280 Programming Laptop <59985235+Team1280Programming@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:42:48 -0800 Subject: [PATCH] in the middle of fixing --- src/app/db/loaders.ts | 2 +- src/app/db/workers/authorLoader.worker.ts | 19 +++++++++++++++---- .../document/view/[slug]/VersionChooser.tsx | 10 ++++++---- 3 files changed, 22 insertions(+), 9 deletions(-) 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}`