Disable post button for 3 seconds max
This commit is contained in:
		
							parent
							
								
									259b5b7a36
								
							
						
					
					
						commit
						f2f205dc80
					
				| @ -1,3 +1,4 @@ | |||||||
|  | import { useState } from 'react'; | ||||||
| import { Form, Input, SubmitButton } from '../components/form' | import { Form, Input, SubmitButton } from '../components/form' | ||||||
| import { useRouter } from 'next/router' | import { useRouter } from 'next/router' | ||||||
| import { gql, useApolloClient, useLazyQuery, useMutation } from '@apollo/client' | import { gql, useApolloClient, useLazyQuery, useMutation } from '@apollo/client' | ||||||
| @ -33,7 +34,8 @@ export function LinkForm ({ item, editThreshold }) { | |||||||
|       ...ItemFields |       ...ItemFields | ||||||
|     } |     } | ||||||
|   }`, {
 |   }`, {
 | ||||||
|     fetchPolicy: 'network-only' |     fetchPolicy: 'network-only', | ||||||
|  |     onCompleted: () => setPostDisabled(false) | ||||||
|   }) |   }) | ||||||
|   const [getRelated, { data: relatedData }] = useLazyQuery(gql` |   const [getRelated, { data: relatedData }] = useLazyQuery(gql` | ||||||
|   ${ITEM_FIELDS} |   ${ITEM_FIELDS} | ||||||
| @ -71,6 +73,8 @@ export function LinkForm ({ item, editThreshold }) { | |||||||
|       }` |       }` | ||||||
|   ) |   ) | ||||||
| 
 | 
 | ||||||
|  |   const [postDisabled, setPostDisabled] = useState(false) | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <Form |     <Form | ||||||
|       initial={{ |       initial={{ | ||||||
| @ -124,10 +128,13 @@ export function LinkForm ({ item, editThreshold }) { | |||||||
|               variables: { url: e.target.value } |               variables: { url: e.target.value } | ||||||
|             }) |             }) | ||||||
|           } |           } | ||||||
|           if (e.target.value) |           if (e.target.value) { | ||||||
|  |             setPostDisabled(true) | ||||||
|  |             setTimeout(() => setPostDisabled(false), 3000) | ||||||
|             getDupes({ |             getDupes({ | ||||||
|               variables: { url: e.target.value } |               variables: { url: e.target.value } | ||||||
|             }) |             }) | ||||||
|  |           } | ||||||
|         }} |         }} | ||||||
|       /> |       /> | ||||||
|       <AdvPostForm edit={!!item} /> |       <AdvPostForm edit={!!item} /> | ||||||
| @ -144,7 +151,7 @@ export function LinkForm ({ item, editThreshold }) { | |||||||
|               /> |               /> | ||||||
|             </div>) |             </div>) | ||||||
|           : <FeeButton |           : <FeeButton | ||||||
|               baseFee={1} parentId={null} text='post' disabled={dupesLoading} |               baseFee={1} parentId={null} text='post' disabled={postDisabled} | ||||||
|               ChildButton={SubmitButton} variant='secondary' |               ChildButton={SubmitButton} variant='secondary' | ||||||
|             />} |             />} | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user