-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-event.js
More file actions
38 lines (31 loc) · 1.02 KB
/
create-event.js
File metadata and controls
38 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fm = importModule('countdown/file-manager')
module.exports = async (eventsPath = 'events.json') => {
console.log('Create Event')
const savedEvents = await fm.readEvents(eventsPath)
const alert = new Alert()
alert.title = 'Create Event'
alert.message = 'Event created successfully!'
alert.addAction('OK')
alert.addCancelAction('Cancel')
alert.addTextField('Title')
const month = new Date().getMonth() + 1
alert.addTextField('Month', `${month}`)
alert.addTextField('Day', `${new Date().getDate()}`)
alert.addTextField('Year (optional)')
await alert.present()
const titleRes = alert.textFieldValue(0)
const monthRes = parseInt(alert.textFieldValue(1))
const dayRes = parseInt(alert.textFieldValue(2))
const yearRes = parseInt(alert.textFieldValue(3))
const newEvent = {
title: titleRes,
month: monthRes,
day: dayRes,
year: yearRes,
}
if (titleRes && monthRes && dayRes) {
savedEvents.push(newEvent)
await fm.writeEvents(savedEvents, eventsPath)
return newEvent
}
}