diff --git a/app/src/app/add.tsx b/app/src/app/add.tsx index f4bc907..73506e0 100644 --- a/app/src/app/add.tsx +++ b/app/src/app/add.tsx @@ -2,7 +2,7 @@ import { useRouter } from "expo-router"; import { useState } from "react"; import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"; import PriorityChips from "../components/PriorityChips"; -import { Button, Chips, Field } from "../components/ui"; +import { Chips, Field } from "../components/ui"; import { haptic } from "../lib/haptics"; import { activeProjects, createTask } from "../lib/store"; import { C } from "../lib/theme"; @@ -10,7 +10,6 @@ import { useStore } from "../lib/useStore"; import type { Task, TaskStatus } from "../lib/types"; const BOXES: { key: TaskStatus; label: string }[] = [ - { key: "inbox", label: "Inbox" }, { key: "next", label: "Next up" }, { key: "waiting", label: "Waiting" }, { key: "someday", label: "Someday" }, @@ -29,25 +28,29 @@ export default function AddTask() { const store = useStore(); const [title, setTitle] = useState(""); const [notes, setNotes] = useState(""); - const [priority, setPriority] = useState(4); + const [priority, setPriority] = useState(null); const [estimate, setEstimate] = useState(null); const [due, setDue] = useState(""); - const [box, setBox] = useState("inbox"); + const [box, setBox] = useState("next"); const [projectId, setProjectId] = useState(null); const projects = activeProjects(store).filter((p) => p.status === "active"); const projectOptions = ["none", ...projects.map((p) => p.id)]; const projectLabels = Object.fromEntries([["none", "None"], ...projects.map((p) => [p.id, p.name])]); + // Every task must be born fully scoped: title + priority + due date. + const dueValid = /^\d{4}-\d{2}-\d{2}$/.test(due.trim()); + const ready = title.trim().length > 0 && priority !== null && dueValid; + const save = () => { - if (!title.trim()) return; + if (!ready || priority === null) return; createTask({ title: title.trim(), notes, status: box, priority, estimate_min: estimate, - due_date: due.trim() || null, + due_date: due.trim(), project_id: projectId, }); haptic.success(); @@ -66,6 +69,28 @@ export default function AddTask() { style={{ minHeight: 64, textAlignVertical: "top" }} /> + + Due date + + {[ + { label: "Today", v: isoToday() }, + { label: "Tomorrow", v: isoToday(1) }, + { label: "Next week", v: isoToday(7) }, + ].map(({ label, v }) => ( + { + haptic.select(); + setDue(due === v ? "" : v); + }} + > + {label} + + ))} + + + Estimated time @@ -88,26 +113,6 @@ export default function AddTask() { })} - - - {[ - { label: "Due today", v: isoToday() }, - { label: "Tomorrow", v: isoToday(1) }, - ].map(({ label, v }) => ( - { - haptic.select(); - setDue(due === v ? "" : v); - }} - > - {label} - - ))} - - - b.key)} @@ -125,7 +130,11 @@ export default function AddTask() { value={projectId ?? "none"} onChange={(v) => setProjectId(v === "none" ? null : v)} /> -