1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Update unread counter when using keyboard to navigate

This commit is contained in:
Frédéric Guillot 2017-12-28 18:59:17 -08:00
parent 8cd58a746a
commit 519d4fcd73
11 changed files with 62 additions and 25 deletions

View file

@ -205,8 +205,8 @@ class KeyboardHandler {
class FormHandler {
static handleSubmitButtons() {
let elements = document.querySelectorAll("form");
elements.forEach(function (element) {
element.onsubmit = function () {
elements.forEach((element) => {
element.onsubmit = () => {
let button = document.querySelector("button");
if (button) {
@ -274,6 +274,28 @@ class RequestBuilder {
}
}
class UnreadCounterHandler {
static decrement(n) {
this.updateValue((current) => {
return current - n;
});
}
static increment(n) {
this.updateValue((current) => {
return current + n;
});
}
static updateValue(callback) {
let counterElements = document.querySelectorAll("span.unread-counter");
counterElements.forEach((element) => {
let oldValue = parseInt(element.textContent, 10);
element.innerHTML = callback(oldValue);
});
}
}
class EntryHandler {
static updateEntriesStatus(entryIDs, status, callback) {
let url = document.body.dataset.entriesStatusUrl;
@ -295,6 +317,13 @@ class EntryHandler {
element.classList.add("item-status-" + newStatus);
this.updateEntriesStatus([entryID], newStatus);
if (newStatus === "read") {
UnreadCounterHandler.decrement(1);
} else {
UnreadCounterHandler.increment(1);
}
break;
}
}