-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(web): add autocompletion for destination folder input when adding new torrent #7676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
A drawback of using |
8fd3bf7 to
4823bd3
Compare
killemov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main problem with this solution is rebuilding the datalist on every focus(). Can you find a cached solution for this?
web/src/open-dialog.js
Outdated
| let torrents = this.controller._rows | ||
| .toSorted((a, b) => b.getTorrent().getDateAdded() - a.getTorrent().getDateAdded()) | ||
| .map(row => row.getTorrent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. First map then sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe i will just not sort and just leave it as the original sorting being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
let torrents = this.controller._rows
.map(row => row.getTorrent())
.sort((a, b) => b.getDateAdded() - a.getDateAdded());There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if _rows are already being sorted by the controller then toSorted is unnecessary i think. see my other comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in JavaScript, chaining .map() and .toSorted() does create two intermediate arrays — one after .map(), and another after .toSorted().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured you needed the last added X torrents to get the last X used paths. Are you sure the controller has the row/torrents in the correct order already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if they have the sorting set to Age then yes
|
regarding sorting i think it is better to keep the ordering in |
|
@ckerr should we sort by age again manually in the open-dialog or should we let it order based on |
| if (!dir || dirs.has(dir)) { | ||
| continue; | ||
| } | ||
| dirs.add(dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both Set.has and Set.add traverse the entire set to check if an item is in the collection. You should change Set to Array since you are checking the collection yourself anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just avoid the has() call?
if (dir)
dirs.add(dir)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just avoid the
has()call?if (dir) dirs.add(dir)
Unfortunately not. There has to be some check to skip the loop if the dir already exists to avoid duplicate option elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik Set.has is O(1) while Array.includes is O(n)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick search led me to this article: Using Array.prototype.includes() vs Set.prototype.has() to filter arrays
And the comments painted a different picture from the main article: It appears to be implementation dependent.
If you want to be sure you can do some online Javascript performance testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Then we can simplify(?) to:
workarea.append((() => {
const datalist = document.createElement('datalist');
datalist.id = 'add-dialog-folder-datalist';
var i = 0;
for (const dir of new Set(this.controller._rows.map(row => row.getTorrent().getDownloadDir().trim()))) {
const option = document.createElement('option');
option.value = dir;
datalist.append(option);
if (++i >= max_datalist_options) { // do not explode the ui
break;
}
}
return datalist;
})());IF an option is created with a null and/or "" it should not appear in the input because you have to type something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think by using map() we could very well be using reduce(), it is accumulator for new Set() and do less job when reaching 100
const datalist = document.createElement('DATALIST');
datalist.id = 'add-dialog-folder-datalist';
const dirs = this.controller._rows.reduce(
(accumulator, row) => {
if (accumulator.size < max_datalist_options) {
accumulator.add(row.getTorrent().getDownloadDir().trim());
}
return accumulator;
},
new Set(),
);
for (const dir of dirs) {
datalist.append(new Option(dir));
}
workarea.append(input, datalist);Performance untested
I am not sure what I think yet -- lemme try test-driving this and see how it looks to me in practice |
452d277 to
1699c71
Compare

sometimes i need to add multiple torrents manually via the web gui into the same folder and it really slows me down typing/copy pasting the same full path every single time. with
datalistit will help me a lot and avoid typos.Notes: Added autocompletion to folder path input with datalist.