Skip to main content

Posts

Showing posts with the label promise

upload to storage with promise (helper) instead of hook (useUploadStorage)

export const uploadFileToStorage = async ( foldName: string, dataUrl: string ) => { return new Promise((resolve, reject) => { const timestamp = Number( new Date()) const fileName = `/documents/ ${ foldName } - ${ timestamp.toString() } ` const storageRef = firebaseApp.storage().ref(fileName) const uploadTask = storageRef.putString(dataUrl, 'data_url' ) uploadTask.on( firebaseApp.storage.TaskEvent.STATE_CHANGED, snapshot => {}, error => { reject(error.message) }, () => { storageRef.getDownloadURL().then(url => { resolve(url) }) } ) }) } onSubmit = { (values, { setSubmitting, resetForm }) => { setMessage(i18next.t( 'PROCESSING' )) const copy = { ...values } await Promise.all( inputFieldsForAdditionalForm .filter(field => field.type === 'file' ) ...

for loop in javascript - promise - .eslintrc for "for of"

the vast majority of cases  map ,  forEach ,  find  etc. can be used.  async function printFiles () { const files = await getFilePaths(); await Promise.all(files. map (async (file) => { const contents = await fs.readFile(file, 'utf8') console.log(contents) })); } const inventory = [ { name : 'apples' , quantity : 2 } , { name : 'bananas' , quantity : 0 } , { name : 'cherries' , quantity : 5 } ] ; const result = inventory . find ( ( { name } ) => name === 'cherries' ) ;   function getFirstMatching(array) { for (let item of array) { const result = heavyTransform(item); if (result) { return result; } } } Specifically this shuts down the whole no-restricted-syntax. If you want to cherry-pick, here is the current definition: 'no-restricted-syntax' : [ 'error' , { selector : 'ForInStatement' , message...

turn GraphQL mutation into promise - with parameters

export interface SigningProps { forms : Document [] todos ?: Document [] listingId : string listingAddress : Address addDocument ?: ( data : DocumentInput ) => void printPdf ?: ( data : PrintPdfInput ) => void fillInPdfForm : ( data : FillInPdfInput ) => Promise < string > deleteTodo ?: ( id : string ) => void }   function fillInPdfForm ( fillInPdfInput : FillInPdfInput ): Promise < string > { return new Promise (( resolve , reject ) => { fillInPdf ({ variables : { fillInPdfInput : fillInPdfInput , }, }) . then (( data : any ) => { const doc = { ... data . data . fillInPdf , created : new Date (). toString (), } setDocuments ([... documents , doc ]) const todoDocs = todoDocuments . filter ( todo => todo . name !== doc . name ) setTodoDocuments ( todoDocs ) resolve ( '' ) ...