Skip to content

Commit

Permalink
added functionality to delete title
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfang97 committed Feb 2, 2024
1 parent fc31dfe commit 46ca8ec
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions frontend/components/Viewing/ViewHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function ViewHeader(properties) {
});
};

const confirmDeletion = () => {
const confirmDescriptionDeletion = () => {
// Show a confirmation dialog
const userConfirmed = window.confirm("Do you want to delete this description?");

Expand All @@ -80,6 +80,18 @@ export default function ViewHeader(properties) {
}
};

const confirmTitleDeletion = () => {
// Show a confirmation dialog
const userConfirmed = window.confirm("Do you want to delete this description?");

if (userConfirmed) {
// User clicked "OK"
deleteTitle();
} else {
// User clicked "Cancel", do nothing
}
};

const deleteDescription = () => {
axios.post(`${objectUri}/remove/description`, {
object: properties.description
Expand All @@ -100,6 +112,26 @@ export default function ViewHeader(properties) {
});
};

const deleteTitle = () => {
axios.post(`${objectUri}/remove/title`, {
object: properties.name
}, {
headers: {
"Accept": "text/plain; charset=UTF-8",
"X-authorization": token
}
})
.then(response => {
// Successfully deleted the description, now reset the relevant states
setDisplayedTitle(''); // Reset the displayed description
setEditedTitle('');
setIsEditingTitle(false); // Exit edit mode if it's active
})
.catch(error => {
console.error('Error removing description:', error);
});
};


const handleSaveTitle = () => {
// Axios POST request to save edited title
Expand Down Expand Up @@ -151,6 +183,18 @@ export default function ViewHeader(properties) {
onClick={handleEditClick}
className={styles.editIcon}
/>
{properties.name.length > 0 && (
<FontAwesomeIcon
icon={faTrash}
size="1x"
className={styles.deleteIcon}
title="Remove title"
onClick={(e) => {
e.stopPropagation();
confirmTitleDeletion();
}}
/>
)}
</>
)
}
Expand Down Expand Up @@ -211,7 +255,7 @@ export default function ViewHeader(properties) {
title="Remove description"
onClick={(e) => {
e.stopPropagation();
confirmDeletion();
confirmDescriptionDeletion();
}}
/>
)}
Expand Down

0 comments on commit 46ca8ec

Please sign in to comment.