mirror of
https://github.com/miniflux/v2.git
synced 2025-08-21 18:11:09 +00:00
feat(ui): refresh the page when marking as read the last visible entry
This commit is contained in:
parent
cce0e7bd29
commit
5e07278e87
1 changed files with 23 additions and 7 deletions
|
@ -22,6 +22,15 @@ function getVisibleElements(selector) {
|
||||||
return [...elements].filter((element) => element.offsetParent !== null);
|
return [...elements].filter((element) => element.offsetParent !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all visible entries on the current page.
|
||||||
|
*
|
||||||
|
* @return {Array<Element>}
|
||||||
|
*/
|
||||||
|
function getVisibleEntries() {
|
||||||
|
return getVisibleElements(".items .item");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll the page to the given element.
|
* Scroll the page to the given element.
|
||||||
*
|
*
|
||||||
|
@ -152,7 +161,7 @@ function showKeyboardShortcuts() {
|
||||||
|
|
||||||
// Mark as read visible items of the current page.
|
// Mark as read visible items of the current page.
|
||||||
function markPageAsRead() {
|
function markPageAsRead() {
|
||||||
const items = getVisibleElements(".items .item");
|
const items = getVisibleEntries();
|
||||||
const entryIDs = [];
|
const entryIDs = [];
|
||||||
|
|
||||||
items.forEach((element) => {
|
items.forEach((element) => {
|
||||||
|
@ -182,19 +191,22 @@ function markPageAsRead() {
|
||||||
/**
|
/**
|
||||||
* Handle entry status changes from the list view and entry view.
|
* Handle entry status changes from the list view and entry view.
|
||||||
* Focus the next or the previous entry if it exists.
|
* Focus the next or the previous entry if it exists.
|
||||||
* @param {string} item Item to focus: "previous" or "next".
|
*
|
||||||
* @param {Element} element
|
* @param {string} navigationDirection Navigation direction: "previous" or "next".
|
||||||
* @param {boolean} setToRead
|
* @param {Element} element Element that triggered the action.
|
||||||
|
* @param {boolean} setToRead If true, set the entry to read instead of toggling the status.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function handleEntryStatus(item, element, setToRead) {
|
function handleEntryStatus(navigationDirection, element, setToRead) {
|
||||||
const toasting = !element;
|
const toasting = !element;
|
||||||
const currentEntry = findEntry(element);
|
const currentEntry = findEntry(element);
|
||||||
|
|
||||||
if (currentEntry) {
|
if (currentEntry) {
|
||||||
if (!setToRead || currentEntry.querySelector(":is(a, button)[data-toggle-status]").dataset.value === "unread") {
|
if (!setToRead || currentEntry.querySelector(":is(a, button)[data-toggle-status]").dataset.value === "unread") {
|
||||||
toggleEntryStatus(currentEntry, toasting);
|
toggleEntryStatus(currentEntry, toasting);
|
||||||
}
|
}
|
||||||
if (isListView() && currentEntry.classList.contains('current-item')) {
|
if (isListView() && currentEntry.classList.contains('current-item')) {
|
||||||
switch (item) {
|
switch (navigationDirection) {
|
||||||
case "previous":
|
case "previous":
|
||||||
goToListItem(-1);
|
goToListItem(-1);
|
||||||
break;
|
break;
|
||||||
|
@ -248,6 +260,10 @@ function toggleEntryStatus(element, toasting) {
|
||||||
element.classList.remove("item-status-" + currentStatus);
|
element.classList.remove("item-status-" + currentStatus);
|
||||||
element.classList.add("item-status-" + newStatus);
|
element.classList.add("item-status-" + newStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isListView() && getVisibleEntries().length === 0) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +558,7 @@ const BOTTOM = -9999;
|
||||||
* @param {number} offset How many items to jump for focus.
|
* @param {number} offset How many items to jump for focus.
|
||||||
*/
|
*/
|
||||||
function goToListItem(offset) {
|
function goToListItem(offset) {
|
||||||
const items = getVisibleElements(".items .item");
|
const items = getVisibleEntries();
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue