Skip to content

Commit

Permalink
FEATURE: Delete a reference (close #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
LIUC2H5OH committed Jun 9, 2023
1 parent e55a72d commit d924f7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
21 changes: 21 additions & 0 deletions frontend/src/DeleteReferenceButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Button from 'react-bootstrap/Button';
import {useNavigate} from 'react-router-dom';
import {XCircle} from 'react-bootstrap-icons';

function DeleteReferenceButton({doc, ref_id, setLastUpdate, backend}) {
const navigate = useNavigate();
let handleDelete = async () => {
let _id = doc._id;
doc.links = doc.links.filter(link => link.object.toString() !== ref_id.toString());
backend.putDocument(doc).then(() => {
setLastUpdate(_id);
navigate('/' + ref_id);
});
};

return (
<XCircle title="Delete this reference" className="icon delete_reference" onClick={handleDelete}/>
);
}

export default DeleteReferenceButton;
12 changes: 9 additions & 3 deletions frontend/src/DocumentsCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import BrowseTools from './BrowseTools';
import FutureDocument from './FutureDocument';
import FutureCollection from './FutureCollection';
import { TypeBadge } from './Type';
import DeleteReferenceButton from './DeleteReferenceButton';

function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backend}) {
function DocumentsCards({docs, expandable, byRow, isDeletable, createOn, setLastUpdate, backend}) {
return (
<Row className="gy-4">
{docs.map(x =>
<Col key={x._id} md={ byRow && (12 / byRow) }>
<DocumentCard doc={x} expandable={expandable} />
<DocumentCard doc={x} expandable={expandable} isDeletable={isDeletable} ref_id={createOn} {...{setLastUpdate, backend}}/>
</Col>
)}
{createOn &&
Expand All @@ -35,7 +36,7 @@ function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backe
);
}

function DocumentCard({doc, expandable}) {
function DocumentCard({doc, expandable, isDeletable, ref_id, setLastUpdate, backend}) {
const collectionId = useMemo(() => {
if (doc?.links?.length > 1) {
return doc.links.every((item) => {
Expand All @@ -48,6 +49,11 @@ function DocumentCard({doc, expandable}) {

return (
<Card className="h-100">
{isDeletable && (
<Card.Header className="d-flex justify-content-end">
<DeleteReferenceButton doc={doc} ref_id={ref_id} setLastUpdate={setLastUpdate} backend={backend}/>
</Card.Header>
)}
<Card.Body>
<BrowseTools
id={collectionId ? doc.links.length && windowWidth.current < 820 ? doc.links[0].object : doc._id : doc._id}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function References({scholiaMetadata, active, createOn, setLastUpdate, backend})
if (!active) return;
return (
<Col className="gloses" >
<DocumentsCards docs={scholiaMetadata} expandable={true} byRow={1}
<DocumentsCards docs={scholiaMetadata} expandable={true} byRow={1} isDeletable={true}
{...{createOn, setLastUpdate, backend}}
/>
</Col>
Expand Down

0 comments on commit d924f7e

Please sign in to comment.