bulk ai event creation

This commit is contained in:
2025-08-15 22:13:14 -04:00
parent b4c59bbde0
commit a41d003401
2 changed files with 47 additions and 22 deletions

View File

@@ -139,21 +139,42 @@ export default function HomePage() {
body: JSON.stringify({ prompt: aiPrompt })
})
const data = await res.json()
if (data.title) {
setTitle(data.title || '')
setDescription(data.description || '')
setLocation(data.location || '')
setUrl(data.url || '')
setStart(data.start || '')
setEnd(data.end || '')
setAllDay(data.allDay || false)
setEditingId(null)
setDialogOpen(true)
if (Array.isArray(data) && data.length > 0) {
if (data.length === 1) {
// Prefill dialog directly (same as before)
const ev = data[0]
setTitle(ev.title || '')
setDescription(ev.description || '')
setLocation(ev.location || '')
setUrl(ev.url || '')
setStart(ev.start || '')
setEnd(ev.end || '')
setAllDay(ev.allDay || false)
setEditingId(null)
setDialogOpen(true)
} else {
// Save them all directly to DB
for (const ev of data) {
const newEvent = {
id: nanoid(),
...ev,
createdAt: new Date().toISOString(),
lastModified: new Date().toISOString(),
}
await addEvent(newEvent)
}
const stored = await getAllEvents()
setEvents(stored)
setSummary(`Added ${data.length} AI-generated events.`)
setSummaryUpdated(new Date().toLocaleString())
}
} else {
alert('AI could not parse event.')
alert('AI did not return event data.')
}
} catch {
alert('Error creating event')
} catch (err) {
console.error(err)
alert('Error from AI service.')
} finally {
setAiLoading(false)
}