From 091e363e0c36e7e5f99b317b93d39b9ba1e24718 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 13 Jan 2022 16:34:33 -0700 Subject: [PATCH] Fix render error and add useRetain --- web/src/api/index.jsx | 6 +++--- web/src/routes/Event.jsx | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/api/index.jsx b/web/src/api/index.jsx index 5024096b1..b5ac78b19 100644 --- a/web/src/api/index.jsx +++ b/web/src/api/index.jsx @@ -117,14 +117,14 @@ export function useDelete() { return deleteEvent; } -export function useRetain() { +export function useRetain(shouldRetain) { const { dispatch, state } = useContext(Api); async function retainEvent(eventId) { if (!eventId) return null; - const response = await fetch(`${state.host}/api/events/${eventId}`, { method: 'POST' }); - await dispatch({ type: 'DELETE', payload: { eventId } }); + const response = await fetch(`${state.host}/api/events/${eventId}?retain=${shouldRetain}`, { method: 'POST' }); + await dispatch({ type: 'POST', payload: { eventId } }); return await (response.status < 300 ? response.json() : { success: true }); } diff --git a/web/src/routes/Event.jsx b/web/src/routes/Event.jsx index b05bb7b01..f140de572 100644 --- a/web/src/routes/Event.jsx +++ b/web/src/routes/Event.jsx @@ -14,7 +14,7 @@ import Dialog from '../components/Dialog'; import Heading from '../components/Heading'; import VideoPlayer from '../components/VideoPlayer'; import { Table, Thead, Tbody, Th, Tr, Td } from '../components/Table'; -import { FetchStatus, useApiHost, useEvent, useDelete } from '../api'; +import { FetchStatus, useApiHost, useEvent, useDelete, useRetain } from '../api'; const ActionButtonGroup = ({ className, handleClickRetain, handleClickDelete, close }) => (
@@ -58,6 +58,7 @@ export default function Event({ eventId, close, scrollRef }) { const [showDetails, setShowDetails] = useState(false); const [shouldScroll, setShouldScroll] = useState(true); const [deleteStatus, setDeleteStatus] = useState(FetchStatus.NONE); + const setRetainEvent = useRetain(); const setDeleteEvent = useDelete(); useEffect(() => {