mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	error handling and linting
This commit is contained in:
		
							parent
							
								
									85de881181
								
							
						
					
					
						commit
						6e6ee93282
					
				@ -38,15 +38,15 @@ function reducer(state, { type, payload, meta }) {
 | 
				
			|||||||
      const { eventId } = payload;
 | 
					      const { eventId } = payload;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return produce(state, (draftState) => {
 | 
					      return produce(state, (draftState) => {
 | 
				
			||||||
        Object.keys(draftState.queries).map(function (url, index) {
 | 
					        Object.keys(draftState.queries).map((url, index) => {
 | 
				
			||||||
          // If no url or data has no array length then just return state.
 | 
					          // If data has no array length then just return state.
 | 
				
			||||||
          if (!(url in draftState.queries) || !draftState.queries[url].data.length) return state;
 | 
					          if (!('data' in draftState.queries[url]) || !draftState.queries[url].data.length) return state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          //Find the index to remove
 | 
					          //Find the index to remove
 | 
				
			||||||
          const removeIndex = draftState.queries[url].data.map((event) => event.id).indexOf(eventId);
 | 
					          const removeIndex = draftState.queries[url].data.map((event) => event.id).indexOf(eventId);
 | 
				
			||||||
          if (removeIndex === -1) return;
 | 
					          if (removeIndex === -1) return state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // We need to keep track of deleted items, This will be used to calculate "ReachEnd" for auto load new events. Events.jsx
 | 
					          // We need to keep track of deleted items, This will be used to re-calculate "ReachEnd" for auto load new events. Events.jsx
 | 
				
			||||||
          const totDeleted = state.queries[url].deleted || 0;
 | 
					          const totDeleted = state.queries[url].deleted || 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // Splice the deleted index.
 | 
					          // Splice the deleted index.
 | 
				
			||||||
@ -120,7 +120,7 @@ export function useDelete() {
 | 
				
			|||||||
  const { dispatch, state } = useContext(Api);
 | 
					  const { dispatch, state } = useContext(Api);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async function deleteEvent(eventId) {
 | 
					  async function deleteEvent(eventId) {
 | 
				
			||||||
    if (!eventId) return { success: false };
 | 
					    if (!eventId) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const response = await fetch(`${state.host}/api/events/${eventId}`, { method: 'DELETE' });
 | 
					    const response = await fetch(`${state.host}/api/events/${eventId}`, { method: 'DELETE' });
 | 
				
			||||||
    await dispatch({ type: 'DELETE', payload: { eventId } });
 | 
					    await dispatch({ type: 'DELETE', payload: { eventId } });
 | 
				
			||||||
 | 
				
			|||||||
@ -42,7 +42,7 @@ export default function Event({ eventId }) {
 | 
				
			|||||||
      setShowDialog(false);
 | 
					      setShowDialog(false);
 | 
				
			||||||
      route('/events', true);
 | 
					      route('/events', true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }, [eventId, setShowDialog]);
 | 
					  }, [eventId, setShowDialog, setDeleteEvent]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (status !== FetchStatus.LOADED) {
 | 
					  if (status !== FetchStatus.LOADED) {
 | 
				
			||||||
    return <ActivityIndicator />;
 | 
					    return <ActivityIndicator />;
 | 
				
			||||||
@ -66,7 +66,7 @@ export default function Event({ eventId }) {
 | 
				
			|||||||
            title="Delete Event?"
 | 
					            title="Delete Event?"
 | 
				
			||||||
            text={
 | 
					            text={
 | 
				
			||||||
              deleteStatus === FetchStatus.ERROR
 | 
					              deleteStatus === FetchStatus.ERROR
 | 
				
			||||||
                ? 'Could not delete event, please try again.'
 | 
					                ? 'An error occurred, please try again.'
 | 
				
			||||||
                : 'This event will be permanently deleted along with any related clips and snapshots'
 | 
					                : 'This event will be permanently deleted along with any related clips and snapshots'
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            actions={[
 | 
					            actions={[
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user