From 7b4e2f6a587f612cf6e6d6c38c46e9fbfed56a68 Mon Sep 17 00:00:00 2001 From: Torjus Date: Wed, 1 Aug 2018 15:09:58 +0200 Subject: [PATCH] Add basic scroll-to-bottom functionality --- .../FileSharing/SharedFilesList.jsx | 59 +++++++++++++++++++ app/lib/components/FileSharing/index.jsx | 26 +------- 2 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 app/lib/components/FileSharing/SharedFilesList.jsx diff --git a/app/lib/components/FileSharing/SharedFilesList.jsx b/app/lib/components/FileSharing/SharedFilesList.jsx new file mode 100644 index 0000000..109b009 --- /dev/null +++ b/app/lib/components/FileSharing/SharedFilesList.jsx @@ -0,0 +1,59 @@ +import React, { PureComponent } from 'react'; +import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; +import FileEntry, { FileEntryProps } from './FileEntry'; + +class SharedFilesList extends PureComponent +{ + constructor(props) + { + super(props); + + this.listRef = React.createRef(); + } + + scrollToBottom = () => + { + const elem = this.listRef.current; + + elem.scrollTop = elem.scrollHeight; + }; + + componentDidUpdate() + { + this.scrollToBottom(); + } + + render() + { + return ( +
+ {this.props.sharing.map((entry, i) => ( + + ))} +
+ ); + } +} + +SharedFilesList.propTypes = { + sharing : PropTypes.arrayOf(FileEntryProps.data).isRequired +}; + +const mapStateToProps = (state) => + ({ + sharing : state.sharing, + + // Included to scroll to the bottom when the user + // actually opens the tab. When the component first + // mounts, the component is not visible and so the + // component has no height which can be used for scrolling. + tabOpen : state.toolarea.currentToolTab === 'files' + }); + +export default connect( + mapStateToProps +)(SharedFilesList); \ No newline at end of file diff --git a/app/lib/components/FileSharing/index.jsx b/app/lib/components/FileSharing/index.jsx index 9eafbd0..fd41051 100644 --- a/app/lib/components/FileSharing/index.jsx +++ b/app/lib/components/FileSharing/index.jsx @@ -1,6 +1,4 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; import WebTorrent from 'webtorrent'; import createTorrent from 'create-torrent'; import randomString from 'random-string'; @@ -9,7 +7,7 @@ import * as stateActions from '../../redux/stateActions'; import * as requestActions from '../../redux/requestActions'; import { store } from '../../store'; import config from '../../../config'; -import FileEntry, { FileEntryProps } from './FileEntry'; +import SharedFilesList from './SharedFilesList'; export const client = WebTorrent.WEBRTC_SUPPORT && new WebTorrent({ tracker : { @@ -124,28 +122,10 @@ class FileSharing extends Component -
- {this.props.sharing.map((entry, i) => ( - - ))} -
+ ); } } -FileSharing.propTypes = { - sharing : PropTypes.arrayOf(FileEntryProps.data).isRequired -}; - -const mapStateToProps = (state) => - ({ - sharing : state.sharing - }); - -export default connect( - mapStateToProps -)(FileSharing); \ No newline at end of file +export default FileSharing; \ No newline at end of file