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

149 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-08-01 16:41:54 +00:00
// @flow
2019-03-19 15:42:25 +00:00
2018-09-25 12:48:03 +00:00
import React from 'react';
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';
2018-08-01 16:41:54 +00:00
import { translate } from '../../base/i18n';
2020-04-06 15:25:30 +00:00
import { setActiveModalId } from '../../base/modal';
2019-03-21 16:38:29 +00:00
import { NavigateSectionList, type Section } from '../../base/react';
import { connect } from '../../base/redux';
2019-05-07 14:50:57 +00:00
import { ColorPalette } from '../../base/styles';
2020-04-06 15:25:30 +00:00
import { DIAL_IN_SUMMARY_VIEW_ID } from '../../invite/constants';
2018-09-25 12:48:03 +00:00
import { deleteRecentListEntry } from '../actions';
import { isRecentListEnabled, toDisplayableList } from '../functions';
2020-05-20 10:57:03 +00:00
import AbstractRecentList from './AbstractRecentList';
2018-08-01 16:41:54 +00:00
/**
* The type of the React {@code Component} props of {@link RecentList}
*/
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
/**
* 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> {
_getRenderListEmptyComponent: () => React$Node;
_onPress: string => {};
2018-08-01 16:41:54 +00:00
/**
* Initializes a new {@code RecentList} instance.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
2018-09-25 12:48:03 +00:00
this._onDelete = this._onDelete.bind(this);
2019-05-07 14:50:57 +00:00
this._onShowDialInInfo = this._onShowDialInInfo.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,
t,
_defaultServerURL,
_recentList
} = this.props;
2018-08-01 16:41:54 +00:00
const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
2018-09-25 12:48:03 +00:00
const slideActions = [ {
2019-05-07 14:50:57 +00:00
backgroundColor: ColorPalette.blue,
onPress: this._onShowDialInInfo,
text: t('welcomepage.info')
}, {
2018-09-25 12:48:03 +00:00
backgroundColor: 'red',
onPress: this._onDelete,
text: t('welcomepage.recentListDelete')
} ];
2018-08-01 16:41:54 +00:00
return (
<NavigateSectionList
disabled = { disabled }
onPress = { this._onPress }
renderListEmptyComponent
= { this._getRenderListEmptyComponent() }
2018-09-25 12:48:03 +00:00
sections = { recentList }
slideActions = { slideActions } />
2018-08-01 16:41:54 +00:00
);
}
2018-09-25 12:48:03 +00:00
_onDelete: Object => void
/**
* Callback for the delete action of the list.
*
* @param {Object} itemId - The ID of the entry thats deletion is
* requested.
* @returns {void}
*/
_onDelete(itemId) {
this.props.dispatch(deleteRecentListEntry(itemId));
}
2019-05-07 14:50:57 +00:00
_onShowDialInInfo: Object => void
/**
* Callback for the dial-in info action of the list.
*
* @param {Object} itemId - The ID of the entry for which we'd like to show the dial in numbers.
* @returns {void}
*/
_onShowDialInInfo(itemId) {
2020-04-06 15:25:30 +00:00
this.props.dispatch(setActiveModalId(DIAL_IN_SUMMARY_VIEW_ID, { summaryUrl: itemId.url }));
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 {{
* _defaultServerURL: string,
* _recentList: Array
* }}
*/
export function _mapStateToProps(state: Object) {
return {
_defaultServerURL: getDefaultURL(state),
_recentList: state['features/recent-list']
};
}
export default translate(connect(_mapStateToProps)(RecentList));