From ea3856e1aba72bc4eb2deca07135ef4e9b019cab Mon Sep 17 00:00:00 2001 From: Nizreenana Date: Wed, 17 Jul 2024 18:58:48 +0200 Subject: [PATCH] FEATURE: Comment or adapt a document with an existing document (closes #219). --- frontend/src/components/BrowseTools.js | 2 +- frontend/src/components/DocumentList.js | 44 +++++++++++++++++++++ frontend/src/components/DocumentsCards.js | 4 +- frontend/src/components/ExistingDocument.js | 41 +++++++++++++++++++ frontend/src/components/FutureDocument.js | 28 +++++++++++-- frontend/src/index.js | 2 +- frontend/src/routes/Lectern.js | 4 +- frontend/src/styles/FutureDocument.css | 6 ++- samples/perrault_bintizulkiflee.json | 1 + 9 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 frontend/src/components/DocumentList.js create mode 100644 frontend/src/components/ExistingDocument.js diff --git a/frontend/src/components/BrowseTools.js b/frontend/src/components/BrowseTools.js index 0fef3870..163eaa94 100644 --- a/frontend/src/components/BrowseTools.js +++ b/frontend/src/components/BrowseTools.js @@ -10,7 +10,7 @@ function BrowseTools({id, closable, openable, editable, focusable = true}) { } {closable && - + } diff --git a/frontend/src/components/DocumentList.js b/frontend/src/components/DocumentList.js new file mode 100644 index 00000000..08e84e54 --- /dev/null +++ b/frontend/src/components/DocumentList.js @@ -0,0 +1,44 @@ +import { Card } from 'react-bootstrap'; +import { useState, useEffect } from 'react'; +import ExistingDocument from './ExistingDocument'; + +function DocumentList({ relatedTo, setSelectedDocument, setShowDocumentList, setLastUpdate, backend, user }) { + const [userDocuments, setUserDocuments] = useState([]); + const [searchQuery, setSearchQuery] = useState(''); + + const handleSearchChange = (event) => { + setSearchQuery(event.target.value); + }; + + const filteredDocuments = userDocuments.filter(({dc_title}) => + dc_title?.toLowerCase().includes(searchQuery.toLowerCase()) + ); + + useEffect(() => { + backend.refreshDocuments(setUserDocuments); + }, [user]); + + return ( + <> + + + + + + {filteredDocuments.map(document => ( + + ))} + + ); +} + +export default DocumentList; diff --git a/frontend/src/components/DocumentsCards.js b/frontend/src/components/DocumentsCards.js index 4a721f2c..80d0962d 100644 --- a/frontend/src/components/DocumentsCards.js +++ b/frontend/src/components/DocumentsCards.js @@ -8,7 +8,7 @@ import FutureDocument from './FutureDocument'; import { TypeBadge } from './Type'; // asSource is a flag that indicates whether to create a parent (left) or a glose (right) -function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backend, asSource = false}) { +function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backend, user, asSource = false}) { return ( {docs.map(x => x._id && @@ -20,7 +20,7 @@ function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backe - + {(!asSource && createOn.length > 0) && diff --git a/frontend/src/components/ExistingDocument.js b/frontend/src/components/ExistingDocument.js new file mode 100644 index 00000000..cb4cd4c4 --- /dev/null +++ b/frontend/src/components/ExistingDocument.js @@ -0,0 +1,41 @@ +import Card from 'react-bootstrap/Card'; +import { useNavigate } from 'react-router-dom'; + +function ExistingDocument({ document, relatedTo, setLastUpdate, backend, setShowDocumentList }) { + const navigate = useNavigate(); + const title = extractSubstring(document.dc_title || 'Untitled Document'); + + const handleClick = async () => { + backend.putDocument({ + ...document, + links: [...document.links || [], { verb: 'refersTo', object: relatedTo[0] }] + }).then(() => { + setLastUpdate(document._id); + navigate('#' + document._id); + }).catch(console.error); + + setShowDocumentList(false); + }; + + return ( + + + {title} + + + ); +} + +function extractSubstring(str) { + if (str.includes('–')) { + str = str.split('–')[0]; + } + + if (str.length > 25) { + str = str.substring(0, 25) + '...'; + } + + return str; +} + +export default ExistingDocument; diff --git a/frontend/src/components/FutureDocument.js b/frontend/src/components/FutureDocument.js index 51228875..66e7ca00 100644 --- a/frontend/src/components/FutureDocument.js +++ b/frontend/src/components/FutureDocument.js @@ -1,13 +1,16 @@ import '../styles/FutureDocument.css'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { Card, Form} from 'react-bootstrap'; -import { PlusLg, FolderPlus } from 'react-bootstrap-icons'; +import { PlusLg, Link, FolderPlus } from 'react-bootstrap-icons'; import { v4 as uuid } from 'uuid'; +import DocumentList from './DocumentList'; -function FutureDocument({relatedTo, verb = 'refersTo', setLastUpdate, backend, asSource = false}) { +function FutureDocument({relatedTo, verb = 'refersTo', setLastUpdate, backend, user, asSource = false}) { const [selectedVerb, setSelectedVerb] = useState(verb); + const [showDocumentList, setShowDocumentList] = useState(false); + const [selectedDocument, setSelectedDocument] = useState(null); const fixedType = relatedTo.length === 0 || verb === 'includes' || asSource; const handleSelectChange = (event) => { @@ -23,8 +26,25 @@ function FutureDocument({relatedTo, verb = 'refersTo', setLastUpdate, backend, a )} - + + {!fixedType && ( + setShowDocumentList(!showDocumentList)} + /> + )} + {showDocumentList && ( + + + + )} ); } diff --git a/frontend/src/index.js b/frontend/src/index.js index 05bff3c8..7feeee95 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -39,7 +39,7 @@ function App() { } /> } /> - } /> + } /> diff --git a/frontend/src/routes/Lectern.js b/frontend/src/routes/Lectern.js index e2624591..7214c7a0 100644 --- a/frontend/src/routes/Lectern.js +++ b/frontend/src/routes/Lectern.js @@ -8,7 +8,7 @@ import { useParams, useLocation } from 'react-router-dom'; import OpenedDocuments from '../components/OpenedDocuments'; import DocumentsCards from '../components/DocumentsCards'; -function Lectern({backend}) { +function Lectern({backend, user}) { const [lectern, setLectern] = useState([]); const [metadata, setMetadata] = useState([]); @@ -90,7 +90,7 @@ function Lectern({backend}) { - + 0} diff --git a/frontend/src/styles/FutureDocument.css b/frontend/src/styles/FutureDocument.css index c853bab0..346f1c20 100644 --- a/frontend/src/styles/FutureDocument.css +++ b/frontend/src/styles/FutureDocument.css @@ -1,3 +1,7 @@ -.icon { +.icon, .existingDocument { cursor: pointer; } + +.link-icon { + font-size: 28px; +} diff --git a/samples/perrault_bintizulkiflee.json b/samples/perrault_bintizulkiflee.json index ed2b38b3..931ef9c7 100644 --- a/samples/perrault_bintizulkiflee.json +++ b/samples/perrault_bintizulkiflee.json @@ -10,5 +10,6 @@ "verb": "isTranslationOf", "object": "420ab198674f11eda3b7a3fdd5ea984f" }], + "editors": ["alice"], "text": "{1} Once upon a time were a widow and her two daughters." } \ No newline at end of file