您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractRecentList.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // @flow
  2. import { Component } from 'react';
  3. import { ListView } from 'react-native';
  4. import { appNavigate } from '../../app';
  5. import { getRecentRooms } from '../functions';
  6. /**
  7. * The type of the React {@code Component} props of {@link AbstractRecentList}
  8. */
  9. type Props = {
  10. /**
  11. * The redux store's {@code dispatch} function.
  12. */
  13. dispatch: Dispatch<*>
  14. };
  15. /**
  16. * The type of the React {@code Component} state of {@link AbstractRecentList}.
  17. */
  18. type State = {
  19. /**
  20. * The {@code ListView.DataSource} to be used for the {@code ListView}. Its
  21. * content comes from the native implementation of
  22. * {@code window.localStorage}.
  23. */
  24. dataSource: Object
  25. };
  26. /**
  27. * Implements a React {@link Component} which represents the list of conferences
  28. * recently joined, similar to how a list of last dialed numbers list would do
  29. * on a mobile device.
  30. *
  31. * @extends Component
  32. */
  33. export default class AbstractRecentList extends Component<Props, State> {
  34. /**
  35. * The datasource that backs the {@code ListView}.
  36. */
  37. listDataSource = new ListView.DataSource({
  38. rowHasChanged: (r1, r2) =>
  39. r1.conference !== r2.conference
  40. && r1.dateTimeStamp !== r2.dateTimeStamp
  41. });
  42. /**
  43. * Initializes a new {@code AbstractRecentList} instance.
  44. */
  45. constructor() {
  46. super();
  47. this.state = {
  48. dataSource: this.listDataSource.cloneWithRows([])
  49. };
  50. }
  51. /**
  52. * Implements React's {@link Component#componentWillMount()}. Invoked
  53. * immediately before mounting occurs.
  54. *
  55. * @inheritdoc
  56. */
  57. componentWillMount() {
  58. // The following must be done asynchronously because we don't have the
  59. // storage initiated on app startup immediately.
  60. getRecentRooms()
  61. .then(rooms =>
  62. this.setState({
  63. dataSource: this.listDataSource.cloneWithRows(rooms)
  64. }));
  65. }
  66. /**
  67. * Joins the selected room.
  68. *
  69. * @param {string} room - The selected room.
  70. * @returns {void}
  71. */
  72. _onJoin(room) {
  73. room && this.props.dispatch(appNavigate(room));
  74. }
  75. /**
  76. * Creates a bound onPress action for the list item.
  77. *
  78. * @param {string} room - The selected room.
  79. * @returns {Function}
  80. */
  81. _onSelect(room) {
  82. return this._onJoin.bind(this, room);
  83. }
  84. }