Repos / pytaku / a607ac0378
commit a607ac03781a4033d1a958efa30940272b2754b5
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sat Sep 4 08:03:03 2021 +0700
add "unread all" button
diff --git a/src/pytaku/js-src/routes/title.js b/src/pytaku/js-src/routes/title.js
index 47739dc..62710ab 100644
--- a/src/pytaku/js-src/routes/title.js
+++ b/src/pytaku/js-src/routes/title.js
@@ -5,8 +5,10 @@ function Title(initialVNode) {
let isLoading = false;
let isTogglingFollow = false;
let isMarkingAllAsRead = false;
+ let isMarkingAllAsUnread = false;
let title = {};
let allAreRead;
+ let allAreUnread;
return {
oninit: (vnode) => {
@@ -33,9 +35,14 @@ function Title(initialVNode) {
view: (vnode) => {
if (!isLoading && Auth.isLoggedIn()) {
allAreRead = true;
+ allAreUnread = true;
for (let chap of title.chapters) {
if (!chap.is_read) {
allAreRead = false;
+ } else {
+ allAreUnread = false;
+ }
+ if (allAreRead === false && allAreUnread === false) {
break;
}
}
@@ -95,6 +102,12 @@ function Title(initialVNode) {
? null
: "Click to mark all chapters as read",
onclick: (ev) => {
+ const confirmed = window.confirm(
+ "Do you surely want to read all chapters?"
+ );
+ if (!confirmed) {
+ return;
+ }
isMarkingAllAsRead = true;
m.redraw();
Auth.request({
@@ -122,6 +135,55 @@ function Title(initialVNode) {
});
},
}),
+ m(Button, {
+ icon: "x-square",
+ disabled:
+ isMarkingAllAsUnread || allAreUnread
+ ? "disabled"
+ : null,
+ text: isMarkingAllAsUnread
+ ? "submitting..."
+ : allAreUnread
+ ? "all unread!"
+ : "unread all",
+ color: "white",
+ title: allAreUnread
+ ? null
+ : "Click to mark all chapters as unread",
+ onclick: (ev) => {
+ const confirmed = window.confirm(
+ "Do you surely want to unread all chapters?"
+ );
+ if (!confirmed) {
+ return;
+ }
+ isMarkingAllAsUnread = true;
+ m.redraw();
+ Auth.request({
+ method: "POST",
+ url: "/api/read",
+ body: {
+ unread: title.chapters
+ .filter((ch) => ch.is_read)
+ .map((ch) => {
+ return {
+ site: title.site,
+ title_id: title.id,
+ chapter_id: ch.id,
+ };
+ }),
+ },
+ })
+ .then((resp) => {
+ title.chapters.forEach((chap) => {
+ chap.is_read = false;
+ });
+ })
+ .finally(() => {
+ isMarkingAllAsUnread = false;
+ });
+ },
+ }),
]
: null,
m(
diff --git a/src/pytaku/static/spa.css b/src/pytaku/static/spa.css
index ea8d676..794b92e 100644
--- a/src/pytaku/static/spa.css
+++ b/src/pytaku/static/spa.css
@@ -379,6 +379,12 @@ @media (max-width: 399px) {
}
}
+@media (min-width: 400px) and (max-width: 500px) {
+ .title--details i {
+ display: none;
+ }
+}
+
/* Chapter route */
.chapter.content {
padding: var(--body-padding) 0;