fix: clear stale weekly preference after concurrent changes

This commit is contained in:
2026-09-06 14:44:25 +03:00
parent 38227862c0
commit 8faf03e632
3 changed files with 17 additions and 2 deletions
+6 -2
View File
@@ -11,7 +11,7 @@ function BriefPanel(){
const [value,setValue]=useState(null),[metin,setMetin]=useState(null),[busy,setBusy]=useState(true),[error,setError]=useState(null),[attempt,setAttempt]=useState(0);
const lifetime=useRef(null),lock=useRef(false);
useEffect(()=>{
const controller=new AbortController();lifetime.current=controller;lock.current=true;setBusy(true);setError(null);
const controller=new AbortController();lifetime.current=controller;lock.current=true;setBusy(true);setError(null);setValue(null);
getWeeklyBrief({signal:controller.signal}).then(data=>{if(!controller.signal.aborted)setValue(data);})
.catch(e=>{if(!controller.signal.aborted)setError(e.message);})
.finally(()=>{if(!controller.signal.aborted){lock.current=false;setBusy(false);}});
@@ -23,7 +23,11 @@ function BriefPanel(){
try{
const data=preview?await getWeeklyBrief({preview:true,signal}):await saveWeeklyBrief(!value.kapali,value.revision,{signal});
if(!signal.aborted){setValue(data);if(preview)setMetin(data.metin);}
}catch(e){if(!signal.aborted)setError(e.message);}
}catch(e){if(!signal.aborted){
if(e.kod==='VERSION_CONFLICT'){
setValue(null);setMetin(null);setError('Bu tercih başka bir sekmede veya cihazda değişti. Güncel durumu görmek için Özet ayarını yenile düğmesine basın.');
}else setError(e.message);
}}
finally{if(!signal.aborted){lock.current=false;setBusy(false);}}
};
return <section aria-label="Haftalık özet ayarı" className="bg-white rounded-2xl border border-slate-200 p-5 space-y-3">