-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Comment or adapt a document with an existing document (closes …
…#219).
- Loading branch information
1 parent
eaec084
commit ea3856e
Showing
9 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<Card className="h-100"> | ||
<Card.Body> | ||
<input | ||
type="text" | ||
placeholder="Search documents" | ||
value={searchQuery} | ||
onChange={handleSearchChange} | ||
className="form-control" | ||
/> | ||
</Card.Body> | ||
</Card> | ||
{filteredDocuments.map(document => ( | ||
<ExistingDocument key={document._id} | ||
{...{document, relatedTo, setSelectedDocument, setShowDocumentList, | ||
setLastUpdate, backend}} | ||
/> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
export default DocumentList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Card onClick={handleClick} className="existingDocument documentList"> | ||
<Card.Body> | ||
<span>{title}</span> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
|
||
function extractSubstring(str) { | ||
if (str.includes('–')) { | ||
str = str.split('–')[0]; | ||
} | ||
|
||
if (str.length > 25) { | ||
str = str.substring(0, 25) + '...'; | ||
} | ||
|
||
return str; | ||
} | ||
|
||
export default ExistingDocument; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.icon { | ||
.icon, .existingDocument { | ||
cursor: pointer; | ||
} | ||
|
||
.link-icon { | ||
font-size: 28px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters