Skip to content

Commit

Permalink
fix(search): merge files in search when same torrent twice in a row
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Mar 3, 2018
1 parent 43780bc commit 22d3173
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,33 @@ export default class Search extends Component {
if(files != this.searchLimit)
this.moreSearchFiles = false;

this.mergeFiles()

this.setState({moreFilesIndicator: false});
}
}));
}
mergeFiles()
{
for(let i = 0; i < this.searchFiles.length; i++)
{
for(let j = i + 1; j < this.searchFiles.length; j++)
{
if(this.searchFiles[i].hash != this.searchFiles[j].hash)
continue

if(!this.searchFiles[i].remove)
{
this.searchFiles[i].path = this.searchFiles[i].path.concat(this.searchFiles[j].path)
}

this.searchFiles[j].remove = true
}
}

this.searchFiles = this.searchFiles.filter(torrent => !torrent.remove)
}

componentDidMount() {
this.newStatisticFunc = (statistic) => {
if(statistic) {
Expand All @@ -230,6 +253,7 @@ export default class Search extends Component {
if(!torrents)
return
this.searchFiles = _.unionBy(this.searchFiles, torrents, 'hash')
this.mergeFiles()
this.forceUpdate();
}
window.torrentSocket.on('remoteSearchFiles', this.remoteSearchFiles);
Expand Down

0 comments on commit 22d3173

Please sign in to comment.