From 1d5afc0f02097689bf97be8c52dd79040bcb089f Mon Sep 17 00:00:00 2001 From: John Furrow Date: Sun, 22 Nov 2015 16:45:16 -0800 Subject: [PATCH] Allow torrent sidebar to dismiss itself intelligently --- .../source/scripts/containers/TorrentList.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/client/source/scripts/containers/TorrentList.js b/client/source/scripts/containers/TorrentList.js index d698a03e..c0c8ae70 100644 --- a/client/source/scripts/containers/TorrentList.js +++ b/client/source/scripts/containers/TorrentList.js @@ -78,6 +78,38 @@ class TorrentList extends React.Component { getTorrents(); } + componentWillReceiveProps(nextProps) { + if ((nextProps.selectedTorrents.length !== 1 && + this.state.detailsPanelOpen) || nextProps.torrents.length === 0) { + // Close the detail side panel if more than one torrent is selected. + this.setState({ + detailsPanelOpen: false + }); + } else if (this.state.detailsPanelOpen) { + // Close the detail side panel if the currently selected torrent isn't + // visible. + let searchingForSelectedTorrent = true; + let index = 0; + + while (searchingForSelectedTorrent) { + if (nextProps.torrents[index].hash === nextProps.selectedTorrents[0]) { + // The currently selected torrent is visible. + searchingForSelectedTorrent = false; + } else if (index === nextProps.torrents.length - 1) { + // The currently selected torrent is not visible, so clos the details + // panel. + this.setState({ + detailsPanelOpen: false + }); + index++; + searchingForSelectedTorrent = false; + } else { + index++; + } + } + } + } + shouldComponentUpdate(nextProps) { if (nextProps.isFetching === true) { return false; @@ -207,7 +239,6 @@ class TorrentList extends React.Component { }}> -