You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractRecentList.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // @flow
  2. import { Component } from 'react';
  3. import { ListView } from 'react-native';
  4. import { getRecentRooms } from '../functions';
  5. import { appNavigate } from '../../app';
  6. /**
  7. * The type of the React {@code Component} state of {@link AbstractRecentList}.
  8. */
  9. type State = {
  10. /**
  11. * The {@code ListView.DataSource} to be used for the {@code ListView}.
  12. * Its content comes from the native implementation of
  13. * {@code window.localStorage}.
  14. */
  15. dataSource: Object
  16. }
  17. /**
  18. * The type of the React {@code Component} props of {@link AbstractRecentList}
  19. */
  20. type Props = {
  21. /**
  22. * Redux store dispatch function.
  23. */
  24. dispatch: Dispatch<*>,
  25. }
  26. /**
  27. * Implements a React {@link Component} which represents the list of
  28. * conferences recently joined, similar to how a list of last dialed
  29. * numbers list would do on a mobile
  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. // this must be done asynchronously because we don't have the storage
  59. // initiated on app startup immediately.
  60. getRecentRooms().then(rooms => {
  61. this.setState({
  62. dataSource: this.listDataSource.cloneWithRows(rooms)
  63. });
  64. });
  65. }
  66. /**
  67. * Creates a bound onPress action for the list item.
  68. *
  69. * @param {string} room - The selected room.
  70. * @returns {Function}
  71. */
  72. _onSelect(room) {
  73. return this._onJoin.bind(this, room);
  74. }
  75. /**
  76. * Joins the selected room.
  77. *
  78. * @param {string} room - The selected room.
  79. * @returns {void}
  80. */
  81. _onJoin(room) {
  82. if (room) {
  83. this.props.dispatch(appNavigate(room));
  84. }
  85. }
  86. }