Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   const onClickClear = (inputType?: 'checkbox' | 'radio', queryProps?: string[]) => () => {
  2.     if (!!queryProps) {
  3.       let params = {};
  4.       let updatedQuery = query;
  5.  
  6.       if (inputType === 'radio' || (inputType === 'checkbox' && queryProps.length > 1)) {
  7.         if (inputType === 'radio' && queryProps.length === 1) {
  8.           const {publish, ...rest} = query;
  9.           updatedQuery = rest;
  10.         } else {
  11.           params = queryProps.reduce((acc, prop) => ({...acc, [prop]: false}), {});
  12.           updatedQuery = {...query, ...params};
  13.         }
  14.       } else {
  15.         params = {[queryProps[0]]: []};
  16.         updatedQuery = {...query, ...params};
  17.       }
  18.       onUpdateSearch(updatedQuery);
  19.     } else {
  20.       const initialQuery = initialState.query;
  21.       onUpdateSearch(initialQuery);
  22.     }
  23.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement