persist imported calendar events per session

This commit is contained in:
2026-09-06 18:43:44 +03:00
parent 580bc6dd9f
commit bdf67e58e4
2 changed files with 10 additions and 2 deletions
+6 -2
View File
@@ -10,7 +10,11 @@ export const TenderCalendar = () => {
const today = istanbulDateKey(now);
const [month,setMonth] = useState(today.slice(0,7));
const [selectedDay, setSelectedDay] = useState(today);
const [imported,setImported] = useState([]), [importError,setImportError] = useState('');
const [imported,setImported] = useState(() => {
try { const saved = JSON.parse(sessionStorage.getItem('ihaleist_imported_calendar') || '[]'); return Array.isArray(saved) && saved.length <= 100 ? saved : []; }
catch { return []; }
}), [importError,setImportError] = useState('');
React.useEffect(() => { try { sessionStorage.setItem('ihaleist_imported_calendar', JSON.stringify(imported)); } catch { /* private browsing can deny storage */ } }, [imported]);
const allTenders = useMemo(() => [...tenders, ...imported], [tenders, imported]);
const agenda=useMemo(()=>calendarAgenda(allTenders,now),[allTenders,now]);
const daysList=calendarMonthDays(month).map(day=>({...day,count:agenda.days.get(day.key)?.length || 0}));
@@ -59,7 +63,7 @@ export const TenderCalendar = () => {
catch(error) { setImported([]); setImportError(error.message); }
event.target.value='';
}} className="block text-xs" />
{imported.length>0&&<p role="status" className="text-xs text-emerald-700">{imported.length} harici etkinlik içe aktarıldı.</p>}
{imported.length>0&&<div className="flex flex-wrap items-center gap-3"><p role="status" className="text-xs text-emerald-700">{imported.length} harici etkinlik içe aktarıldı.</p><button type="button" className="text-xs underline text-slate-700" onClick={()=>setImported([])}>İçe aktarılanları temizle</button></div>}
{importError&&<p role="alert" className="text-xs text-red-700">Takvim içe aktarılamadı: {importError}</p>}
</section>
<div role="group" className="flex flex-wrap gap-2" aria-label="Takvim ayı gezinme">