UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

100 lines 4.41 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.AttachmentFileUploadProgressIndicatorUI = exports.AttachmentFileUploadProgressIndicator = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _ComponentsContext = require("../../contexts/componentsContext/ComponentsContext"); var _ThemeContext = require("../../contexts/themeContext/ThemeContext"); var _usePendingAttachmentUpload = require("../../hooks/usePendingAttachmentUpload"); var _theme = require("../../theme"); var _utils = require("../../utils/utils"); var _jsxRuntime = require("react/jsx-runtime"); var _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Attachment/AttachmentFileUploadProgressIndicator.tsx"; function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var parseTotalBytes = value => { if (value == null) { return null; } if (typeof value === 'number' && Number.isFinite(value)) { return value; } if (typeof value === 'string') { var n = parseFloat(value); return Number.isFinite(n) ? n : null; } return null; }; var formatMegabytesOneDecimal = bytes => { if (!Number.isFinite(bytes) || bytes <= 0) { return '0.0 MB'; } return `${(bytes / (1000 * 1000)).toFixed(1)} MB`; }; var AttachmentFileUploadProgressIndicatorUI = ({ containerStyle, localId, sourceUrl, totalBytes }) => { var _useTheme = (0, _ThemeContext.useTheme)(), semantics = _useTheme.theme.semantics; var _useComponentsContext = (0, _ComponentsContext.useComponentsContext)(), AttachmentUploadIndicator = _useComponentsContext.AttachmentUploadIndicator; var shouldTrackPendingUpload = !!localId && !!sourceUrl && (0, _utils.isLocalUrl)(sourceUrl); var pendingUpload = (0, _usePendingAttachmentUpload.usePendingAttachmentUpload)(shouldTrackPendingUpload ? localId : undefined); var uploadProgress = pendingUpload.uploadProgress; var shouldRender = pendingUpload.isUploading; var progressLabel = (0, _react.useMemo)(() => { var bytes = parseTotalBytes(totalBytes); if (bytes == null || bytes <= 0) { return null; } var uploaded = (uploadProgress != null ? uploadProgress : 0) / 100 * bytes; return `${formatMegabytesOneDecimal(uploaded)} / ${formatMegabytesOneDecimal(bytes)}`; }, [totalBytes, uploadProgress]); if (!shouldRender) { return null; } return (0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.row, containerStyle], children: [(0, _jsxRuntime.jsx)(AttachmentUploadIndicator, { localId: localId, sourceUrl: sourceUrl }), progressLabel ? (0, _jsxRuntime.jsx)(_reactNative.Text, { numberOfLines: 1, style: [styles.label, { color: semantics.textSecondary }], children: progressLabel }) : null] }); }; exports.AttachmentFileUploadProgressIndicatorUI = AttachmentFileUploadProgressIndicatorUI; var AttachmentFileUploadProgressIndicator = props => { var localId = props.localId, sourceUrl = props.sourceUrl; var shouldTrackPendingUpload = !!localId && !!sourceUrl && (0, _utils.isLocalUrl)(sourceUrl); if (!shouldTrackPendingUpload) { return null; } return (0, _jsxRuntime.jsx)(AttachmentFileUploadProgressIndicatorUI, { ...props }); }; exports.AttachmentFileUploadProgressIndicator = AttachmentFileUploadProgressIndicator; var styles = _reactNative.StyleSheet.create({ label: { flex: 1, flexShrink: 1, fontSize: _theme.primitives.typographyFontSizeXs, fontWeight: _theme.primitives.typographyFontWeightRegular, lineHeight: _theme.primitives.typographyLineHeightTight }, row: { alignItems: 'center', flexDirection: 'row', gap: _theme.primitives.spacingXxs } }); //# sourceMappingURL=AttachmentFileUploadProgressIndicator.js.map