PickerPanelTopBar.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const { h } = require('preact')
  2. const uploadStates = {
  3. 'STATE_ERROR': 'error',
  4. 'STATE_WAITING': 'waiting',
  5. 'STATE_PREPROCESSING': 'preprocessing',
  6. 'STATE_UPLOADING': 'uploading',
  7. 'STATE_POSTPROCESSING': 'postprocessing',
  8. 'STATE_COMPLETE': 'complete',
  9. 'STATE_PAUSED': 'paused'
  10. }
  11. function getUploadingState (isAllErrored, isAllComplete, isAllPaused, files = {}) {
  12. if (isAllErrored) {
  13. return uploadStates.STATE_ERROR
  14. }
  15. if (isAllComplete) {
  16. return uploadStates.STATE_COMPLETE
  17. }
  18. if (isAllPaused) {
  19. return uploadStates.STATE_PAUSED
  20. }
  21. let state = uploadStates.STATE_WAITING
  22. const fileIDs = Object.keys(files)
  23. for (let i = 0; i < fileIDs.length; i++) {
  24. const progress = files[fileIDs[i]].progress
  25. // If ANY files are being uploaded right now, show the uploading state.
  26. if (progress.uploadStarted && !progress.uploadComplete) {
  27. return uploadStates.STATE_UPLOADING
  28. }
  29. // If files are being preprocessed AND postprocessed at this time, we show the
  30. // preprocess state. If any files are being uploaded we show uploading.
  31. if (progress.preprocess && state !== uploadStates.STATE_UPLOADING) {
  32. state = uploadStates.STATE_PREPROCESSING
  33. }
  34. // If NO files are being preprocessed or uploaded right now, but some files are
  35. // being postprocessed, show the postprocess state.
  36. if (progress.postprocess && state !== uploadStates.STATE_UPLOADING && state !== uploadStates.STATE_PREPROCESSING) {
  37. state = uploadStates.STATE_POSTPROCESSING
  38. }
  39. }
  40. return state
  41. }
  42. function UploadStatus (props) {
  43. const uploadingState = getUploadingState(
  44. props.isAllErrored,
  45. props.isAllComplete,
  46. props.isAllPaused,
  47. props.files
  48. )
  49. switch (uploadingState) {
  50. case 'uploading':
  51. return props.i18n('uploadingXFiles', { smart_count: props.inProgressNotPausedFiles.length })
  52. case 'preprocessing':
  53. case 'postprocessing':
  54. return props.i18n('processingXFiles', { smart_count: props.processingFiles.length })
  55. case 'paused':
  56. return props.i18n('uploadPaused')
  57. case 'waiting':
  58. return props.i18n('xFilesSelected', { smart_count: props.newFiles.length })
  59. case 'complete':
  60. return props.i18n('uploadComplete')
  61. }
  62. }
  63. function PanelTopBar (props) {
  64. let allowNewUpload = props.allowNewUpload
  65. // TODO maybe this should be done in ../index.js, then just pass that down as `allowNewUpload`
  66. if (allowNewUpload && props.maxNumberOfFiles) {
  67. allowNewUpload = props.totalFileCount < props.maxNumberOfFiles
  68. }
  69. return (
  70. <div class="uppy-DashboardContent-bar">
  71. <div>
  72. {!props.isAllComplete
  73. ? <button class="uppy-DashboardContent-back"
  74. type="button"
  75. onclick={props.cancelAll}>{props.i18n('cancel')}</button>
  76. : null
  77. }
  78. </div>
  79. <div class="uppy-DashboardContent-title" role="heading" aria-level="h1">
  80. <UploadStatus {...props} />
  81. </div>
  82. { allowNewUpload &&
  83. <button class="uppy-DashboardContent-addMore"
  84. type="button"
  85. aria-label={props.i18n('addMoreFiles')}
  86. title={props.i18n('addMoreFiles')}
  87. onclick={() => props.toggleAddFilesPanel(true)}>
  88. <svg class="UppyIcon" width="14" height="14" viewBox="0 0 14 14">
  89. <path d="M7.5 6H13a.5.5 0 0 1 .5.5V7a.5.5 0 0 1-.5.5H7.5V13a.5.5 0 0 1-.5.5h-.5A.5.5 0 0 1 6 13V7.5H.5A.5.5 0 0 1 0 7v-.5A.5.5 0 0 1 .5 6H6V.5a.5.5 0 0 1 .5-.5H7a.5.5 0 0 1 .5.5V6z" />
  90. </svg>
  91. </button>
  92. }
  93. </div>
  94. )
  95. }
  96. module.exports = PanelTopBar