UNPKG

@sendbird/uikit-react-native

Version:

Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

79 lines (78 loc) 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _reactNative = require("react-native"); var _chat = require("@sendbird/chat"); var _uikitReactNativeFoundation = require("@sendbird/uikit-react-native-foundation"); var _uikitUtils = require("@sendbird/uikit-utils"); var _useContext = require("../../../hooks/useContext"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const GroupChannelListList = ({ onPressChannel, renderGroupChannelPreview, groupChannels, onLoadNext, flatListProps, menuItemCreator = _uikitUtils.PASS }) => { const toast = (0, _uikitReactNativeFoundation.useToast)(); const { openMenu } = (0, _uikitReactNativeFoundation.useActionMenu)(); const { STRINGS } = (0, _useContext.useLocalization)(); const { sdk, currentUser } = (0, _useContext.useSendbirdChat)(); const onLongPress = (0, _uikitUtils.useFreshCallback)(channel => { const action = channel.myPushTriggerOption === 'off' ? 'on' : 'off'; const menuItem = menuItemCreator({ title: STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_TITLE((currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId) ?? '', channel), menuItems: [{ title: STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_NOTIFICATION(channel), onPress: async () => { if (action === 'on') { await channel.setMyPushTriggerOption(_chat.PushTriggerOption.DEFAULT); } else { await channel.setMyPushTriggerOption(_chat.PushTriggerOption.OFF); } }, onError: () => { toast.show(action === 'on' ? STRINGS.TOAST.TURN_ON_NOTIFICATIONS_ERROR : STRINGS.TOAST.TURN_OFF_NOTIFICATIONS_ERROR, 'error'); } }, { title: STRINGS.GROUP_CHANNEL_LIST.DIALOG_CHANNEL_LEAVE, onPress: async () => { channel.leave().then(() => sdk.clearCachedMessages([channel.url]).catch(_uikitUtils.NOOP)); }, onError: () => toast.show(STRINGS.TOAST.LEAVE_CHANNEL_ERROR, 'error') }] }); openMenu(menuItem); }); const renderItem = (0, _uikitUtils.useFreshCallback)(({ item }) => renderGroupChannelPreview === null || renderGroupChannelPreview === void 0 ? void 0 : renderGroupChannelPreview({ channel: item, onPress: () => onPressChannel(item), onLongPress: () => onLongPress(item) })); const safeArea = (0, _uikitUtils.useSafeAreaPadding)(['left', 'right']); return /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, _extends({ bounces: false, data: groupChannels, renderItem: renderItem, onEndReached: onLoadNext }, flatListProps, { contentContainerStyle: [flatListProps === null || flatListProps === void 0 ? void 0 : flatListProps.contentContainerStyle, safeArea], keyExtractor: _uikitUtils.getChannelUniqId })); }; var _default = exports.default = GroupChannelListList; //# sourceMappingURL=GroupChannelListList.js.map