Ask in the page's own dialog, not confirm(), which the iOS app answered Cancel (#462)

Deleting a downloaded file from the iOS app did nothing: no DELETE reached ipx-web or ipx.
WKWebView answers confirm() Cancel without showing it unless the app implements the panel,
which 614f270 does (#453), but only once the app is rebuilt. ask() is a <dialog> of the
page's own, in the top layer, so it opens over a dialog already up (the file menu, Settings)
and leaves it as it was, and Escape answers it alone. Every confirm() in the page and the
admin page goes through it; the tests answer it rather than the browser's dialog, and the
warning before sharing a feed with its key in the address, untested before, now is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 23:32:15 +00:00
parent d1ba83bb7a
commit eda77e87c7
9 changed files with 77 additions and 36 deletions

View File

@@ -191,7 +191,7 @@ async function drawDirectoryAdmin(){
try{
if(b.dataset.a === 'drop'){
const name = row!.dataset.name!;
if(!confirm(`Drop ${name}'s feeds and counts from the directory? They come back the next time ${name} shares.`)) return;
if(!await ask(`Drop ${name}'s feeds and counts from the directory? They come back the next time ${name} shares.`, 'Drop')) return;
await api(`/api/directory-instances/${encodeURIComponent(name)}`, {method: 'DELETE'});
toast(`Dropped ${name}'s snapshot`);
}else if(b.dataset.a === 'unblock'){
@@ -235,8 +235,8 @@ async function drawAccounts(){
const u = users.find(x => String(x.id) === row.dataset.id)!;
$('[data-a="admin"]', row).onchange = (e: Event) =>
change(u, {method: 'PATCH', body: JSON.stringify({admin: (e.target as HTMLInputElement).checked})});
$('[data-a="rm"]', row).onclick = () => {
if(confirm(`Remove ${u.name}? Their subscriptions and read state go with them. Downloaded files stay.`))
$('[data-a="rm"]', row).onclick = async () => {
if(await ask(`Remove ${u.name}? Their subscriptions and read state go with them. Downloaded files stay.`, 'Remove'))
change(u, {method: 'DELETE'});
};
}

View File

@@ -269,7 +269,7 @@ async function fillShow(box: HTMLElement,p: DirFeed){
catch(e){ toast(why(e),true); }
};
$('[data-a="dremove"]',acts).onclick=async()=>{
if(!confirm(`Remove ${NAME(p)} from the directory? It is blocked, so no server's snapshot brings it back. Admin, Directory can unblock it.`)) return;
if(!await ask(`Remove ${NAME(p)} from the directory? It is blocked, so no server's snapshot brings it back. Admin, Directory can unblock it.`, 'Remove')) return;
try{ await api(`/api/directory/${encodeURIComponent(p.id)}`,{method:'DELETE'}); }
catch(e){ return toast(why(e),true); }
toast(`Removed ${NAME(p)} from the directory`);
@@ -531,11 +531,11 @@ async function prefsModal(){
renderFeeds();
}catch(err){ toast(why(err),true); }
};
$<HTMLInputElement>('#ssigon').onchange=(e: Event)=>{
$<HTMLInputElement>('#ssigon').onchange=async(e: Event)=>{
const on=(e.target as HTMLInputElement).checked;
if(on){ $('#ssigkey').hidden=false; $<HTMLInputElement>('#stskey').focus(); return; }
if(!S.me?.typesafe_key_set){ $('#ssigkey').hidden=true; return; }
if(confirm('Turn Signals off and forget your TypeSafe key? Your signals are kept for when you turn them on again.')) saveKey(null);
if(await ask('Turn Signals off and forget your TypeSafe key? Your signals are kept for when you turn them on again.', 'Turn off')) saveKey(null);
else (e.target as HTMLInputElement).checked=true;
};
$<HTMLInputElement>('#stskey').onchange=(e: Event)=>{ const k=(e.target as HTMLInputElement).value.trim(); if(k) saveKey(k); };

View File

@@ -187,7 +187,7 @@ async function allAction(a: string){
const n=S.feeds.reduce((k,x)=>k+(x.unread||0),0);
if(!n){ toast('Nothing unread'); return; }
// One click across every feed is a lot to take back, so this one asks first.
if(!confirm(`Mark all ${n} unread item${n===1?'':'s'} read, in every feed you subscribe to?`)) return;
if(!await ask(`Mark all ${n} unread item${n===1?'':'s'} read, in every feed you subscribe to?`, 'Mark all read')) return;
try{
const r=await api('/api/read-all',{method:'POST'});
haptic('done'); toast(`Marked ${r.marked} read`); await loadFeeds(true); renderFeed(); loadEntries();

View File

@@ -594,7 +594,7 @@ async function shareEpisode(e: Entry, encId: number|null){
const at=!link.url ? 0 : player.guid===e.guid && player.feed===e.feed_id ? audio.currentTime : e.position;
// A menu rather than the share sheet at once, for the item's own address too: the sheet needs a
// press of its own, and the request above has used up the one that opened this (#452). The
// warning is written here, not asked with confirm(), which the iOS app answers Cancel (#453).
// warning is written here, not asked first, since it is in the menu anyway.
openModal(`<button class="iconbtn cardx" onclick="closeModal()" title="Close" aria-label="Close">${ICON.close}</button>
<h3>Share</h3><p class="hint">${esc(name)}</p>
${link.url ? '' : noLinkNote(link.why, url)}
@@ -641,17 +641,17 @@ async function epAction(a: string, e: Entry, el: HTMLElement|null, encId?: numbe
if(a==='del'){
const f=S.feeds.find(x=>x.id===e.feed_id);
const shared=f&&f.subscribers>1;
if(!confirm(shared
? `Delete this file?\n\nThere is one copy, shared with ${f.subscribers-1} other `
if(!await ask(shared
? `Delete this file? There is one copy, shared with ${f.subscribers-1} other `
+`${f.subscribers===2?'person':'people'} reading this feed. The item stays listed `
+`and will not be downloaded again automatically.`
: 'Delete the downloaded file?\n\nThe item stays listed and will not be downloaded again automatically.')) return;
: 'Delete the downloaded file? The item stays listed and will not be downloaded again automatically.', 'Delete')) return;
try{
await api(`/api/enclosures/${enc.id}`,{method:'DELETE'});
}catch(err){
// 409: somebody else has it starred or unplayed. Their reason, their words.
if(!/one copy of this file/.test(why(err))) throw err;
if(!confirm(why(err)+'\n\nDelete it anyway?')) return;
if(!await ask(why(err), 'Delete it anyway')) return;
await api(`/api/enclosures/${enc.id}?force=true`,{method:'DELETE'});
}
toast('Deleted'); loadEntries(); loadFeeds(true);

View File

@@ -126,7 +126,7 @@ function signalHead(sg: Signal){
async function signalAction(a: string, sg: Signal){
if(a==='settings') signalModal(sg);
if(a==='rm'){
if(!confirm(`Delete the signal ${sg.name}? The items stay in their own feeds.`)) return;
if(!await ask(`Delete the signal ${sg.name}? The items stay in their own feeds.`, 'Delete')) return;
try{
await api(`/api/signals/${sg.id}`,{method:'DELETE'});
toast('Deleted'); await loadFeeds(true); selectFeed(':all');

View File

@@ -18,6 +18,26 @@ function asLink(el: HTMLElement, current: boolean){
}
const ESCAPED: Record<string,string> ={'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'};
const esc = (s: string|null|undefined) => (s??'').replace(/[&<>"']/g,c=>ESCAPED[c]);
/// Asks before something hard to take back, in a dialog of the page's own. Not confirm(): the iOS
/// app answered that Cancel without showing it, so nothing that asked first went ahead there
/// (#453, #462). A <dialog> of its own, in the top layer, so it opens over a dialog already up and
/// leaves it as it was; Escape or a tap on Cancel answers no.
function ask(text: string, yes: string): Promise<boolean>{
const d=document.createElement('dialog');
d.className='card ask';
d.innerHTML=`<p></p><div class="cardacts"><button type="button" class="btn" value="">Cancel</button>
<button type="button" class="btn danger" value="y"></button></div>`;
d.querySelector('p')!.textContent=text;
d.querySelector('[value="y"]')!.textContent=yes;
document.body.append(d);
return new Promise(done=>{
d.onclick=(e: MouseEvent)=>{ const b=(e.target as Element).closest('button'); if(b) d.close(b.value); };
// Escape answers this dialog alone, not the one under it too.
d.onkeydown=(e: KeyboardEvent)=>{ if(e.key==='Escape') e.stopPropagation(); };
d.onclose=()=>{ d.remove(); done(d.returnValue==='y'); };
d.showModal();
});
}
// A feed's link, only if it is a web address: esc() keeps a javascript: or data: one working (#326).
const webUrl = (u: string|null|undefined): string|null => /^https?:\/\//i.test(u??'') ? u! : null;
// Icons: Font Awesome Free 7.3.1 by @fontawesome - https://fontawesome.com
@@ -213,7 +233,7 @@ async function copyText(text: string,btn?: HTMLElement){
/// ponytail: a guess from the address. A private feed whose key has another name is shared
/// without asking; add its pattern here when one turns up.
async function share(title: string, url: string, btn?: HTMLElement){
if(carriesAccess(url) && !confirm(ACCESS_WARNING+'\n\nShare it anyway?')) return;
if(carriesAccess(url) && !await ask(ACCESS_WARNING, 'Share it anyway')) return;
await sendLink(title, url, btn);
}