Skip to content
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

WebUI: Restore previously used tab on load #20705

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Piccirello
Copy link
Member

@Piccirello Piccirello commented Apr 15, 2024

This PR restores the users previously used tab (Transfer, Search, RSS, etc.) when the Web UI is reloaded.

Screen.Recording.2024-04-14.at.23.33.19.mov

@Piccirello Piccirello added the WebUI WebUI-related issues/changes label Apr 15, 2024
@Piccirello Piccirello added this to the 5.0 milestone Apr 15, 2024
@Piccirello Piccirello requested a review from a team April 15, 2024 06:35
This simplifies development as developers can now directly set breakpoints in the browser on search code.
The log panel may be displayed before its JS has loaded, which results in an error. This prevents the error by delaying initialization until the necessary scripts are loaded.
@Piccirello Piccirello marked this pull request as ready for review April 15, 2024 06:37
This logic bug prevented the double click handler from being readded to rows once the search completed.
Comment on lines +97 to +99
let showSearchEngine = false;
let showRssReader = false;
let showLogViewer = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move them to some specific scope? I wouldn't like more global variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move them to window.qBittorrent.Client, which seems like an appropriate place.

@@ -1256,6 +1291,12 @@ window.addEventListener("DOMContentLoaded", function() {
},
loadMethod: 'xhr',
contentURL: 'views/search.html',
require: {
js: ['scripts/search.js'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be better to include <script defer src="scripts/search.js"></script> in search.html?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they're functionally equivalent, so would just be a matter of personal preference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought a little more about it.

  • If search.html always require search.js, then it is better to include the js within it, rather than externally.
  • <script> can have defer attribute which might be able to speed up page loading.

ps. I would like to investigate whether if I can migrate all require.js and require.css to html equivalents.

Comment on lines +1649 to +1660
if (showSearchEngine && (previouslyUsedTab === 'search')) {
$('searchTabLink').click();
}
else if (showRssReader && (previouslyUsedTab === 'rss')) {
$('rssTabLink').click();
}
else if (showLogViewer && (previouslyUsedTab === 'log')) {
$('logTabLink').click();
}
else {
LocalPreferences.set('selected_tab', 'transfers');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a switch()?

Suggested change
if (showSearchEngine && (previouslyUsedTab === 'search')) {
$('searchTabLink').click();
}
else if (showRssReader && (previouslyUsedTab === 'rss')) {
$('rssTabLink').click();
}
else if (showLogViewer && (previouslyUsedTab === 'log')) {
$('logTabLink').click();
}
else {
LocalPreferences.set('selected_tab', 'transfers');
}
switch (previouslyUsedTab) {
case 'log':
if (showLogViewer)
$('logTabLink').click();
break;
case 'rss':
if (showRssReader)
$('rssTabLink').click();
break;
case 'search':
if (showSearchEngine)
$('searchTabLink').click();
break;
case 'transfers':
$('transfersTabLink').click();
break;
}

Note that I replaced LocalPreferences.set('selected_tab', 'transfers'); with case 'transfers'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants