Skip to content

Commit

Permalink
FEATURE: Delete a document.
Browse files Browse the repository at this point in the history
  • Loading branch information
benel committed Sep 16, 2024
1 parent 0169054 commit 490d84f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions frontend/src/components/DeleteDocumentAction.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Modal, Button } from 'react-bootstrap';
import DiscreeteDropdown from './DiscreeteDropdown';

function DeleteDocumentAction({metadata, backend, setLastUpdate}) {
const focus = useNavigate('#');
const [show, setShow] = useState(false);

const handleClick = () => {
backend.deleteDocument(metadata)
.then(x => setLastUpdate(x._rev))
.then(focus);
};

return (
<>
<DiscreeteDropdown.Item onClick={() => setShow(true)}>
Delete...
</DiscreeteDropdown.Item>
<Modal show={show} onHide={() => setShow(false)}>
<Modal.Body>
Are you sure you want to delete this document (with all of its contents and metadata).
This action cannot be undone.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShow(false)}>
Cancel
</Button>
<Button variant="primary" onClick={handleClick}>
Delete
</Button>
</Modal.Footer>
</Modal>
</>
);
}

export default DeleteDocumentAction;

2 changes: 2 additions & 0 deletions frontend/src/components/OpenedDocuments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import License from './License';
import DiscreeteDropdown from './DiscreeteDropdown';
import InviteEditorsAction from './InviteEditorsAction';
import BreakIntoPassagesAction from './BreakIntoPassagesAction';
import DeleteDocumentAction from './DeleteDocumentAction';
import Bookmark from './Bookmark';
import LicenseCompatibility from './LicenseCompatibility';

Expand Down Expand Up @@ -68,6 +69,7 @@ function RunningHeadMargin({metadata, lectern, margin, sourceHasRubrics, marginH
<DiscreeteDropdown>
<InviteEditorsAction {...{backend, metadata}} />
<BreakIntoPassagesAction {...{lectern, margin, sourceHasRubrics, marginHasRubrics, backend, setLastUpdate}} />
<DeleteDocumentAction {...{metadata, backend, setLastUpdate}} />
</DiscreeteDropdown>
<Metadata editable={true} {...{backend, metadata, setLastUpdate}} />
<Type editable={true} {...{backend, metadata}}/>
Expand Down

0 comments on commit 490d84f

Please sign in to comment.