From c62c36238a3ff613a72bdf1e5d0b659b0e824aea Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Mon, 22 Apr 2024 13:54:54 -0500 Subject: [PATCH] add feature: import papers by author --- frontend/src/App.css | 2 +- frontend/src/App.jsx | 7 +++- .../{Import.jsx => ImportPaper.jsx} | 6 +-- .../src/components/ImportPapersByAuthor.jsx | 41 +++++++++++++++++++ .../src/components/posts/ViewPostModal.jsx | 2 +- 5 files changed, 51 insertions(+), 7 deletions(-) rename frontend/src/components/{Import.jsx => ImportPaper.jsx} (93%) create mode 100644 frontend/src/components/ImportPapersByAuthor.jsx diff --git a/frontend/src/App.css b/frontend/src/App.css index 86d9ede..05c5864 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -1,4 +1,4 @@ -.post-content { +.linebreaks { white-space: pre-line; } diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 2728b05..4bc0a59 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -25,7 +25,8 @@ import AddPostModal from './components/posts/AddPostModal'; import ViewPostModal from './components/posts/ViewPostModal'; import Post from './utils/Post'; import Proposals from './components/Proposals'; -import Import from './components/Import'; +import ImportPaper from './components/ImportPaper'; +import ImportPapersByAuthor from './components/ImportPapersByAuthor'; import getAddressName from './utils/get-address-name'; function App() { @@ -575,7 +576,9 @@ function App() { - +

Semantic Scholar Import

+ +
diff --git a/frontend/src/components/Import.jsx b/frontend/src/components/ImportPaper.jsx similarity index 93% rename from frontend/src/components/Import.jsx rename to frontend/src/components/ImportPaper.jsx index 8822188..e6a8b9b 100644 --- a/frontend/src/components/Import.jsx +++ b/frontend/src/components/ImportPaper.jsx @@ -3,7 +3,7 @@ import Button from 'react-bootstrap/Button'; import Form from 'react-bootstrap/Form'; import axios from 'axios'; -function Import() { +function ImportPaper() { const [paperId, setPaperId] = useState(); const [status, setStatus] = useState(''); @@ -22,7 +22,7 @@ function Import() { return ( <> -

Semantic Scholar Import

+

Import Paper

Paper ID @@ -39,4 +39,4 @@ function Import() { ); } -export default Import; +export default ImportPaper; diff --git a/frontend/src/components/ImportPapersByAuthor.jsx b/frontend/src/components/ImportPapersByAuthor.jsx new file mode 100644 index 0000000..cb2e9e9 --- /dev/null +++ b/frontend/src/components/ImportPapersByAuthor.jsx @@ -0,0 +1,41 @@ +import { useState } from 'react'; +import Button from 'react-bootstrap/Button'; +import Form from 'react-bootstrap/Form'; +import axios from 'axios'; + +function ImportPapersByAuthor() { + const [authorId, setAuthorId] = useState(); + const [status, setStatus] = useState(''); + + const handleImport = async () => { + setStatus(`Importing papers by author ${authorId}...`); + const { data: results } = await axios.post('/api/importFromSemanticScholar', { authorId }) + .catch((error) => { + setStatus(`Error: ${error.response?.data ?? error.message}`); + }); + const getStatus = ({ paperId, postId, alreadyAdded }) => (alreadyAdded + ? `Paper ${paperId} was already imported as post ${postId}` + : `Imported paper ${paperId} as post ${postId}`); + setStatus(results.map(getStatus).join('\n')); + }; + + return ( + <> +

Import Papers by Author

+ + + Author ID + setAuthorId(e.target.value)} + /> + + + +

{status}

+ + ); +} + +export default ImportPapersByAuthor; diff --git a/frontend/src/components/posts/ViewPostModal.jsx b/frontend/src/components/posts/ViewPostModal.jsx index 1d7793d..715ad58 100644 --- a/frontend/src/components/posts/ViewPostModal.jsx +++ b/frontend/src/components/posts/ViewPostModal.jsx @@ -37,7 +37,7 @@ function ViewPostModal({ ))}
-

+

{content}