aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/static/index.js
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-06-23 03:11:14 +0900
committernsfisis <nsfisis@gmail.com>2025-06-23 03:15:54 +0900
commite95b823f6554f5bad24be1c7f04b2adc763a9f92 (patch)
tree3cb3e220143cf51e4e60b26283a905393aa6ba94 /backend/static/index.js
parent27bfc8f1d9588322d85197e31b7346601cc680b3 (diff)
downloadfeedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.tar.gz
feedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.tar.zst
feedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.zip
refactor: change directory structure
Diffstat (limited to 'backend/static/index.js')
-rw-r--r--backend/static/index.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/backend/static/index.js b/backend/static/index.js
new file mode 100644
index 0000000..6354bbd
--- /dev/null
+++ b/backend/static/index.js
@@ -0,0 +1,47 @@
+const markAllArticles = (feedId, el, read) => {
+ const basePath = window.BASE_PATH;
+ const apiUrl = `${basePath}/api/feeds/${feedId}/${read ? "read" : "unread"}`;
+ fetch(apiUrl, { method: "PUT" })
+ .then((_data) => {
+ el.parentNode.nextElementSibling.remove();
+ el.parentNode.remove();
+ })
+ .catch((error) => {
+ alert(error);
+ });
+};
+
+const markOneArticle = (articleId, el, read) => {
+ const basePath = window.BASE_PATH;
+ const apiUrl = `${basePath}/api/articles/${articleId}/${read ? "read" : "unread"}`;
+ fetch(apiUrl, { method: "PUT" })
+ .then((_data) => {
+ el.parentNode.remove();
+ })
+ .catch((error) => {
+ alert(error);
+ });
+};
+
+document.addEventListener("DOMContentLoaded", () => {
+ document.querySelectorAll(".js-unread-feed").forEach((el) => {
+ el.addEventListener("click", () => {
+ markAllArticles(el.dataset.feedId, el, false);
+ });
+ });
+ document.querySelectorAll(".js-unread-article").forEach((el) => {
+ el.addEventListener("click", () => {
+ markOneArticle(el.dataset.articleId, el, false);
+ });
+ });
+ document.querySelectorAll(".js-read-feed").forEach((el) => {
+ el.addEventListener("click", () => {
+ markAllArticles(el.dataset.feedId, el, true);
+ });
+ });
+ document.querySelectorAll(".js-read-article").forEach((el) => {
+ el.addEventListener("click", () => {
+ markOneArticle(el.dataset.articleId, el, true);
+ });
+ });
+});