 # Process next element from import queue
 Deps.autorun ->
   # Autorun will not re-run when document changes status from 'preprocessed' to 'importing',
-  # but after it changes to any other status, next file will be returned.
+  # but after it changes to any other status, next file will be returned
   document = ImportingFile.documents.findOne
     state:
       $in: ['importing', 'preprocessed']


hideOverlay = ->
  allCount = ImportingFile.documents.find().count()
  finishedAndErroredCount = ImportingFile.documents.find(
    state:
      $in: ['errored', 'finished', 'imported']
  ).count()

  # We prevent hiding if user is uploading files
  if allCount == finishedAndErroredCount
    Session.set 'importOverlayActive', false
    ImportingFile.documents.remove {}



  return unless importingFilesCount

  finishedImportedFilesCount = ImportingFile.documents.find(state: $in: ['finished', 'imported']).count()

  # If there are any files still in progress or if there are any errors, do nothing
  return if importingFilesCount isnt finishedImportedFilesCount

  importedFilesCount = ImportingFile.documents.find(state: 'imported').count()

