import { List } from 'immutable' ; import { BlockedEntry , BlockedHit , BlockedRequester , Requester , SearchResult } from '../types' ; import { DurationUnit , olderThan , youngerThan } from './dates' ; export const blockedHitFromSearchResult = ( hit ) : BlockedHit => ( { groupId : hit . groupId , requester : hit . requester , title : hit . title , dateBlocked : new Date ( ) } ) ; export const createBlockedRequester = ( item ) : BlockedRequester => ( { ... item , dateBlocked : new Date ( ) } ) ; export const blockedAfter = < T extends BlockedEntry > ( now , duration , unit ) => ( entry ) => olderThan ( entry . dateBlocked , duration , now , unit ) ; export const blockedWithin = < T extends BlockedEntry > ( now , duration , unit ) => ( entry ) => youngerThan ( entry . dateBlocked , duration , now , unit ) ; export interface BlocklistProps < T extends BlockedEntry > { readonly blockedEntries : List < T > ; } export const createBlocklistFilterFn = ( searchTerm , searchRegex ) => ( hit ) => hit . groupId === searchTerm || hit . requester . id === searchTerm || searchRegex . test ( hit . title ) || searchRegex . test ( hit . requester . name ) ;