From 95ed6be5c6539d3b5c44fd8505f82cf0e45a7ebc Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Tue, 17 Feb 2026 15:06:42 -0800 Subject: Refine Settings UI: Fix dark mode text colors, split font controls for headers and body, update monospace stack, and soft-deprecate tags --- frontend-vanilla/src/main.test.ts | 8 +- frontend-vanilla/src/main.ts | 26 +++++- frontend-vanilla/src/regression.test.ts | 4 +- frontend-vanilla/src/store.ts | 7 ++ frontend-vanilla/src/style.css | 54 ++++++++++- web/dist/v3/assets/index-BBLioDl6.css | 1 + web/dist/v3/assets/index-C-K96KpW.css | 1 - web/dist/v3/assets/index-C4yUJp1Z.js | 161 ++++++++++++++++++++++++++++++++ web/dist/v3/assets/index-DzN8ggB1.js | 152 ------------------------------ web/dist/v3/index.html | 4 +- 10 files changed, 253 insertions(+), 165 deletions(-) create mode 100644 web/dist/v3/assets/index-BBLioDl6.css delete mode 100644 web/dist/v3/assets/index-C-K96KpW.css create mode 100644 web/dist/v3/assets/index-C4yUJp1Z.js delete mode 100644 web/dist/v3/assets/index-DzN8ggB1.js diff --git a/frontend-vanilla/src/main.test.ts b/frontend-vanilla/src/main.test.ts index 7dddc3f..7cad61a 100644 --- a/frontend-vanilla/src/main.test.ts +++ b/frontend-vanilla/src/main.test.ts @@ -4,12 +4,10 @@ import { router } from './router'; import { renderLayout, renderFeeds, - renderTags, renderFilters, renderItems, renderSettings, fetchFeeds, - fetchTags, fetchItems, init, logout @@ -76,6 +74,7 @@ describe('main application logic', () => { expect(feedList?.innerHTML).toContain('Test Feed'); }); + /* FIXME: Tags feature soft-deprecated it('renderTags should populate tag list', () => { renderLayout(); store.setTags([{ title: 'Test Tag' } as any]); @@ -83,6 +82,7 @@ describe('main application logic', () => { const tagList = document.getElementById('tag-list'); expect(tagList?.innerHTML).toContain('Test Tag'); }); + */ it('renderFilters should update active filter', () => { renderLayout(); @@ -118,6 +118,7 @@ describe('main application logic', () => { expect(store.feeds[0].title).toBe('API Feed'); }); + /* FIXME: Tags feature soft-deprecated it('fetchTags should update store', async () => { vi.mocked(apiFetch).mockResolvedValueOnce({ ok: true, @@ -128,6 +129,7 @@ describe('main application logic', () => { expect(store.tags).toHaveLength(1); expect(store.tags[0].title).toBe('API Tag'); }); + */ it('fetchItems should update store items', async () => { vi.mocked(apiFetch).mockResolvedValueOnce({ @@ -348,6 +350,7 @@ describe('main application logic', () => { getCurrentRouteSpy.mockRestore(); }); + /* FIXME: Tags feature soft-deprecated it('should navigate to tag when clicking tag from settings page', () => { renderLayout(); store.setTags([{ title: 'Tech' } as any]); @@ -363,6 +366,7 @@ describe('main application logic', () => { expect(navigateSpy).toHaveBeenCalledWith('/tag/Tech', expect.any(Object)); getCurrentRouteSpy.mockRestore(); }); + */ it('deleteFeed should call API', async () => { vi.mocked(apiFetch).mockResolvedValueOnce({ ok: true } as Response); diff --git a/frontend-vanilla/src/main.ts b/frontend-vanilla/src/main.ts index 4e1d216..62a47cc 100644 --- a/frontend-vanilla/src/main.ts +++ b/frontend-vanilla/src/main.ts @@ -23,7 +23,8 @@ let appEl: HTMLDivElement | null = null; export function renderLayout() { appEl = document.querySelector('#app'); if (!appEl) return; - appEl.className = `theme-${store.theme} font-${store.fontTheme}`; + // Apply both font themes (font-* for body, heading-font-* for headers) + appEl.className = `theme-${store.theme} font-${store.fontTheme} heading-font-${store.headingFontTheme}`; appEl.innerHTML = `
@@ -394,6 +395,15 @@ export function renderSettings() {
+ + + + +
+ + + + + + +
+
+
+ + `,q())}function q(){document.getElementById("search-input")?.addEventListener("input",s=>{const o=s.target.value;r.updateQuery({q:o})}),document.getElementById("logo-link")?.addEventListener("click",()=>r.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),X()}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{n.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{n.setSidebarVisible(!1)}),document.querySelectorAll(".sidebar-section.collapsible h3").forEach(s=>{s.addEventListener("click",()=>{s.parentElement?.classList.toggle("collapsed")})}),document.getElementById("sidebar")?.addEventListener("click",s=>{const o=s.target,d=o.closest("a");if(!d){o.classList.contains("logo")&&(s.preventDefault(),r.navigate("/",{}));return}const h=d.getAttribute("data-nav"),g=Object.fromEntries(r.getCurrentRoute().query.entries());if(h==="filter"){s.preventDefault();const u=d.getAttribute("data-value");r.getCurrentRoute().path==="/settings"?r.navigate("/",{...g,filter:u}):r.updateQuery({filter:u})}else if(h==="tag"){s.preventDefault();const u=d.getAttribute("data-value");r.navigate(`/tag/${encodeURIComponent(u)}`,g)}else if(h==="feed"){s.preventDefault();const u=d.getAttribute("data-value"),l=r.getCurrentRoute();n.activeFeedId===parseInt(u)&&l.path!=="/settings"?r.navigate("/",g):r.navigate(`/feed/${u}`,g)}else h==="settings"&&(s.preventDefault(),r.getCurrentRoute().path==="/settings"?r.navigate("/",g):r.navigate("/settings",g));window.innerWidth<=768&&n.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const o=s.target,d=o.closest('[data-action="toggle-star"]');if(d){const l=d.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));j(v)}return}const h=o.closest('[data-action="scrape"]');if(h){const l=h.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));V(v)}return}const g=o.closest('[data-action="open"]'),u=o.closest(".feed-item");if(u&&!g){const l=parseInt(u.getAttribute("data-id"));c=l,document.querySelectorAll(".feed-item").forEach(b=>{const R=parseInt(b.getAttribute("data-id")||"0");b.classList.toggle("selected",R===c)});const v=n.items.find(b=>b._id===l);v&&!v.read&&p(l,{read:!0})}})}function k(){const{feeds:t,activeFeedId:e}=n,i=document.getElementById("feed-list");i&&(i.innerHTML=t.map(a=>` +
  • + + ${a.title||a.url} + +
  • + `).join(""))}function $(){}function F(){const{filter:t}=n,e=document.getElementById("filter-list");e&&e.querySelectorAll("li").forEach(i=>{i.classList.toggle("active",i.getAttribute("data-filter")===t)})}function w(){const{items:t,loading:e}=n,i=document.getElementById("content-area");if(!i||r.getCurrentRoute().path==="/settings")return;if(e&&t.length===0){i.innerHTML='

    Loading items...

    ';return}if(t.length===0){i.innerHTML='

    No items found.

    ';return}i.innerHTML=` + + ${n.hasMore?'
    Loading more...
    ':""} + `;const a=document.getElementById("main-content");if(a){let s=null;a.onscroll=()=>{!n.loading&&n.hasMore&&a.scrollHeight>a.clientHeight&&a.scrollHeight-a.scrollTop-a.clientHeight<200&&T(),s===null&&(s=window.setTimeout(()=>{_(a),s=null},250))}}}function _(t){const e=t.getBoundingClientRect();n.items.forEach(i=>{if(i.read)return;const a=document.querySelector(`.feed-item[data-id="${i._id}"]`);a&&a.getBoundingClientRect().bottom{const t=document.getElementById("main-content");if(n.loading||!n.hasMore)return;if(t&&(_(t),t.scrollHeight>t.clientHeight&&t.scrollHeight-t.scrollTop-t.clientHeight<200)){T();return}const e=document.documentElement.scrollHeight||document.body.scrollHeight,i=window.innerHeight,a=window.scrollY||document.documentElement.scrollTop;e>i&&e-i-a<200&&T()},1e3);function I(){const t=document.getElementById("content-area");if(!t)return;t.innerHTML=` +
    +

    Settings

    + +
    +
    +

    Data

    + +
    +
    + + + +
    + +
    +
    + +
    +

    Theme

    +
    +
    + + +
    +
    +
    + + + + + +
    +
    +
    + +
    +

    Manage Feeds

    + +
    + + +
    + +
      + ${n.feeds.map(a=>` +
    • +
      +
      ${a.title||a.url}
      +
      ${a.url}
      +
      +
      + + +
      +
    • + `).join("")} +
    +
    +
    + `,document.getElementById("theme-options")?.addEventListener("click",a=>{const s=a.target.closest("button");s&&(n.setTheme(s.getAttribute("data-theme")),I())}),document.getElementById("heading-font-selector")?.addEventListener("change",a=>{n.setHeadingFontTheme(a.target.value)}),document.getElementById("font-selector")?.addEventListener("change",a=>{n.setFontTheme(a.target.value)}),document.getElementById("add-feed-btn")?.addEventListener("click",async()=>{const a=document.getElementById("new-feed-url"),s=a.value.trim();s&&(await N(s)?(a.value="",alert("Feed added successfully!"),y()):alert("Failed to add feed."))});let e="opml";const i=document.getElementById("import-file");document.querySelectorAll(".import-btn").forEach(a=>{a.addEventListener("click",s=>{e=s.currentTarget.getAttribute("data-format")||"opml",i.click()})}),i?.addEventListener("change",async a=>{const s=a.target.files?.[0];s&&(await x(s,e)?(alert(`Import (${e}) started! check logs.`),y()):alert("Failed to import.")),i.value=""}),document.querySelectorAll(".delete-feed-btn").forEach(a=>{a.addEventListener("click",async s=>{const o=parseInt(s.target.getAttribute("data-id"));confirm("Delete this feed?")&&(await Q(o),await y(),I())})})}async function N(t){try{return(await f("/api/feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})})).ok}catch(e){return console.error("Failed to add feed",e),!1}}async function x(t,e){try{const i=new FormData;i.append("file",t),i.append("format",e);const a=document.cookie.split("; ").find(o=>o.startsWith("csrf_token="))?.split("=")[1];return(await fetch("/api/import",{method:"POST",headers:{"X-CSRF-Token":a||""},body:i})).ok}catch(i){return console.error("Failed to import",i),!1}}async function Q(t){try{return(await f(`/api/feed/${t}`,{method:"DELETE"})).ok}catch(e){return console.error("Failed to delete feed",e),!1}}async function j(t){const e=n.items.find(i=>i._id===t);e&&p(t,{starred:!e.starred})}async function V(t){if(n.items.find(i=>i._id===t))try{const i=await f(`/api/item/${t}/content`);if(i.ok){const a=await i.json();a.full_content&&p(t,{full_content:a.full_content})}}catch(i){console.error("Failed to fetch full content",i)}}async function p(t,e){try{if((await f(`/api/item/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok){const a=n.items.find(s=>s._id===t);if(a){Object.assign(a,e);const s=document.querySelector(`.feed-item[data-id="${t}"]`);if(s){if(e.read!==void 0&&s.classList.toggle("read",e.read),e.starred!==void 0){const o=s.querySelector(".star-btn");o&&(o.classList.toggle("is-starred",e.starred),o.classList.toggle("is-unstarred",!e.starred),o.setAttribute("title",e.starred?"Unstar":"Star"))}e.full_content&&w()}}}}catch(i){console.error("Failed to update item",i)}}async function y(){const t=await f("/api/feed/");if(t.ok){const e=await t.json();n.setFeeds(e)}}async function U(){const t=await f("/api/tag");if(t.ok){const e=await t.json();n.setTags(e)}}async function E(t,e,i=!1){n.setLoading(!0);try{const a=new URLSearchParams;t&&a.append("feed_id",t),e&&a.append("tag",e),n.searchQuery&&a.append("q",n.searchQuery),(n.filter==="starred"||n.filter==="all")&&a.append("read_filter","all"),n.filter==="starred"&&a.append("starred","true"),i&&n.items.length>0&&a.append("max_id",String(n.items[n.items.length-1]._id));const s=await f(`/api/stream?${a.toString()}`);if(s.ok){const o=await s.json();n.setHasMore(o.length>0),n.setItems(o,i)}}finally{n.setLoading(!1)}}async function T(){const t=r.getCurrentRoute();E(t.params.feedId,t.params.tagName,!0)}async function X(){await f("/api/logout",{method:"POST"}),window.location.href="/login/"}function S(){const t=r.getCurrentRoute(),e=t.query.get("filter");n.setFilter(e||"unread");const i=t.query.get("q");if(i!==null&&n.setSearchQuery(i),t.path==="/settings"){I();return}if(t.path==="/feed"&&t.params.feedId){const a=parseInt(t.params.feedId);n.setActiveFeed(a),E(t.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else t.path==="/tag"&&t.params.tagName?(n.setActiveTag(t.params.tagName),E(void 0,t.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(n.setActiveFeed(null),n.setActiveTag(null),E())}window.addEventListener("keydown",t=>{if(!["INPUT","TEXTAREA"].includes(t.target.tagName))switch(t.key){case"j":L(1);break;case"k":L(-1);break;case"r":if(c){const e=n.items.find(i=>i._id===c);e&&p(e._id,{read:!e.read})}break;case"s":if(c){const e=n.items.find(i=>i._id===c);e&&p(e._id,{starred:!e.starred})}break;case"/":t.preventDefault(),document.getElementById("search-input")?.focus();break}});function L(t){if(n.items.length===0)return;const e=n.items.findIndex(a=>a._id===c);let i;if(e===-1?i=t>0?0:n.items.length-1:i=e+t,i>=0&&i{const o=parseInt(s.getAttribute("data-id")||"0");s.classList.toggle("selected",o===c)});const a=document.querySelector(`.feed-item[data-id="${c}"]`);a&&a.scrollIntoView({block:"start",behavior:"smooth"}),n.items[i].read||p(c,{read:!0})}}n.on("feeds-updated",k);n.on("tags-updated",$);n.on("active-feed-updated",k);n.on("active-tag-updated",$);n.on("filter-updated",F);n.on("search-updated",()=>{const t=document.getElementById("search-input");t&&t.value!==n.searchQuery&&(t.value=n.searchQuery),S()});n.on("theme-updated",()=>{m||(m=document.querySelector("#app")),m&&(m.className=`theme-${n.theme} font-${n.fontTheme} heading-font-${n.headingFontTheme}`),r.getCurrentRoute().path==="/settings"&&I()});n.on("sidebar-toggle",()=>{const t=document.querySelector(".layout");t&&(n.sidebarVisible?(t.classList.remove("sidebar-hidden"),t.classList.add("sidebar-visible")):(t.classList.remove("sidebar-visible"),t.classList.add("sidebar-hidden")))});n.on("items-updated",w);n.on("loading-state-changed",w);r.addEventListener("route-changed",S);window.app={navigate:t=>r.navigate(t)};async function J(){const t=await f("/api/auth");if(!t||t.status===401){window.location.href="/login/";return}D(),F();try{await Promise.all([y(),U()])}catch(e){console.error("Initial fetch failed",e)}S()}typeof window<"u"&&!window.__VITEST__&&J(); diff --git a/web/dist/v3/assets/index-DzN8ggB1.js b/web/dist/v3/assets/index-DzN8ggB1.js deleted file mode 100644 index fc0f9fe..0000000 --- a/web/dist/v3/assets/index-DzN8ggB1.js +++ /dev/null @@ -1,152 +0,0 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))a(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const d of r.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&a(d)}).observe(document,{childList:!0,subtree:!0});function i(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function a(s){if(s.ep)return;s.ep=!0;const r=i(s);fetch(s.href,r)}})();function A(e){const i=`; ${document.cookie}`.split(`; ${e}=`);if(i.length===2)return i.pop()?.split(";").shift()}async function f(e,t){const i=t?.method?.toUpperCase()||"GET",a=["POST","PUT","DELETE"].includes(i),s=new Headers(t?.headers||{});if(a){const r=A("csrf_token");r&&s.set("X-CSRF-Token",r)}return fetch(e,{...t,headers:s,credentials:"include"})}function C(){const e=document.cookie.split("; ").find(t=>t.startsWith("neko_sidebar="));return e?e.split("=")[1]==="1":null}function B(e){document.cookie=`neko_sidebar=${e?"1":"0"}; path=/; max-age=31536000; SameSite=Lax`}function P(){const e=C();return e!==null?e:window.innerWidth>1024}class O extends EventTarget{feeds=[];tags=[];items=[];activeFeedId=null;activeTagName=null;filter="unread";searchQuery="";loading=!1;hasMore=!0;theme=localStorage.getItem("neko-theme")||"light";fontTheme=localStorage.getItem("neko-font-theme")||"default";sidebarVisible=P();setFeeds(t){this.feeds=t,this.emit("feeds-updated")}setTags(t){this.tags=t,this.emit("tags-updated")}setItems(t,i=!1){i?this.items=[...this.items,...t]:this.items=t,this.emit("items-updated")}setActiveFeed(t){this.activeFeedId=t,this.activeTagName=null,this.emit("active-feed-updated")}setActiveTag(t){this.activeTagName=t,this.activeFeedId=null,this.emit("active-tag-updated")}setFilter(t){this.filter!==t&&(this.filter=t,this.emit("filter-updated"))}setSearchQuery(t){this.searchQuery!==t&&(this.searchQuery=t,this.emit("search-updated"))}setLoading(t){this.loading=t,this.emit("loading-state-changed")}setHasMore(t){this.hasMore=t}setTheme(t){this.theme=t,localStorage.setItem("neko-theme",t),this.emit("theme-updated")}setFontTheme(t){this.fontTheme=t,localStorage.setItem("neko-font-theme",t),this.emit("theme-updated")}setSidebarVisible(t){this.sidebarVisible=t,B(t),this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){this.addEventListener(t,i)}}const n=new O;class M extends EventTarget{constructor(){super(),window.addEventListener("popstate",()=>this.handleRouteChange())}handleRouteChange(){this.dispatchEvent(new CustomEvent("route-changed",{detail:this.getCurrentRoute()}))}getCurrentRoute(){const t=new URL(window.location.href),a=t.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let s="/";const r={};return a[0]==="feed"&&a[1]?(s="/feed",r.feedId=a[1]):a[0]==="tag"&&a[1]?(s="/tag",r.tagName=decodeURIComponent(a[1])):a[0]==="settings"&&(s="/settings"),{path:s,params:r,query:t.searchParams}}navigate(t,i){let a=`/v3${t}`;if(i){const s=new URLSearchParams(i);a+=`?${s.toString()}`}window.history.pushState({},"",a),this.handleRouteChange()}updateQuery(t){const i=new URL(window.location.href);for(const[a,s]of Object.entries(t))s?i.searchParams.set(a,s):i.searchParams.delete(a);window.history.pushState({},"",i.toString()),this.handleRouteChange()}}const o=new M;function H(e,t=!1){const i=new Date(e.publish_date).toLocaleDateString();return` -
  • - - - ${e.full_content||e.description?` -
    - ${e.full_content||e.description} -
    - `:""} -
  • - `}let c=null,m=null;function D(){m=document.querySelector("#app"),m&&(m.className=`theme-${n.theme} font-${n.fontTheme}`,m.innerHTML=` -
    - - - -
    -
    -
    -
    - `,q())}function q(){document.getElementById("search-input")?.addEventListener("input",s=>{const r=s.target.value;o.updateQuery({q:r})}),document.getElementById("logo-link")?.addEventListener("click",()=>o.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),X()}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{n.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{n.setSidebarVisible(!1)}),document.querySelectorAll(".sidebar-section.collapsible h3").forEach(s=>{s.addEventListener("click",()=>{s.parentElement?.classList.toggle("collapsed")})}),document.getElementById("sidebar")?.addEventListener("click",s=>{const r=s.target,d=r.closest("a");if(!d){r.classList.contains("logo")&&(s.preventDefault(),o.navigate("/",{}));return}const h=d.getAttribute("data-nav"),g=Object.fromEntries(o.getCurrentRoute().query.entries());if(h==="filter"){s.preventDefault();const u=d.getAttribute("data-value");o.getCurrentRoute().path==="/settings"?o.navigate("/",{...g,filter:u}):o.updateQuery({filter:u})}else if(h==="tag"){s.preventDefault();const u=d.getAttribute("data-value");o.navigate(`/tag/${encodeURIComponent(u)}`,g)}else if(h==="feed"){s.preventDefault();const u=d.getAttribute("data-value"),l=o.getCurrentRoute();n.activeFeedId===parseInt(u)&&l.path!=="/settings"?o.navigate("/",g):o.navigate(`/feed/${u}`,g)}else h==="settings"&&(s.preventDefault(),o.getCurrentRoute().path==="/settings"?o.navigate("/",g):o.navigate("/settings",g));window.innerWidth<=768&&n.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const r=s.target,d=r.closest('[data-action="toggle-star"]');if(d){const l=d.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));j(v)}return}const h=r.closest('[data-action="scrape"]');if(h){const l=h.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));V(v)}return}const g=r.closest('[data-action="open"]'),u=r.closest(".feed-item");if(u&&!g){const l=parseInt(u.getAttribute("data-id"));c=l,document.querySelectorAll(".feed-item").forEach(b=>{const F=parseInt(b.getAttribute("data-id")||"0");b.classList.toggle("selected",F===c)});const v=n.items.find(b=>b._id===l);v&&!v.read&&p(l,{read:!0})}})}function k(){const{feeds:e,activeFeedId:t}=n,i=document.getElementById("feed-list");i&&(i.innerHTML=e.map(a=>` -
  • - - ${a.title||a.url} - -
  • - `).join(""))}function $(){}function _(){const{filter:e}=n,t=document.getElementById("filter-list");t&&t.querySelectorAll("li").forEach(i=>{i.classList.toggle("active",i.getAttribute("data-filter")===e)})}function T(){const{items:e,loading:t}=n,i=document.getElementById("content-area");if(!i||o.getCurrentRoute().path==="/settings")return;if(t&&e.length===0){i.innerHTML='

    Loading items...

    ';return}if(e.length===0){i.innerHTML='

    No items found.

    ';return}i.innerHTML=` -
      - ${e.map(s=>H(s,s._id===c)).join("")} -
    - ${n.hasMore?'
    Loading more...
    ':""} - `;const a=document.getElementById("main-content");if(a){let s=null;a.onscroll=()=>{!n.loading&&n.hasMore&&a.scrollHeight>a.clientHeight&&a.scrollHeight-a.scrollTop-a.clientHeight<200&&w(),s===null&&(s=window.setTimeout(()=>{R(a),s=null},250))}}}function R(e){const t=e.getBoundingClientRect();n.items.forEach(i=>{if(i.read)return;const a=document.querySelector(`.feed-item[data-id="${i._id}"]`);a&&a.getBoundingClientRect().bottom{const e=document.getElementById("main-content");if(n.loading||!n.hasMore)return;if(e&&(R(e),e.scrollHeight>e.clientHeight&&e.scrollHeight-e.scrollTop-e.clientHeight<200)){w();return}const t=document.documentElement.scrollHeight||document.body.scrollHeight,i=window.innerHeight,a=window.scrollY||document.documentElement.scrollTop;t>i&&t-i-a<200&&w()},1e3);function I(){const e=document.getElementById("content-area");if(!e)return;e.innerHTML=` -
    -

    Settings

    - -
    -
    -

    Data

    - -
    -
    - - - -
    - -
    -
    - -
    -

    Theme

    -
    -
    - - -
    -
    -
    - -
    -
    -
    - -
    -

    Manage Feeds

    - -
    - - -
    - -
      - ${n.feeds.map(a=>` -
    • -
      -
      ${a.title||a.url}
      -
      ${a.url}
      -
      -
      - - -
      -
    • - `).join("")} -
    -
    -
    - `,document.getElementById("theme-options")?.addEventListener("click",a=>{const s=a.target.closest("button");s&&(n.setTheme(s.getAttribute("data-theme")),I())}),document.getElementById("font-selector")?.addEventListener("change",a=>{n.setFontTheme(a.target.value)}),document.getElementById("add-feed-btn")?.addEventListener("click",async()=>{const a=document.getElementById("new-feed-url"),s=a.value.trim();s&&(await N(s)?(a.value="",alert("Feed added successfully!"),y()):alert("Failed to add feed."))});let t="opml";const i=document.getElementById("import-file");document.querySelectorAll(".import-btn").forEach(a=>{a.addEventListener("click",s=>{t=s.currentTarget.getAttribute("data-format")||"opml",i.click()})}),i?.addEventListener("change",async a=>{const s=a.target.files?.[0];s&&(await x(s,t)?(alert(`Import (${t}) started! check logs.`),y()):alert("Failed to import.")),i.value=""}),document.querySelectorAll(".delete-feed-btn").forEach(a=>{a.addEventListener("click",async s=>{const r=parseInt(s.target.getAttribute("data-id"));confirm("Delete this feed?")&&(await Q(r),await y(),I())})})}async function N(e){try{return(await f("/api/feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})})).ok}catch(t){return console.error("Failed to add feed",t),!1}}async function x(e,t){try{const i=new FormData;i.append("file",e),i.append("format",t);const a=document.cookie.split("; ").find(r=>r.startsWith("csrf_token="))?.split("=")[1];return(await fetch("/api/import",{method:"POST",headers:{"X-CSRF-Token":a||""},body:i})).ok}catch(i){return console.error("Failed to import",i),!1}}async function Q(e){try{return(await f(`/api/feed/${e}`,{method:"DELETE"})).ok}catch(t){return console.error("Failed to delete feed",t),!1}}async function j(e){const t=n.items.find(i=>i._id===e);t&&p(e,{starred:!t.starred})}async function V(e){if(n.items.find(i=>i._id===e))try{const i=await f(`/api/item/${e}/content`);if(i.ok){const a=await i.json();a.full_content&&p(e,{full_content:a.full_content})}}catch(i){console.error("Failed to fetch full content",i)}}async function p(e,t){try{if((await f(`/api/item/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok){const a=n.items.find(s=>s._id===e);if(a){Object.assign(a,t);const s=document.querySelector(`.feed-item[data-id="${e}"]`);if(s){if(t.read!==void 0&&s.classList.toggle("read",t.read),t.starred!==void 0){const r=s.querySelector(".star-btn");r&&(r.classList.toggle("is-starred",t.starred),r.classList.toggle("is-unstarred",!t.starred),r.setAttribute("title",t.starred?"Unstar":"Star"))}t.full_content&&T()}}}}catch(i){console.error("Failed to update item",i)}}async function y(){const e=await f("/api/feed/");if(e.ok){const t=await e.json();n.setFeeds(t)}}async function U(){const e=await f("/api/tag");if(e.ok){const t=await e.json();n.setTags(t)}}async function E(e,t,i=!1){n.setLoading(!0);try{const a=new URLSearchParams;e&&a.append("feed_id",e),t&&a.append("tag",t),n.searchQuery&&a.append("q",n.searchQuery),(n.filter==="starred"||n.filter==="all")&&a.append("read_filter","all"),n.filter==="starred"&&a.append("starred","true"),i&&n.items.length>0&&a.append("max_id",String(n.items[n.items.length-1]._id));const s=await f(`/api/stream?${a.toString()}`);if(s.ok){const r=await s.json();n.setHasMore(r.length>0),n.setItems(r,i)}}finally{n.setLoading(!1)}}async function w(){const e=o.getCurrentRoute();E(e.params.feedId,e.params.tagName,!0)}async function X(){await f("/api/logout",{method:"POST"}),window.location.href="/login/"}function L(){const e=o.getCurrentRoute(),t=e.query.get("filter");n.setFilter(t||"unread");const i=e.query.get("q");if(i!==null&&n.setSearchQuery(i),e.path==="/settings"){I();return}if(e.path==="/feed"&&e.params.feedId){const a=parseInt(e.params.feedId);n.setActiveFeed(a),E(e.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else e.path==="/tag"&&e.params.tagName?(n.setActiveTag(e.params.tagName),E(void 0,e.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(n.setActiveFeed(null),n.setActiveTag(null),E())}window.addEventListener("keydown",e=>{if(!["INPUT","TEXTAREA"].includes(e.target.tagName))switch(e.key){case"j":S(1);break;case"k":S(-1);break;case"r":if(c){const t=n.items.find(i=>i._id===c);t&&p(t._id,{read:!t.read})}break;case"s":if(c){const t=n.items.find(i=>i._id===c);t&&p(t._id,{starred:!t.starred})}break;case"/":e.preventDefault(),document.getElementById("search-input")?.focus();break}});function S(e){if(n.items.length===0)return;const t=n.items.findIndex(a=>a._id===c);let i;if(t===-1?i=e>0?0:n.items.length-1:i=t+e,i>=0&&i{const r=parseInt(s.getAttribute("data-id")||"0");s.classList.toggle("selected",r===c)});const a=document.querySelector(`.feed-item[data-id="${c}"]`);a&&a.scrollIntoView({block:"start",behavior:"smooth"}),n.items[i].read||p(c,{read:!0})}}n.on("feeds-updated",k);n.on("tags-updated",$);n.on("active-feed-updated",k);n.on("active-tag-updated",$);n.on("filter-updated",_);n.on("search-updated",()=>{const e=document.getElementById("search-input");e&&e.value!==n.searchQuery&&(e.value=n.searchQuery),L()});n.on("theme-updated",()=>{m||(m=document.querySelector("#app")),m&&(m.className=`theme-${n.theme} font-${n.fontTheme}`)});n.on("sidebar-toggle",()=>{const e=document.querySelector(".layout");e&&(n.sidebarVisible?(e.classList.remove("sidebar-hidden"),e.classList.add("sidebar-visible")):(e.classList.remove("sidebar-visible"),e.classList.add("sidebar-hidden")))});n.on("items-updated",T);n.on("loading-state-changed",T);o.addEventListener("route-changed",L);window.app={navigate:e=>o.navigate(e)};async function J(){const e=await f("/api/auth");if(!e||e.status===401){window.location.href="/login/";return}D(),_();try{await Promise.all([y(),U()])}catch(t){console.error("Initial fetch failed",t)}L()}typeof window<"u"&&!window.__VITEST__&&J(); diff --git a/web/dist/v3/index.html b/web/dist/v3/index.html index c9551c4..9b4448a 100644 --- a/web/dist/v3/index.html +++ b/web/dist/v3/index.html @@ -5,8 +5,8 @@ neko - - + +
    -- cgit v1.2.3