From ce107072a4b45cd681c29ad19a9da3c503165abc Mon Sep 17 00:00:00 2001
From: Ananth Venkatesh <46249765+quantum9Innovation@users.noreply.github.com>
Date: Fri, 16 Feb 2024 19:39:26 +0000
Subject: [PATCH] Revamp documents Include new citation hash function, search
by citation hash, toasts, and QR codes
---
package-lock.json | 22 +++++
package.json | 3 +
.../document/view/[slug]/DocumentViewer.tsx | 24 +++--
.../document/view/[slug]/VersionChooser.tsx | 14 ++-
src/app/search/page.tsx | 29 +++++-
src/app/utils/hash.ts | 8 +-
src/app/utils/search.worker.ts | 94 ++++++++++++-------
7 files changed, 147 insertions(+), 47 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 2fa252a..26294ad 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,9 +9,11 @@
"version": "0.1.0",
"dependencies": {
"@tanstack/react-query": "^5.20.2",
+ "fnv-plus": "^1.3.1",
"million": "^3.0.3",
"minisearch": "^6.3.0",
"next": "14.1.0",
+ "qrcode.react": "^3.1.0",
"react": "^18",
"react-dom": "^18",
"react-icons": "^5.0.1",
@@ -23,6 +25,7 @@
"devDependencies": {
"@redux-devtools/extension": "^3.3.0",
"@types/file-saver": "^2.0.7",
+ "@types/fnv-plus": "^1.3.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
@@ -1042,6 +1045,12 @@
"integrity": "sha512-dNKVfHd/jk0SkR/exKGj2ggkB45MAkzvWCaqLUUgkyjITkGNzH8H+yUwr+BLJUBjZOe9w8X3wgmXhZDRg1ED6A==",
"dev": true
},
+ "node_modules/@types/fnv-plus": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/@types/fnv-plus/-/fnv-plus-1.3.2.tgz",
+ "integrity": "sha512-Bgr5yn2dph2q8HZKDS002Pob6vaRTRfhqN9E+TOhjKsJvnfZXULPR3ihH8dL5ZjgxbNhqhTn9hijpbAMPtKZzw==",
+ "dev": true
+ },
"node_modules/@types/json5": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
@@ -2654,6 +2663,11 @@
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
"dev": true
},
+ "node_modules/fnv-plus": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/fnv-plus/-/fnv-plus-1.3.1.tgz",
+ "integrity": "sha512-Gz1EvfOneuFfk4yG458dJ3TLJ7gV19q3OM/vVvvHf7eT02Hm1DleB4edsia6ahbKgAYxO9gvyQ1ioWZR+a00Yw=="
+ },
"node_modules/for-each": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
@@ -4340,6 +4354,14 @@
"node": ">=6"
}
},
+ "node_modules/qrcode.react": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-3.1.0.tgz",
+ "integrity": "sha512-oyF+Urr3oAMUG/OiOuONL3HXM+53wvuH3mtIWQrYmsXoAq0DkvZp2RYUWFSMFtbdOpuS++9v+WAkzNVkMlNW6Q==",
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
diff --git a/package.json b/package.json
index e7ddcd5..cd48a47 100644
--- a/package.json
+++ b/package.json
@@ -11,9 +11,11 @@
},
"dependencies": {
"@tanstack/react-query": "^5.20.2",
+ "fnv-plus": "^1.3.1",
"million": "^3.0.3",
"minisearch": "^6.3.0",
"next": "14.1.0",
+ "qrcode.react": "^3.1.0",
"react": "^18",
"react-dom": "^18",
"react-icons": "^5.0.1",
@@ -25,6 +27,7 @@
"devDependencies": {
"@redux-devtools/extension": "^3.3.0",
"@types/file-saver": "^2.0.7",
+ "@types/fnv-plus": "^1.3.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
diff --git a/src/app/document/view/[slug]/DocumentViewer.tsx b/src/app/document/view/[slug]/DocumentViewer.tsx
index bbd579a..0aeb6f2 100644
--- a/src/app/document/view/[slug]/DocumentViewer.tsx
+++ b/src/app/document/view/[slug]/DocumentViewer.tsx
@@ -14,6 +14,7 @@ import generateHash from '@/app/utils/hash'
import { Suspense } from 'react'
import { loadDocument } from '@/app/db/loaders'
import { useSuspenseQuery } from '@tanstack/react-query'
+import QRCode from 'qrcode.react'
const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] })
@@ -48,15 +49,20 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
return (
-
- {title}
-
+
diff --git a/src/app/document/view/[slug]/VersionChooser.tsx b/src/app/document/view/[slug]/VersionChooser.tsx
index 1dbfe5e..e3aee65 100644
--- a/src/app/document/view/[slug]/VersionChooser.tsx
+++ b/src/app/document/view/[slug]/VersionChooser.tsx
@@ -6,6 +6,7 @@ import { loadAuthors } from '@/app/db/loaders'
import { useSuspenseQuery } from '@tanstack/react-query'
import { epoch2date } from '@/app/utils/epoch2datestring'
import { toast } from 'react-toastify'
+import generateHash from '@/app/utils/hash'
const VersionChooser = ({
doc,
@@ -26,7 +27,7 @@ const VersionChooser = ({
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 notifyCopied = (content: string) => toast.success(`${content} copied to clipboard!`)
const handleClick = () => {
const bibtex = `@article{
@@ -45,7 +46,13 @@ const VersionChooser = ({
url={${window.location.href}}
}`
navigator.clipboard.writeText(bibtex)
- notifyCopied()
+ notifyCopied('BibTeX')
+ }
+
+ const handleCopy = () => {
+ const id = doc.citation ? doc.citation : generateHash(slug)
+ navigator.clipboard.writeText(`eeXiv:${id}`)
+ notifyCopied('Citation')
}
return (
@@ -75,6 +82,9 @@ const VersionChooser = ({
+