2021-05-19 10:08:30 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-06-08 15:43:10 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2021-05-19 11:05:28 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-01-12 16:29:58 +00:00
|
|
|
import { ScrollView, Text, View } from 'react-native';
|
2021-06-09 15:35:58 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-06-08 15:43:10 +00:00
|
|
|
|
2022-07-27 08:40:34 +00:00
|
|
|
import Button from '../../../base/ui/components/native/Button';
|
2022-11-09 12:45:55 +00:00
|
|
|
import { BUTTON_TYPES } from '../../../base/ui/constants.native';
|
2021-06-29 14:05:11 +00:00
|
|
|
import { admitMultiple } from '../../../lobby/actions.native';
|
2021-08-18 11:29:41 +00:00
|
|
|
import { getKnockingParticipants, getLobbyEnabled } from '../../../lobby/functions';
|
2021-05-19 10:08:30 +00:00
|
|
|
|
2022-01-12 16:29:58 +00:00
|
|
|
import CollapsibleList from './CollapsibleList';
|
2021-05-19 10:08:30 +00:00
|
|
|
import { LobbyParticipantItem } from './LobbyParticipantItem';
|
2021-05-20 16:06:52 +00:00
|
|
|
import styles from './styles';
|
2021-05-19 10:08:30 +00:00
|
|
|
|
2021-07-30 09:48:06 +00:00
|
|
|
|
2022-07-07 12:29:18 +00:00
|
|
|
const LobbyParticipantList = () => {
|
2021-08-18 11:29:41 +00:00
|
|
|
const lobbyEnabled = useSelector(getLobbyEnabled);
|
|
|
|
const participants = useSelector(getKnockingParticipants);
|
|
|
|
|
2021-06-08 15:43:10 +00:00
|
|
|
const dispatch = useDispatch();
|
2021-06-09 15:35:58 +00:00
|
|
|
const admitAll = useCallback(() =>
|
2021-06-29 14:05:11 +00:00
|
|
|
dispatch(admitMultiple(participants)),
|
2021-07-30 09:48:06 +00:00
|
|
|
[ dispatch, participants ]);
|
2021-05-19 11:05:28 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2021-06-30 12:21:15 +00:00
|
|
|
if (!lobbyEnabled || !participants.length) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-07-07 12:29:18 +00:00
|
|
|
|
2022-01-12 16:29:58 +00:00
|
|
|
const title = (
|
|
|
|
<View style = { styles.lobbyListDetails } >
|
|
|
|
<Text style = { styles.lobbyListDescription }>
|
|
|
|
{t('participantsPane.headings.waitingLobby',
|
2021-05-24 11:08:58 +00:00
|
|
|
{ count: participants.length })}
|
2022-01-12 16:29:58 +00:00
|
|
|
</Text>
|
2021-10-20 19:29:21 +00:00
|
|
|
{
|
2022-01-12 16:29:58 +00:00
|
|
|
participants.length > 1 && (
|
|
|
|
<Button
|
2022-07-07 12:29:18 +00:00
|
|
|
accessibilityLabel = 'lobby.admitAll'
|
2022-08-22 09:40:59 +00:00
|
|
|
labelKey = 'lobby.admitAll'
|
2022-07-07 12:29:18 +00:00
|
|
|
labelStyle = { styles.admitAllButtonLabel }
|
2022-08-22 09:40:59 +00:00
|
|
|
onClick = { admitAll }
|
2022-07-07 12:29:18 +00:00
|
|
|
type = { BUTTON_TYPES.TERTIARY } />
|
2021-10-20 19:29:21 +00:00
|
|
|
)
|
|
|
|
}
|
2021-05-24 18:23:41 +00:00
|
|
|
</View>
|
2021-05-19 11:05:28 +00:00
|
|
|
);
|
2022-01-12 16:48:12 +00:00
|
|
|
|
|
|
|
// Regarding the fact that we have 3 sections, we apply
|
|
|
|
// a certain height percentage for every section in order for all to fit
|
|
|
|
// inside the participants pane container
|
2022-01-12 16:29:58 +00:00
|
|
|
const style = participants.length > 1 && styles.lobbyListContent;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CollapsibleList
|
|
|
|
title = { title }>
|
|
|
|
<ScrollView
|
|
|
|
bounces = { false }
|
|
|
|
style = { style } >
|
|
|
|
{
|
|
|
|
participants.map(p => (
|
|
|
|
<LobbyParticipantItem
|
|
|
|
key = { p.id }
|
|
|
|
participant = { p } />)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</ScrollView>
|
|
|
|
</CollapsibleList>
|
|
|
|
);
|
2021-05-19 11:05:28 +00:00
|
|
|
};
|
2021-07-30 09:48:06 +00:00
|
|
|
|
2022-07-07 12:29:18 +00:00
|
|
|
export default LobbyParticipantList;
|