jiti-meet/react/features/recent-list/components/AbstractRecentList.js

99 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-12-13 10:35:42 +00:00
// @flow
import { Component } from 'react';
import { ListView } from 'react-native';
import { appNavigate } from '../../app';
2017-12-20 00:49:36 +00:00
import { getRecentRooms } from '../functions';
2017-12-13 10:35:42 +00:00
/**
2017-12-20 00:49:36 +00:00
* The type of the React {@code Component} props of {@link AbstractRecentList}
2017-12-13 10:35:42 +00:00
*/
2017-12-20 00:49:36 +00:00
type Props = {
2017-12-13 10:35:42 +00:00
/**
2017-12-20 00:49:36 +00:00
* The redux store's {@code dispatch} function.
2017-12-13 10:35:42 +00:00
*/
2017-12-20 00:49:36 +00:00
dispatch: Dispatch<*>
};
2017-12-13 10:35:42 +00:00
/**
2017-12-20 00:49:36 +00:00
* The type of the React {@code Component} state of {@link AbstractRecentList}.
2017-12-13 10:35:42 +00:00
*/
2017-12-20 00:49:36 +00:00
type State = {
2017-12-13 10:35:42 +00:00
/**
2017-12-20 00:49:36 +00:00
* The {@code ListView.DataSource} to be used for the {@code ListView}. Its
* content comes from the native implementation of
* {@code window.localStorage}.
2017-12-13 10:35:42 +00:00
*/
2017-12-20 00:49:36 +00:00
dataSource: Object
};
2017-12-13 10:35:42 +00:00
/**
2017-12-20 00:49:36 +00:00
* Implements a React {@link Component} which represents the list of conferences
* recently joined, similar to how a list of last dialed numbers list would do
* on a mobile device.
2017-12-13 10:35:42 +00:00
*
* @extends Component
*/
export default class AbstractRecentList extends Component<Props, State> {
/**
2017-12-20 00:49:36 +00:00
* The datasource that backs the {@code ListView}.
*/
2017-12-13 10:35:42 +00:00
listDataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) =>
r1.conference !== r2.conference
&& r1.dateTimeStamp !== r2.dateTimeStamp
2017-12-20 00:49:36 +00:00
});
2017-12-13 10:35:42 +00:00
/**
* Initializes a new {@code AbstractRecentList} instance.
*/
constructor() {
super();
this.state = {
dataSource: this.listDataSource.cloneWithRows([])
};
}
/**
* Implements React's {@link Component#componentWillMount()}. Invoked
* immediately before mounting occurs.
*
* @inheritdoc
*/
componentWillMount() {
2017-12-20 00:49:36 +00:00
// The following must be done asynchronously because we don't have the
// storage initiated on app startup immediately.
getRecentRooms()
.then(rooms =>
this.setState({
dataSource: this.listDataSource.cloneWithRows(rooms)
}));
2017-12-13 10:35:42 +00:00
}
/**
2017-12-20 00:49:36 +00:00
* Joins the selected room.
*
* @param {string} room - The selected room.
* @returns {void}
*/
_onJoin(room) {
room && this.props.dispatch(appNavigate(room));
2017-12-13 10:35:42 +00:00
}
/**
2017-12-20 00:49:36 +00:00
* Creates a bound onPress action for the list item.
*
* @param {string} room - The selected room.
* @returns {Function}
*/
_onSelect(room) {
return this._onJoin.bind(this, room);
2017-12-13 10:35:42 +00:00
}
}