Page type-check: noImplicitAny, every parameter and variable typed (#235)
290 places the type-check could not see into, mostly parameters, now typed with web/src/types.ts (feeds, items, files, accounts, log lines, the directory's rows and items). Two changes run differently in form only: the seek and volume inputs divide Number(value) where they divided the string, and esc's table has a name. Null checks are #236. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/// One feed's row from the server, in place of the old one (or added, for a feed an OPML just
|
||||
/// listed). A scan sends dozens; the list is redrawn once a frame, not once each.
|
||||
let rowsQueued=0;
|
||||
function patchFeed(row){
|
||||
function patchFeed(row: Feed){
|
||||
const i=S.feeds.findIndex(f=>f.id===row.id);
|
||||
if(i<0) S.feeds.push(row); else S.feeds[i]=row;
|
||||
if(!rowsQueued) rowsQueued=requestAnimationFrame(()=>{ rowsQueued=0; renderFeeds(); });
|
||||
@@ -24,10 +24,10 @@ async function loadFeeds(keepSel?: boolean){
|
||||
}
|
||||
// An OPML can hold dozens of feeds; the ones with something new go first. sort is stable, so the
|
||||
// server's alphabetical order still holds within each half.
|
||||
const unreadFirst=(a,b)=>Number(b.unread>0)-Number(a.unread>0);
|
||||
const unreadFirst=(a: Feed,b: Feed)=>Number(b.unread>0)-Number(a.unread>0);
|
||||
// The original's source list opened with these, above the feeds. They are places, not feeds:
|
||||
// an id starting with ':' can never be a feed's, since feed ids are slugs.
|
||||
const VIEWS={
|
||||
const VIEWS: Record<string,{title: string, icon: string, url?: string, blurb?: string}>={
|
||||
// The Directory holds the most subscribed feeds too, which had a place of their own, Popular (#124).
|
||||
':directory':{title:'Directory',icon:ICON.directory,url:'/api/directory'},
|
||||
':listening':{title:'Currently Listening',icon:ICON.audio,url:'/api/entries?filter=in_progress&limit=50',
|
||||
@@ -108,9 +108,9 @@ function renderFeeds(){
|
||||
// Feeds from a subscribed OPML sit under it, so the group reads as one thing. Pinned feeds
|
||||
// go first: a folder with its feeds under it, a feed from inside one lifted out of it.
|
||||
const byId=Object.fromEntries(shown.map(f=>[f.id,f]));
|
||||
const inside=f=>shown.filter(c=>c.group===f.id&&!c.pinned);
|
||||
const inside=(f: Feed)=>shown.filter(c=>c.group===f.id&&!c.pinned);
|
||||
const tops=shown.filter(f=>f.pinned||!(f.group&&byId[f.group]));
|
||||
const order=[];
|
||||
const order: [Feed, number][]=[];
|
||||
for(const f of [...tops.filter(f=>f.pinned),...tops.filter(f=>!f.pinned)]){
|
||||
order.push([f,0]);
|
||||
// A subscription can hold dozens of feeds, so a folder starts closed. Searching
|
||||
@@ -127,14 +127,14 @@ function renderFeeds(){
|
||||
// A subscription holds no entries itself, so its counts are the sum of what is inside --
|
||||
// taken from every feed it holds, not just the ones a filter left showing.
|
||||
const mine=S.feeds.filter(c=>c.group===f.id);
|
||||
const sum=k=>mine.reduce((n,c)=>n+(c[k]||0),0);
|
||||
const sum=(k: 'unread'|'entries'|'downloaded')=>mine.reduce((n,c)=>n+(c[k]||0),0);
|
||||
const [unread,eps,saved]=mine.length
|
||||
? [sum('unread'),sum('entries'),sum('downloaded')]
|
||||
: [f.unread,f.entries,f.downloaded];
|
||||
// A group's own row has no error of its own worth mentioning if the OPML itself
|
||||
// reads fine; it is failing when any feed inside it is. The feed's own page says what
|
||||
// went wrong (failBannerHTML); the list only has to make it findable.
|
||||
const bad=c=>c.failing?.reason||c.last_error;
|
||||
const bad=(c: Feed)=>c.failing?.reason||c.last_error;
|
||||
const err=mine.length ? mine.map(bad).find(Boolean) : bad(f);
|
||||
const nbad=mine.filter(bad).length;
|
||||
const el=document.createElement('div');
|
||||
@@ -160,14 +160,14 @@ function renderFeeds(){
|
||||
(f.orphaned?'<span class="tag" title="No longer listed, kept because it has downloads">Gone</span>':'')+
|
||||
`<span class="badge${unread?'':' zero'}" title="${unread} unread">${unread>999?'999+':unread}</span>`;
|
||||
el.onclick=()=>{ selectFeed(f.id); nav(false); };
|
||||
if(kids) $('.chev',el).onclick=ev=>{ ev.stopPropagation(); toggleGroup(f.id); };
|
||||
if(kids) $('.chev',el).onclick=(ev: Event)=>{ ev.stopPropagation(); toggleGroup(f.id); };
|
||||
for(const img of $$('img',el)){ const was=drawn.get(img.outerHTML)?.shift(); if(was) img.replaceWith(was); }
|
||||
list.appendChild(el);
|
||||
}
|
||||
paintScanning();
|
||||
done();
|
||||
}
|
||||
function selectFeed(id){
|
||||
function selectFeed(id: string){
|
||||
S.feed=id; S.offset=0; S.sel=null; S.q=''; $('#epSearch').value='';
|
||||
try{ localStorage.setItem('ipx.feed',id); }catch{}
|
||||
renderFeeds(); renderFeed(); loadEntries();
|
||||
@@ -176,14 +176,14 @@ function selectFeed(id){
|
||||
/// A failing feed's error, in plain words with something to do about it, once `failing` is
|
||||
/// set (it has been failing for a day and is a kind worth naming -- see `explain_failure` in
|
||||
/// src/feed.rs). Anything else still shows the raw error, as before.
|
||||
function failBannerHTML(f){
|
||||
function failBannerHTML(f: Feed){
|
||||
if(f.failing) return `<div class="sub" style="color:var(--bad)">${esc(f.failing.reason)}
|
||||
<button type="button" class="btn tiny" data-ffail="unsub">Unsubscribe</button>${
|
||||
f.failing.new_url?` <button type="button" class="btn tiny" data-ffail="newurl">Use the new address</button>`:''}</div>`;
|
||||
if(f.last_error) return `<div class="sub" style="color:var(--bad)">${esc(f.last_error)}</div>`;
|
||||
return '';
|
||||
}
|
||||
function wireFailBanner(box,f){
|
||||
function wireFailBanner(box: ParentNode,f: Feed){
|
||||
const un=$('[data-ffail="unsub"]',box); if(un) un.onclick=()=>removeFeed(f);
|
||||
const nu=$('[data-ffail="newurl"]',box); if(nu) nu.onclick=()=>settingsModal(f,f.failing.new_url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user