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

feat: Mark above entries as read #2328

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/template/templates/common/item_meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
data-value="{{ if eq .entry.Status "read" }}read{{ else }}unread{{ end }}"
>{{ if eq .entry.Status "read" }}{{ icon "unread" }}{{ else }}{{ icon "read" }}{{ end }}<span class="icon-label">{{ if eq .entry.Status "read" }}{{ t "entry.status.unread" }}{{ else }}{{ t "entry.status.read" }}{{ end }}</span></a>
</li>
<li>
<a href="#"
title="{{ t "Mark above read" }}"
data-action="markAboveAsRead"
data-label-loading="{{ t "confirm.loading" }}"
data-label-unread="{{ t "entry.status.unread" }}"
data-label-read="{{ t "entry.status.read" }}"
data-value="mark-above-read"
>{{ icon "mark-all-as-read" }}<span class="icon-label">Mark above as read</span></a>
</li>
<li class="item-meta-icons-star">
<a href="#"
role="button"
Expand Down
35 changes: 35 additions & 0 deletions internal/ui/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,41 @@ function toggleEntryStatus(element, toasting) {
});
}

// Mark entries above the current as read
function markAboveAsRead(element) {
let allItems = DomHelper.getVisibleElements(".items .item");
let entryIDs = [];

let entryID = parseInt(element.dataset.id, 10);

if (!entryID) return;

for (const element of allItems) {
if (entryID === itemId) {
break;
}

const itemId = parseInt(element.dataset.id, 10);
element.classList.add("item-status-read");
entryIDs.push(itemId);
}

if (entryIDs.length > 0) {
updateEntriesStatus(entryIDs, "read", () => {
// Refresh the page if user wants to hide unread
let element = document.querySelector("a[data-action=markPageAsRead]");
let showOnlyUnread = false;
if (element) {
showOnlyUnread = element.dataset.showOnlyUnread || false;
}

if (showOnlyUnread) {
window.location.href = window.location.href;
}
});
}
}

// Mark a single entry as read.
function markEntryAsRead(element) {
if (element.classList.contains("item-status-unread")) {
Expand Down
7 changes: 7 additions & 0 deletions internal/ui/static/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

onClick("a[data-action=markAboveAsRead]", (event) => {
const entry = findEntry(event.target);

if (entry) {
markAboveAsRead(entry);
}
});
onClick("a[data-save-entry]", (event) => handleSaveEntry(event.target));
onClick("a[data-toggle-bookmark]", (event) => handleBookmark(event.target));
onClick("a[data-fetch-content-entry]", () => handleFetchOriginalContent());
Expand Down