From ca693240b136fc53bafc59b0f4d4c4cdd0e9ccc9 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 26 May 2022 09:06:02 -0600 Subject: [PATCH] Favorite events delete button warning (#3225) * Add dialog to shield deletion of favorite event * Use state to keep track of event id * Adjust named * Set color of button --- web/src/routes/Events.jsx | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/web/src/routes/Events.jsx b/web/src/routes/Events.jsx index 4da3bee63..3be927f57 100644 --- a/web/src/routes/Events.jsx +++ b/web/src/routes/Events.jsx @@ -59,6 +59,10 @@ export default function Events({ path, ...props }) { has_snapshot: false, plus_id: undefined, }); + const [deleteFavoriteState, setDeleteFavoriteState] = useState({ + deletingFavoriteEventId: null, + showDeleteFavorite: false, + }); const eventsFetcher = useCallback((path, params) => { params = { ...params, include_thumbnails: 0, limit: API_LIMIT }; @@ -114,11 +118,16 @@ export default function Events({ path, ...props }) { } }; - const onDelete = async (e, eventId) => { + const onDelete = async (e, eventId, saved) => { e.stopPropagation(); - const response = await axios.delete(`events/${eventId}`); - if (response.status === 200) { - mutate(); + + if (saved) { + setDeleteFavoriteState({ deletingFavoriteEventId: eventId, showDeleteFavorite: true }); + } else { + const response = await axios.delete(`events/${eventId}`); + if (response.status === 200) { + mutate(); + } } }; @@ -374,6 +383,19 @@ export default function Events({ path, ...props }) { )} + {deleteFavoriteState.showDeleteFavorite && ( + +
+ Delete Saved Event? +

Confirm deletion of saved event.

+
+
+ +
+
+ )}
{eventPages ? ( eventPages.map((page, i) => { @@ -441,7 +463,7 @@ export default function Events({ path, ...props }) { )}
- onDelete(e, event.id)} /> + onDelete(e, event.id, event.retain_indefinitely)} />