/** * @flow * @file Overall uploads progress bar */ import React from 'react'; import { FormattedMessage } from 'react-intl'; import messages from '../common/messages'; import ProgressBar from './ProgressBar'; import { VIEW_UPLOAD_IN_PROGRESS, VIEW_UPLOAD_SUCCESS, VIEW_ERROR, VIEW_UPLOAD_EMPTY } from '../../constants'; import './OverallUploadsProgressBar.scss'; /** * Get upload status * * @param {View} view * @return {FormattedMessage|string} */ const getUploadStatus = (view: string) => { switch (view) { case VIEW_UPLOAD_IN_PROGRESS: return ; case VIEW_UPLOAD_SUCCESS: return ; case VIEW_UPLOAD_EMPTY: return ; case VIEW_ERROR: return ; default: return ''; } }; /** * Get overall upload progress percentage * * @param {string} view * @param {number} percent */ const getPercent = (view: string, percent: number): number => { switch (view) { case VIEW_UPLOAD_SUCCESS: return 100; case VIEW_UPLOAD_EMPTY: case VIEW_ERROR: return 0; default: return percent; } }; type Props = { isDragging: boolean, isExpanded: boolean, isVisible: boolean, onClick: Function, onKeyDown: Function, percent: number, view: View, }; const OverallUploadsProgressBar = ({ percent, view, onClick, onKeyDown, isDragging, isVisible, isExpanded }: Props) => { // Show the upload prompt and set progress to 0 when the uploads manager // is invisible or is having files dragged to it const shouldShowPrompt = isDragging || !isVisible; const status = shouldShowPrompt ? ( ) : ( getUploadStatus(view) ); const updatedPercent = shouldShowPrompt ? 0 : getPercent(view, percent); return (
{status}
); }; export default OverallUploadsProgressBar;