import { useAppDispatch } from 'soapbox/hooks'; import { dismissEntities } from '../actions'; type EntityPath = [entityType: string, listKey: string] type DismissFn = (entityId: string) => Promise | T; /** * Removes an entity from a specific list. * To remove an entity globally from all lists, see `useDeleteEntity`. */ function useDismissEntity(path: EntityPath, dismissFn: DismissFn) { const [entityType, listKey] = path; const dispatch = useAppDispatch(); // TODO: optimistic dismissing return async function dismissEntity(entityId: string): Promise { const result = await dismissFn(entityId); dispatch(dismissEntities([entityId], entityType, listKey)); return result; }; } export { useDismissEntity };