@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.
72 lines • 2.98 kB
JavaScript
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); }
import React from 'react';
import { FlatList } from 'react-native';
import { PushTriggerOption } from '@sendbird/chat';
import { useActionMenu, useToast } from '@sendbird/uikit-react-native-foundation';
import { NOOP, PASS, getChannelUniqId, useFreshCallback, useSafeAreaPadding } from '@sendbird/uikit-utils';
import { useLocalization, useSendbirdChat } from '../../../hooks/useContext';
const GroupChannelListList = ({
onPressChannel,
renderGroupChannelPreview,
groupChannels,
onLoadNext,
flatListProps,
menuItemCreator = PASS
}) => {
const toast = useToast();
const {
openMenu
} = useActionMenu();
const {
STRINGS
} = useLocalization();
const {
sdk,
currentUser
} = useSendbirdChat();
const onLongPress = 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(PushTriggerOption.DEFAULT);
} else {
await channel.setMyPushTriggerOption(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(NOOP));
},
onError: () => toast.show(STRINGS.TOAST.LEAVE_CHANNEL_ERROR, 'error')
}]
});
openMenu(menuItem);
});
const renderItem = useFreshCallback(({
item
}) => renderGroupChannelPreview === null || renderGroupChannelPreview === void 0 ? void 0 : renderGroupChannelPreview({
channel: item,
onPress: () => onPressChannel(item),
onLongPress: () => onLongPress(item)
}));
const safeArea = useSafeAreaPadding(['left', 'right']);
return /*#__PURE__*/React.createElement(FlatList, _extends({
bounces: false,
data: groupChannels,
renderItem: renderItem,
onEndReached: onLoadNext
}, flatListProps, {
contentContainerStyle: [flatListProps === null || flatListProps === void 0 ? void 0 : flatListProps.contentContainerStyle, safeArea],
keyExtractor: getChannelUniqId
}));
};
export default GroupChannelListList;
//# sourceMappingURL=GroupChannelListList.js.map