if itemImages.count > 0 {
uploadImages(images: itemImages, itemId: item.id) { (imageLikArray) in
item.imageLinks = imageLikArray
saveItemToFirestore(item)
saveItemToAlgolia(item: item)
self.hideLoadingIndicator()
self.popTheView()
}
} else {
saveItemToFirestore(item)
saveItemToAlgolia(item: item)
popTheView()
}
}
//MARK: - Algolia Funcs
func saveItemToAlgolia(item: Item) {
let index = AlgoliaService.shared.index
let itemToSave = itemDictionaryFrom(item) as! [String : Any]
index.addObject(itemToSave, withID: item.id, requestOptions: nil) { (content, error) in
if error != nil {
print("error saving to algolia", error!.localizedDescription)
} else {
print("added to algolia")
}
}
}