Set showing_news_id during updown hotkey, before waiting 100ms.

I was having issues where after using the up/down keys, sometimes
the newsreader panel would show the wrong item, the second-to-last
selected news. Since we wait 100ms before letting the up/down key
populate the newsreader, there's a bit of limbo time which I think
was the problem. This seems to have helped with that.
This commit is contained in:
voussoir 2022-03-30 20:28:08 -07:00
parent 8b79773c5b
commit a089775b54
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -1653,7 +1653,7 @@ function _up_down(sibling_func)
first_selected_news = neighbor; first_selected_news = neighbor;
mark_read_with_batching(neighbor.dataset.id); mark_read_with_batching(neighbor.dataset.id);
// console.log(`updown ${neighbor.dataset.id}`); showing_news_id = neighbor.dataset.id;
clearTimeout(show_news_after_timeout); clearTimeout(show_news_after_timeout);
show_news_after_timeout = setTimeout(() => {show_news_in_newsreader(neighbor);}, 100); show_news_after_timeout = setTimeout(() => {show_news_in_newsreader(neighbor);}, 100);
mark_read_and_propagate_unread_delta(neighbor); mark_read_and_propagate_unread_delta(neighbor);
@ -1779,6 +1779,10 @@ function set_newsreader_news_text(html)
} }
} }
// When switching news items quickly, a previously requested news item might
// load after the user has already clicked on another one. So we store the most
// recently clicked id and don't show a previously clicked news whose callback
// has just come in.
let showing_news_id = null; let showing_news_id = null;
function show_news_in_newsreader(news) function show_news_in_newsreader(news)
{ {
@ -1786,7 +1790,7 @@ function show_news_in_newsreader(news)
{ {
if (news_object.id != showing_news_id) if (news_object.id != showing_news_id)
{ {
// The user must have clickedon something else in the meantime. // The user must have clicked on something else in the meantime.
return; return;
} }
clearTimeout(show_news_after_timeout); clearTimeout(show_news_after_timeout);