import { useAppDispatch } from 'soapbox/hooks'; import { dismissEntities } from '../actions'; import { parseEntitiesPath } from './utils'; import type { ExpandedEntitiesPath } from './types'; 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(expandedPath: ExpandedEntitiesPath, dismissFn: DismissFn) { const { entityType, listKey } = parseEntitiesPath(expandedPath); 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 };