Angular / Firestore - Anything after combineLatest / switchMap being ignored

97 Views Asked by At

I have a function that's uploading two images to firebase storage. The uploads work perfectly fine.

  const smallTaskRef = this.storage.upload(thumbPath, results.thumb);
  const largeTaskRef = this.storage.upload(largePath, results.large);

However, within the same function i have the snippet below where I would like to update firestore with the download URLs. Upon checking storage, both images are successfully there. Once it reaches the snippet below, nothing happens. Is there anything that could be fixed with the below to ensure that a firestore document can be set?

   const ref = combineLatest([smallTaskRef, largeTaskRef]).pipe(            
        switchMap(async() =>  {
          const smallimageURL = await smallTaskRef.getDownloadURL().toPromise();
          const largeImageURL = await largeTaskRef.getDownloadURL().toPromise();
          return this.afs.collection(`col`).doc(`${id}`).set({
            url_small: smallimageURL,      
            url_large: largeImageURL,    
          }).then(() => {
            console.log('successfully written')
          })
        })
      );

UPDATE

const obs$ = combineLatest([thumbTask, largeTask]);

this._subscription = obs$.pipe(
   switchMap(async ([smallTaskRef, largeTaskRef]) => {
     const smallimageURL = await smallTaskRef.getDownloadURL().toPromise();
     const largeImageURL = await largeTaskRef.getDownloadURL().toPromise();
     return this.afs.collection(`col`).doc(doc).set({  
        // set doc values
     }).then(() => {
       console.log('successfully written')
     })
   })
).subscribe();
0

There are 0 best solutions below