jiti-meet/react/features/recent-list/components/RecentList.native.js

129 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-09-25 12:48:03 +00:00
import React from 'react';
import { TouchableWithoutFeedback, View } from 'react-native';
2019-03-19 15:42:25 +00:00
import type { Dispatch } from 'redux';
2018-08-01 16:41:54 +00:00
import { getDefaultURL } from '../../app/functions';
import { openSheet } from '../../base/dialog/actions';
2018-08-01 16:41:54 +00:00
import { translate } from '../../base/i18n';
2019-03-21 16:38:29 +00:00
import { NavigateSectionList, type Section } from '../../base/react';
import { connect } from '../../base/redux';
import styles from '../../welcome/components/styles';
import { isRecentListEnabled, toDisplayableList } from '../functions';
2020-05-20 10:57:03 +00:00
import AbstractRecentList from './AbstractRecentList';
import RecentListItemMenu from './RecentListItemMenu.native';
2018-08-01 16:41:54 +00:00
/**
2021-11-04 21:10:43 +00:00
* The type of the React {@code Component} props of {@link RecentList}.
2018-08-01 16:41:54 +00:00
*/
type Props = {
/**
* Renders the list disabled.
*/
disabled: boolean,
/**
* The redux store's {@code dispatch} function.
*/
2019-03-19 15:42:25 +00:00
dispatch: Dispatch<any>,
2018-08-01 16:41:54 +00:00
/**
* Callback to be invoked when pressing the list container.
*/
onListContainerPress?: Function,
2018-08-01 16:41:54 +00:00
/**
* The translate function.
*/
t: Function,
/**
* The default server URL.
*/
_defaultServerURL: string,
/**
* The recent list from the Redux store.
*/
_recentList: Array<Section>
};
/**
* A class that renders the list of the recently joined rooms.
2018-08-01 16:41:54 +00:00
*
*/
class RecentList extends AbstractRecentList<Props> {
2018-08-01 16:41:54 +00:00
/**
* Initializes a new {@code RecentList} instance.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
// Bind event handlers so they are only bound once per instance.
this._onLongPress = this._onLongPress.bind(this);
}
2018-08-01 16:41:54 +00:00
/**
* Implements the React Components's render method.
*
* @inheritdoc
*/
render() {
if (!isRecentListEnabled()) {
return null;
}
const {
disabled,
onListContainerPress,
t,
_defaultServerURL,
_recentList
} = this.props;
2018-08-01 16:41:54 +00:00
const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
return (
<TouchableWithoutFeedback
onPress = { onListContainerPress }>
<View style = { disabled ? styles.recentListDisabled : styles.recentList }>
<NavigateSectionList
disabled = { disabled }
onLongPress = { this._onLongPress }
onPress = { this._onPress }
renderListEmptyComponent
= { this._getRenderListEmptyComponent() }
sections = { recentList } />
</View>
</TouchableWithoutFeedback>
2018-08-01 16:41:54 +00:00
);
}
2018-09-25 12:48:03 +00:00
/**
* Handles the list's navigate action.
2018-09-25 12:48:03 +00:00
*
* @private
* @param {Object} item - The item which was long pressed.
2018-09-25 12:48:03 +00:00
* @returns {void}
*/
_onLongPress(item) {
this.props.dispatch(openSheet(RecentListItemMenu, { item }));
2019-05-07 14:50:57 +00:00
}
2018-08-01 16:41:54 +00:00
}
/**
* Maps redux state to component props.
*
* @param {Object} state - The redux state.
* @returns {Props}
2018-08-01 16:41:54 +00:00
*/
export function _mapStateToProps(state: Object) {
return {
_defaultServerURL: getDefaultURL(state),
_recentList: state['features/recent-list']
};
}
export default translate(connect(_mapStateToProps)(RecentList));