import { clearUploadError } from "@/redux/photos/photos.actions"; import theme from "@/util/theme"; import { formatBytes } from "@/util/uploadUtils"; import { useTranslation } from "react-i18next"; import { StyleSheet, View } from "react-native"; import { ProgressBar, Text } from "react-native-paper"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { selectPhotos, selectUploadError, selectUploadProgress, } from "../../redux/photos/photos.selectors"; import ErrorDisplay from "../error/error-display"; const mapStateToProps = createStructuredSelector({ photos: selectPhotos, photoUploadProgress: selectUploadProgress, uploadError: selectUploadError, }); const mapDispatchToProps = (dispatch) => ({ clearError: () => dispatch(clearUploadError()), }); export default connect(mapStateToProps, mapDispatchToProps)(UploadProgress); export function UploadProgress({ photos, photoUploadProgress, uploadError, clearError, }) { const { t } = useTranslation(); if (photos?.length === 0) return null; if (uploadError) return ; return ( {t("general.labels.uploadprogress")} {Object.keys(photoUploadProgress).map((key) => ( {photoUploadProgress[key].fileName} {`${formatBytes( photoUploadProgress[key].loaded / (((photoUploadProgress[key].endTime || new Date()) - photoUploadProgress[key].startTime) / 1000) )}/sec`} ))} ); } const styles = StyleSheet.create({ modalContainer: { display: "flex", // flex: 1, marginTop: 14, marginBottom: 14, justifyContent: "center", }, modal: { //flex: 1, display: "flex", marginLeft: 12, marginRight: 12, backgroundColor: theme.colors.elevation.level3, borderRadius: 20, paddingTop: 12, shadowColor: "#000", shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.25, shadowRadius: 4, elevation: 5, }, title: { alignSelf: "center", alignItems: "center", marginBottom: 12, paddingLeft: 12, paddingRight: 12, }, centeredView: { justifyContent: "center", alignItems: "center", marginTop: 22, }, progressItem: { display: "flex", flexDirection: "row", alignItems: "center", marginBottom: 12, marginLeft: 12, marginRight: 12, }, progressText: { flex: 1, flexShrink: 1, }, progressBarContainer: { flex: 3, marginLeft: 12, marginRight: 12, }, });