From e95b823f6554f5bad24be1c7f04b2adc763a9f92 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Jun 2025 03:11:14 +0900 Subject: refactor: change directory structure --- backend/static/favicon.svg | 7 +++++++ backend/static/index.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 backend/static/favicon.svg create mode 100644 backend/static/index.js (limited to 'backend/static') diff --git a/backend/static/favicon.svg b/backend/static/favicon.svg new file mode 100644 index 0000000..3602b2c --- /dev/null +++ b/backend/static/favicon.svg @@ -0,0 +1,7 @@ + + + + + + + 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); + }); + }); +}); -- cgit v1.2.3-70-g09d2