fix: bound document downloads and cancel stale sessions

This commit is contained in:
2026-09-06 13:56:05 +03:00
parent 34da54a080
commit ae32382ffa
4 changed files with 106 additions and 21 deletions
+14 -4
View File
@@ -16,7 +16,7 @@ const KATEGORILER = ['Yasal Belgeler', 'Kalite Belgeleri', 'Mali Belgeler', 'Res
*/
export const DocumentVault = () => {
const { authUser } = useApp();
return <DocumentVaultSession key={authUser?.email || 'signed-out'} signedIn={Boolean(authUser)} />;
return <DocumentVaultSession key={`${authUser?.email || 'signed-out'}:${getToken()}`} signedIn={Boolean(authUser)} />;
};
const DocumentVaultSession = ({signedIn}) => {
@@ -36,6 +36,15 @@ const DocumentVaultSession = ({signedIn}) => {
const [islemeBilgi, setIslemeBilgi] = useOwnedState(null);
const [kategori, setKategori] = useOwnedState(KATEGORILER[0]);
const dosyaRef = useRef(null);
const downloads = useRef(new Set());
const [downloading,setDownloading] = useOwnedState([]);
const indir = async file => {
if (!current() || downloads.current.has(file.id)) return;
downloads.current.add(file.id);setDownloading([...downloads.current]);setHata(null);
try { await downloadDocument(file.id,file.ad,{signal:readLifetime.current.signal}); }
catch(error) { if(!readLifetime.current.signal.aborted)setHata(error.message); }
finally { downloads.current.delete(file.id);setDownloading([...downloads.current]); }
};
const yukle = () => {
if (!signedIn || !current()) return;
@@ -320,9 +329,10 @@ const DocumentVaultSession = ({signedIn}) => {
Kalemleri yeniden çıkar
</button>
)}
<button onClick={() => downloadDocument(d.id, d.ad).catch((e) => setHata(e.message))}
className="text-slate-400 hover:text-teal-600 p-1" title="İndir">
<Download className="w-4 h-4" />
<button onClick={() => indir(d)} disabled={downloading.includes(d.id) || d.erisilebilir===false}
aria-label={`${d.ad} indir`} aria-busy={downloading.includes(d.id)}
className="text-slate-400 hover:text-teal-600 p-1 disabled:opacity-40" title="İndir">
{downloading.includes(d.id) ? <span role="status" className="text-xs">İndiriliyor…</span> : <Download className="w-4 h-4" />}
</button>
<button onClick={() => sil(d.id)} disabled={busy} className="text-slate-400 hover:text-red-500 p-1" title="Sil">
<Trash2 className="w-4 h-4" />