{
  "$schema": "./.schemas/page.schema.json",
  "title": "Tasks",
  "icon": "checklist",
  "sources": {
    "tasks": {
      "url": "https://api.notion.com",
      "secret": "notion",
      "every": "5m",
      "headers": {
        "Notion-Version": "2026-03-11"
      },
      "requests": {
        "today": {
          "path": "/v1/data_sources/0f3c7a52-6b1e-4d8a-9c2f-7e5b1a4d9c30/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Done"
                  }
                },
                {
                  "property": "Due date",
                  "date": {
                    "equals": "{date.today}"
                  }
                }
              ]
            },
            "sorts": [
              {
                "property": "Due date",
                "direction": "ascending"
              },
              {
                "timestamp": "created_time",
                "direction": "ascending"
              }
            ],
            "page_size": 30
          }
        },
        "overdue": {
          "path": "/v1/data_sources/0f3c7a52-6b1e-4d8a-9c2f-7e5b1a4d9c30/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Done"
                  }
                },
                {
                  "property": "Due date",
                  "date": {
                    "before": "{date.today}"
                  }
                }
              ]
            },
            "sorts": [
              {
                "property": "Due date",
                "direction": "ascending"
              },
              {
                "timestamp": "created_time",
                "direction": "ascending"
              }
            ],
            "page_size": 30
          }
        },
        "upcoming": {
          "path": "/v1/data_sources/0f3c7a52-6b1e-4d8a-9c2f-7e5b1a4d9c30/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Done"
                  }
                },
                {
                  "property": "Due date",
                  "date": {
                    "after": "{date.today}"
                  }
                },
                {
                  "property": "Due date",
                  "date": {
                    "on_or_before": "{date.days_ahead_7}"
                  }
                }
              ]
            },
            "sorts": [
              {
                "property": "Due date",
                "direction": "ascending"
              },
              {
                "timestamp": "created_time",
                "direction": "ascending"
              }
            ],
            "page_size": 60
          }
        },
        "undated": {
          "path": "/v1/data_sources/0f3c7a52-6b1e-4d8a-9c2f-7e5b1a4d9c30/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Done"
                  }
                },
                {
                  "property": "Due date",
                  "date": {
                    "is_empty": true
                  }
                }
              ]
            },
            "sorts": [
              {
                "timestamp": "created_time",
                "direction": "ascending"
              }
            ],
            "page_size": 60
          }
        },
        "done": {
          "path": "/v1/data_sources/0f3c7a52-6b1e-4d8a-9c2f-7e5b1a4d9c30/query",
          "method": "POST",
          "body": {
            "filter": {
              "property": "Status",
              "status": {
                "equals": "Done"
              }
            },
            "sorts": [
              {
                "timestamp": "last_edited_time",
                "direction": "descending"
              }
            ],
            "page_size": 4
          }
        }
      },
      "derive": [
        {
          "name": "today_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "today.has_more",
                  "equals": true
                },
                {
                  "path": "today.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "overdue_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "overdue.has_more",
                  "equals": true
                },
                {
                  "path": "overdue.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "upcoming_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "upcoming.has_more",
                  "equals": true
                },
                {
                  "path": "upcoming.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "undated_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "undated.has_more",
                  "equals": true
                },
                {
                  "path": "undated.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "today_raw",
          "value": {
            "each": "today.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "due": {
                "path": "properties[\"Due date\"].date.start"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "today_titled",
          "value": {
            "each": "today_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "today_rows",
          "value": {
            "each": "today_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "overdue_raw",
          "value": {
            "each": "overdue.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "due": {
                "path": "properties[\"Due date\"].date.start"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "overdue_titled",
          "value": {
            "each": "overdue_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "overdue_rows",
          "value": {
            "each": "overdue_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "upcoming_raw",
          "value": {
            "each": "upcoming.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "due": {
                "path": "properties[\"Due date\"].date.start"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "upcoming_titled",
          "value": {
            "each": "upcoming_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "upcoming_rows",
          "value": {
            "each": "upcoming_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "undated_raw",
          "value": {
            "each": "undated.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "due": {
                "path": "properties[\"Due date\"].date.start"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "undated_titled",
          "value": {
            "each": "undated_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "undated_rows",
          "value": {
            "each": "undated_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "due": "due",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "done_raw",
          "value": {
            "each": "done.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              }
            }
          }
        },
        {
          "name": "done_titled",
          "value": {
            "each": "done_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "done_rows",
          "value": {
            "each": "done_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "lists",
      "type": "tabs",
      "same_height": true,
      "tabs": [
        {
          "label": "Due",
          "cards": [
            {
              "id": "due",
              "type": "checklist",
              "items": [],
              "max_items": 7,
              "itemAction": {
                "label": "Mark done",
                "icon": "checkmark",
                "method": "PATCH",
                "path": "/v1/pages/{id}",
                "body": {
                  "properties": {
                    "Status": {
                      "status": {
                        "name": "Done"
                      }
                    }
                  }
                },
                "error": "message"
              },
              "source": {
                "ref": "tasks",
                "empty": {
                  "text": "Nothing due or overdue.",
                  "when": {
                    "value": {
                      "add": [
                        {
                          "count": "today_rows",
                          "default": 0
                        },
                        {
                          "count": "overdue_rows",
                          "default": 0
                        }
                      ]
                    },
                    "equals": 0
                  }
                },
                "map": {
                  "items": {
                    "each": [
                      "today_rows",
                      "overdue_rows"
                    ],
                    "limit": 60,
                    "fields": {
                      "text": "title",
                      "done": {
                        "path": "checked",
                        "default": false
                      },
                      "detail": {
                        "if": {
                          "path": "due",
                          "exists": true
                        },
                        "then": {
                          "if": {
                            "path": "due",
                            "contains": "T"
                          },
                          "then": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {due|clock} · {status}"
                            },
                            "else": {
                              "template": "{due|day} · {due|clock}"
                            }
                          },
                          "else": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {status}"
                            },
                            "else": {
                              "template": "{due|day}"
                            }
                          }
                        },
                        "else": {
                          "if": {
                            "all": [
                              {
                                "path": "status",
                                "exists": true
                              },
                              {
                                "path": "status",
                                "not": ""
                              }
                            ]
                          },
                          "then": {
                            "template": "{status}"
                          },
                          "else": {
                            "template": "No date"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        {
          "label": "Upcoming",
          "cards": [
            {
              "id": "upcoming",
              "type": "checklist",
              "items": [],
              "max_items": 7,
              "itemAction": {
                "label": "Mark done",
                "icon": "checkmark",
                "method": "PATCH",
                "path": "/v1/pages/{id}",
                "body": {
                  "properties": {
                    "Status": {
                      "status": {
                        "name": "Done"
                      }
                    }
                  }
                },
                "error": "message"
              },
              "source": {
                "ref": "tasks",
                "empty": {
                  "text": "Nothing else in the next 7 days.",
                  "when": {
                    "value": {
                      "add": [
                        {
                          "count": "upcoming_rows",
                          "default": 0
                        },
                        0
                      ]
                    },
                    "equals": 0
                  }
                },
                "map": {
                  "items": {
                    "each": "upcoming_rows",
                    "limit": 60,
                    "fields": {
                      "text": "title",
                      "done": {
                        "path": "checked",
                        "default": false
                      },
                      "detail": {
                        "if": {
                          "path": "due",
                          "exists": true
                        },
                        "then": {
                          "if": {
                            "path": "due",
                            "contains": "T"
                          },
                          "then": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {due|clock} · {status}"
                            },
                            "else": {
                              "template": "{due|day} · {due|clock}"
                            }
                          },
                          "else": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {status}"
                            },
                            "else": {
                              "template": "{due|day}"
                            }
                          }
                        },
                        "else": {
                          "if": {
                            "all": [
                              {
                                "path": "status",
                                "exists": true
                              },
                              {
                                "path": "status",
                                "not": ""
                              }
                            ]
                          },
                          "then": {
                            "template": "{status}"
                          },
                          "else": {
                            "template": "No date"
                          }
                        }
                      },
                      "section": {
                        "template": "{due|day}"
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        {
          "label": "No date",
          "cards": [
            {
              "id": "undated",
              "type": "checklist",
              "items": [],
              "max_items": 7,
              "itemAction": {
                "label": "Mark done",
                "icon": "checkmark",
                "method": "PATCH",
                "path": "/v1/pages/{id}",
                "body": {
                  "properties": {
                    "Status": {
                      "status": {
                        "name": "Done"
                      }
                    }
                  }
                },
                "error": "message"
              },
              "source": {
                "ref": "tasks",
                "empty": {
                  "text": "Every open task has a date.",
                  "when": {
                    "value": {
                      "add": [
                        {
                          "count": "undated_rows",
                          "default": 0
                        },
                        0
                      ]
                    },
                    "equals": 0
                  }
                },
                "map": {
                  "items": {
                    "each": "undated_rows",
                    "limit": 60,
                    "fields": {
                      "text": "title",
                      "done": {
                        "path": "checked",
                        "default": false
                      },
                      "detail": {
                        "if": {
                          "path": "due",
                          "exists": true
                        },
                        "then": {
                          "if": {
                            "path": "due",
                            "contains": "T"
                          },
                          "then": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {due|clock} · {status}"
                            },
                            "else": {
                              "template": "{due|day} · {due|clock}"
                            }
                          },
                          "else": {
                            "if": {
                              "all": [
                                {
                                  "path": "status",
                                  "exists": true
                                },
                                {
                                  "path": "status",
                                  "not": ""
                                }
                              ]
                            },
                            "then": {
                              "template": "{due|day} · {status}"
                            },
                            "else": {
                              "template": "{due|day}"
                            }
                          }
                        },
                        "else": {
                          "if": {
                            "all": [
                              {
                                "path": "status",
                                "exists": true
                              },
                              {
                                "path": "status",
                                "not": ""
                              }
                            ]
                          },
                          "then": {
                            "template": "{status}"
                          },
                          "else": {
                            "template": "No date"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "id": "cut",
      "type": "text",
      "tone": "info",
      "body": "Some tasks aren't shown: a tab has more than the page reads. Open the database in Notion for the rest.",
      "source": {
        "ref": "tasks",
        "when": {
          "any": [
            {
              "path": "today_cut",
              "equals": "yes"
            },
            {
              "path": "overdue_cut",
              "equals": "yes"
            },
            {
              "path": "upcoming_cut",
              "equals": "yes"
            },
            {
              "path": "undated_cut",
              "equals": "yes"
            }
          ]
        }
      }
    },
    {
      "id": "completed",
      "type": "heading",
      "text": "Completed",
      "collapsed": true,
      "cards": [
        "done"
      ]
    },
    {
      "id": "done",
      "type": "list",
      "label": "Edited last",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "tasks",
        "empty": {
          "text": "Nothing marked done yet.",
          "when": {
            "value": {
              "add": [
                {
                  "count": "done_rows",
                  "default": 0
                },
                0
              ]
            },
            "equals": 0
          }
        },
        "map": {
          "items": {
            "each": "done_rows",
            "fields": {
              "key": "id",
              "icon": {
                "template": "checkmark.circle"
              },
              "text": "title",
              "detail": {
                "template": "{edited|ago}"
              },
              "url": "url"
            }
          }
        }
      }
    }
  ]
}
