Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let reminders = await Reminder.incompleteDueThisWeek()
- reminders.sort(function(a, b) { return a.dueDate - b.dueDate })
- let days = 24 * 60 * 60 * 1000
- let count = reminders.length
- let summary
- if (count == 0) {
- summary = "You have nothing due this week. good job!"
- } else {
- summary = "You have " + count + " tasks left:"
- }
- let t = await tableUp(summary)
- // when run with Siri, Siri speaks the summary string
- if (config.runsWithSiri) {
- Speech.speak(summary)
- }
- async function tableUp(summary) {
- let table = new UITable()
- // when not run with Siri, adds a summary header
- if (!config.runsWithSiri) {
- let row = new UITableRow()
- row.isHeader = true
- row.addText(summary)
- table.addRow(row)
- }
- // this part is building the table
- for (reminder of reminders) {
- let row = new UITableRow()
- let title = reminder.title
- // this part is to show how far is the due date
- let dateDifference = reminder.dueDate - new Date()
- let date = Math.round(dateDifference / days)
- let subtitle = "Due in " + date + " days"
- //this part is to implement mark-as-done on select functionality
- row.dismissOnSelect = false
- row.onSelect = (number) => {
- // the number - 1 part is because of the header row
- // the whole tap to done doesn't work in Siri
- // so this will only matter when the header row exists
- let task = reminders[number - 1]
- task.isCompleted = true
- task.completionDate = new Date()
- task.save()
- reminders.splice(number,1)
- table.removeRow(row)
- table.reload()
- }
- let titleCell = row.addText(title, subtitle)
- titleCell.widthWeight = 90
- row.height = 90
- table.addRow(row)
- }
- // showing the table
- return QuickLook.present(table)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement