stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
96 lines • 4.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LoadingErrorIndicator = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _ThemeContext = require("../../contexts/themeContext/ThemeContext");
var _TranslationContext = require("../../contexts/translationContext/TranslationContext");
var _theme = require("../../theme");
var _jsxRuntime = require("react/jsx-runtime");
var _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Indicators/LoadingErrorIndicator.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 LoadingErrorWrapper = props => {
var children = props.children,
onPress = props.onPress,
text = props.text;
var styles = useStyles();
return (0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
accessibilityHint: onPress ? 'Tap to retry' : undefined,
accessibilityLiveRegion: "assertive",
accessibilityRole: onPress ? 'button' : 'alert',
onPress: onPress,
style: styles.container,
children: [(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: styles.errorText,
testID: "loading-error",
children: text
}), children]
});
};
var LoadingErrorIndicator = props => {
var listType = props.listType,
_props$retry = props.retry,
retry = _props$retry === void 0 ? () => null : _props$retry;
var _useTranslationContex = (0, _TranslationContext.useTranslationContext)(),
t = _useTranslationContex.t;
var styles = useStyles();
switch (listType) {
case 'channel':
return (0, _jsxRuntime.jsx)(LoadingErrorWrapper, {
onPress: retry,
text: t('Error loading channel list...'),
children: (0, _jsxRuntime.jsx)(_reactNative.Text, {
style: styles.retryText,
children: "\u27F3"
})
});
case 'message':
return (0, _jsxRuntime.jsx)(LoadingErrorWrapper, {
onPress: retry,
text: t('Error loading messages for this channel...')
});
default:
return (0, _jsxRuntime.jsx)(LoadingErrorWrapper, {
text: t('Error loading')
});
}
};
exports.LoadingErrorIndicator = LoadingErrorIndicator;
LoadingErrorIndicator.displayName = 'LoadingErrorIndicator{loadingErrorIndicator}';
var useStyles = () => {
var _useTheme = (0, _ThemeContext.useTheme)(),
_useTheme$theme = _useTheme.theme,
_useTheme$theme$loadi = _useTheme$theme.loadingErrorIndicator,
errorText = _useTheme$theme$loadi.errorText,
retryText = _useTheme$theme$loadi.retryText,
container = _useTheme$theme$loadi.container,
semantics = _useTheme$theme.semantics;
return (0, _react.useMemo)(() => {
return _reactNative.StyleSheet.create({
container: {
alignItems: 'center',
height: '100%',
justifyContent: 'center',
width: '100%',
...container
},
errorText: {
color: semantics.accentError,
fontSize: _theme.primitives.typographyFontSizeMd,
lineHeight: _theme.primitives.typographyLineHeightNormal,
fontWeight: _theme.primitives.typographyFontWeightSemiBold,
paddingVertical: _theme.primitives.spacingSm,
...errorText
},
retryText: {
color: semantics.textPrimary,
fontSize: _theme.primitives.typographyFontSizeLg,
lineHeight: _theme.primitives.typographyLineHeightNormal,
fontWeight: _theme.primitives.typographyFontWeightSemiBold,
...retryText
}
});
}, [container, semantics.accentError, semantics.textPrimary, errorText, retryText]);
};
//# sourceMappingURL=LoadingErrorIndicator.js.map