'use client' import { useState } from 'react' import { Document } from '@/app/db/data' import Link from 'next/link' import { loadAuthors } from '@/app/db/loaders' import { useSuspenseQuery } from '@tanstack/react-query' import { epoch2date } from '@/app/utils/epoch2datestring' import { toast } from 'react-toastify' const VersionChooser = ({ doc, slug, }: Readonly<{ doc: Document; slug: string }>) => { const { data, error } = useSuspenseQuery({ queryKey: [doc.manifest.authors.join(' ')], queryFn: () => { const data = loadAuthors(doc.manifest.authors) return data }, }) if (error) throw error const { file } = doc const { authors, latest } = doc.manifest const date = epoch2date(doc.manifest.dates[doc.manifest.dates.length - 1]) const fileEnding = file === 'other' ? '' : `.${file}` const [selectedRevision, setSelectedRevision] = useState(latest) // Initialize the selected revision with the latest revision const notifyCopied = () => toast('BibTeX copied to clipboard!') const handleClick = () => { const bibtex = `@article{ author={${authors .map((a: string, i) => { 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}` }) .join('')}}, title={${doc.manifest.title}}, journal={eeXiv journal}, year={${date.getFullYear()}}, month={${date.toLocaleString('default', { month: 'short' })}}, url={${window.location.href}} }` navigator.clipboard.writeText(bibtex) notifyCopied() } return (
) } export default VersionChooser