Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ccd417f2a | |||
| 64967c19a0 | |||
| 8091c7d94d | |||
| e7c092f35d | |||
| d6bd8500e3 |
26
app/package-lock.json
generated
26
app/package-lock.json
generated
@@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/ui": "~57.0.9",
|
"@expo/ui": "~57.0.9",
|
||||||
"@react-native-async-storage/async-storage": "2.2.0",
|
"@react-native-async-storage/async-storage": "2.2.0",
|
||||||
|
"@react-native-community/netinfo": "12.0.1",
|
||||||
"expo": "~57.0.11",
|
"expo": "~57.0.11",
|
||||||
"expo-constants": "~57.0.9",
|
"expo-constants": "~57.0.9",
|
||||||
"expo-crypto": "~57.0.1",
|
"expo-crypto": "~57.0.1",
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
"react": "19.2.3",
|
"react": "19.2.3",
|
||||||
"react-dom": "19.2.3",
|
"react-dom": "19.2.3",
|
||||||
"react-native": "0.86.2",
|
"react-native": "0.86.2",
|
||||||
|
"react-native-draggable-flatlist": "^4.0.3",
|
||||||
"react-native-gesture-handler": "~2.32.0",
|
"react-native-gesture-handler": "~2.32.0",
|
||||||
"react-native-reanimated": "4.5.1",
|
"react-native-reanimated": "4.5.1",
|
||||||
"react-native-safe-area-context": "~5.7.0",
|
"react-native-safe-area-context": "~5.7.0",
|
||||||
@@ -2193,6 +2195,16 @@
|
|||||||
"react-native": "^0.0.0-0 || >=0.65 <1.0"
|
"react-native": "^0.0.0-0 || >=0.65 <1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@react-native-community/netinfo": {
|
||||||
|
"version": "12.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-12.0.1.tgz",
|
||||||
|
"integrity": "sha512-P/3caXIvfYSJG8AWJVefukg+ZGRPs+M4Lp3pNJtgcTYoJxCjWrKQGNnCkj/Cz//zWa/avGed0i/wzm0T8vV2IQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "*",
|
||||||
|
"react-native": ">=0.59"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@react-native-masked-view/masked-view": {
|
"node_modules/@react-native-masked-view/masked-view": {
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@react-native-masked-view/masked-view/-/masked-view-0.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/@react-native-masked-view/masked-view/-/masked-view-0.3.2.tgz",
|
||||||
@@ -6444,6 +6456,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/react-native-draggable-flatlist": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-native-draggable-flatlist/-/react-native-draggable-flatlist-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-2F4x5BFieWdGq9SetD2nSAR7s7oQCSgNllYgERRXXtNfSOuAGAVbDb/3H3lP0y5f7rEyNwabKorZAD/SyyNbDw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/preset-typescript": "^7.17.12"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react-native": ">=0.64.0",
|
||||||
|
"react-native-gesture-handler": ">=2.0.0",
|
||||||
|
"react-native-reanimated": ">=2.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/react-native-drawer-layout": {
|
"node_modules/react-native-drawer-layout": {
|
||||||
"version": "4.2.10",
|
"version": "4.2.10",
|
||||||
"resolved": "https://registry.npmjs.org/react-native-drawer-layout/-/react-native-drawer-layout-4.2.10.tgz",
|
"resolved": "https://registry.npmjs.org/react-native-drawer-layout/-/react-native-drawer-layout-4.2.10.tgz",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/ui": "~57.0.9",
|
"@expo/ui": "~57.0.9",
|
||||||
"@react-native-async-storage/async-storage": "2.2.0",
|
"@react-native-async-storage/async-storage": "2.2.0",
|
||||||
|
"@react-native-community/netinfo": "12.0.1",
|
||||||
"expo": "~57.0.11",
|
"expo": "~57.0.11",
|
||||||
"expo-constants": "~57.0.9",
|
"expo-constants": "~57.0.9",
|
||||||
"expo-crypto": "~57.0.1",
|
"expo-crypto": "~57.0.1",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"react": "19.2.3",
|
"react": "19.2.3",
|
||||||
"react-dom": "19.2.3",
|
"react-dom": "19.2.3",
|
||||||
"react-native": "0.86.2",
|
"react-native": "0.86.2",
|
||||||
|
"react-native-draggable-flatlist": "^4.0.3",
|
||||||
"react-native-gesture-handler": "~2.32.0",
|
"react-native-gesture-handler": "~2.32.0",
|
||||||
"react-native-reanimated": "4.5.1",
|
"react-native-reanimated": "4.5.1",
|
||||||
"react-native-safe-area-context": "~5.7.0",
|
"react-native-safe-area-context": "~5.7.0",
|
||||||
|
|||||||
@@ -1,19 +1,32 @@
|
|||||||
|
import NetInfo from "@react-native-community/netinfo";
|
||||||
import { Link, Stack } from "expo-router";
|
import { Link, Stack } from "expo-router";
|
||||||
import { StatusBar } from "expo-status-bar";
|
import { StatusBar } from "expo-status-bar";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { AppState } from "react-native";
|
import { AppState } from "react-native";
|
||||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
||||||
import { hydrate, sync } from "../lib/store";
|
import { getState, hydrate, sync } from "../lib/store";
|
||||||
import { C } from "../lib/theme";
|
import { C } from "../lib/theme";
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void hydrate();
|
void hydrate();
|
||||||
// Re-sync whenever the app returns to the foreground.
|
// Re-sync whenever the app returns to the foreground.
|
||||||
const sub = AppState.addEventListener("change", (s) => {
|
const appState = AppState.addEventListener("change", (s) => {
|
||||||
if (s === "active") void sync();
|
if (s === "active") void sync();
|
||||||
});
|
});
|
||||||
return () => sub.remove();
|
// Drain the queue the moment connectivity returns (wifi/cellular).
|
||||||
|
const net = NetInfo.addEventListener((s) => {
|
||||||
|
if (s.isConnected) void sync();
|
||||||
|
});
|
||||||
|
// Slow heartbeat as a belt-and-braces retry while changes are queued.
|
||||||
|
const heartbeat = setInterval(() => {
|
||||||
|
if (getState().pending > 0 || getState().offline) void sync();
|
||||||
|
}, 45_000);
|
||||||
|
return () => {
|
||||||
|
appState.remove();
|
||||||
|
net();
|
||||||
|
clearInterval(heartbeat);
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
||||||
|
import DateField from "../components/DateField";
|
||||||
import PriorityChips from "../components/PriorityChips";
|
import PriorityChips from "../components/PriorityChips";
|
||||||
import { Button, Chips, Field } from "../components/ui";
|
import { Chips, Field } from "../components/ui";
|
||||||
import { haptic } from "../lib/haptics";
|
import { haptic } from "../lib/haptics";
|
||||||
import { activeProjects, createTask } from "../lib/store";
|
import { activeProjects, createTask } from "../lib/store";
|
||||||
import { C } from "../lib/theme";
|
import { C } from "../lib/theme";
|
||||||
@@ -10,7 +11,6 @@ import { useStore } from "../lib/useStore";
|
|||||||
import type { Task, TaskStatus } from "../lib/types";
|
import type { Task, TaskStatus } from "../lib/types";
|
||||||
|
|
||||||
const BOXES: { key: TaskStatus; label: string }[] = [
|
const BOXES: { key: TaskStatus; label: string }[] = [
|
||||||
{ key: "inbox", label: "Inbox" },
|
|
||||||
{ key: "next", label: "Next up" },
|
{ key: "next", label: "Next up" },
|
||||||
{ key: "waiting", label: "Waiting" },
|
{ key: "waiting", label: "Waiting" },
|
||||||
{ key: "someday", label: "Someday" },
|
{ key: "someday", label: "Someday" },
|
||||||
@@ -18,36 +18,34 @@ const BOXES: { key: TaskStatus; label: string }[] = [
|
|||||||
|
|
||||||
const ESTIMATES = [15, 30, 45, 60, 90, 120];
|
const ESTIMATES = [15, 30, 45, 60, 90, 120];
|
||||||
|
|
||||||
function isoToday(offset = 0): string {
|
|
||||||
const d = new Date();
|
|
||||||
d.setDate(d.getDate() + offset);
|
|
||||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function AddTask() {
|
export default function AddTask() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [notes, setNotes] = useState("");
|
const [notes, setNotes] = useState("");
|
||||||
const [priority, setPriority] = useState<Task["priority"]>(4);
|
const [priority, setPriority] = useState<Task["priority"] | null>(null);
|
||||||
const [estimate, setEstimate] = useState<number | null>(null);
|
const [estimate, setEstimate] = useState<number | null>(null);
|
||||||
const [due, setDue] = useState("");
|
const [due, setDue] = useState("");
|
||||||
const [box, setBox] = useState<TaskStatus>("inbox");
|
const [box, setBox] = useState<TaskStatus>("next");
|
||||||
const [projectId, setProjectId] = useState<string | null>(null);
|
const [projectId, setProjectId] = useState<string | null>(null);
|
||||||
|
|
||||||
const projects = activeProjects(store).filter((p) => p.status === "active");
|
const projects = activeProjects(store).filter((p) => p.status === "active");
|
||||||
const projectOptions = ["none", ...projects.map((p) => p.id)];
|
const projectOptions = ["none", ...projects.map((p) => p.id)];
|
||||||
const projectLabels = Object.fromEntries([["none", "None"], ...projects.map((p) => [p.id, p.name])]);
|
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 = () => {
|
const save = () => {
|
||||||
if (!title.trim()) return;
|
if (!ready || priority === null) return;
|
||||||
createTask({
|
createTask({
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
notes,
|
notes,
|
||||||
status: box,
|
status: box,
|
||||||
priority,
|
priority,
|
||||||
estimate_min: estimate,
|
estimate_min: estimate,
|
||||||
due_date: due.trim() || null,
|
due_date: due.trim(),
|
||||||
project_id: projectId,
|
project_id: projectId,
|
||||||
});
|
});
|
||||||
haptic.success();
|
haptic.success();
|
||||||
@@ -66,6 +64,7 @@ export default function AddTask() {
|
|||||||
style={{ minHeight: 64, textAlignVertical: "top" }}
|
style={{ minHeight: 64, textAlignVertical: "top" }}
|
||||||
/>
|
/>
|
||||||
<PriorityChips value={priority} onChange={setPriority} />
|
<PriorityChips value={priority} onChange={setPriority} />
|
||||||
|
<DateField label="Due date" value={due || null} onChange={(v) => setDue(v ?? "")} />
|
||||||
<View style={{ marginBottom: 14 }}>
|
<View style={{ marginBottom: 14 }}>
|
||||||
<Text style={s.label}>Estimated time</Text>
|
<Text style={s.label}>Estimated time</Text>
|
||||||
<View style={s.rowWrap}>
|
<View style={s.rowWrap}>
|
||||||
@@ -88,26 +87,6 @@ export default function AddTask() {
|
|||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={{ marginBottom: 2 }}>
|
|
||||||
<View style={s.rowWrap}>
|
|
||||||
{[
|
|
||||||
{ label: "Due today", v: isoToday() },
|
|
||||||
{ label: "Tomorrow", v: isoToday(1) },
|
|
||||||
].map(({ label, v }) => (
|
|
||||||
<Pressable
|
|
||||||
key={label}
|
|
||||||
style={[s.chip, due === v && s.chipActive]}
|
|
||||||
onPress={() => {
|
|
||||||
haptic.select();
|
|
||||||
setDue(due === v ? "" : v);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Text style={[s.chipText, due === v && { color: C.text }]}>{label}</Text>
|
|
||||||
</Pressable>
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
<Field label="Due date" value={due} onChangeText={setDue} placeholder="YYYY-MM-DD" autoCapitalize="none" />
|
|
||||||
<Chips
|
<Chips
|
||||||
label="Box"
|
label="Box"
|
||||||
options={BOXES.map((b) => b.key)}
|
options={BOXES.map((b) => b.key)}
|
||||||
@@ -125,7 +104,11 @@ export default function AddTask() {
|
|||||||
value={projectId ?? "none"}
|
value={projectId ?? "none"}
|
||||||
onChange={(v) => setProjectId(v === "none" ? null : v)}
|
onChange={(v) => setProjectId(v === "none" ? null : v)}
|
||||||
/>
|
/>
|
||||||
<Button title="Add task" onPress={save} />
|
<Pressable style={[s.save, !ready && s.saveDisabled]} onPress={save} disabled={!ready}>
|
||||||
|
<Text style={[s.saveText, !ready && { color: C.muted }]}>
|
||||||
|
{ready ? "Add task" : "Needs a title, priority & due date"}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -143,4 +126,14 @@ const s = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
chipActive: { backgroundColor: C.surface2, borderColor: C.accent },
|
chipActive: { backgroundColor: C.surface2, borderColor: C.accent },
|
||||||
chipText: { color: C.muted, fontSize: 14 },
|
chipText: { color: C.muted, fontSize: 14 },
|
||||||
|
save: {
|
||||||
|
backgroundColor: C.accent,
|
||||||
|
borderRadius: 10,
|
||||||
|
padding: 14,
|
||||||
|
alignItems: "center",
|
||||||
|
marginTop: 8,
|
||||||
|
marginBottom: 24,
|
||||||
|
},
|
||||||
|
saveDisabled: { backgroundColor: C.surface },
|
||||||
|
saveText: { color: C.text, fontSize: 16, fontWeight: "600" },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,226 +1,65 @@
|
|||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { useRef, useState } from "react";
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
||||||
import { Pressable, StyleSheet, Text, TextInput, View } from "react-native";
|
import TaskRow from "../components/TaskRow";
|
||||||
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
||||||
import Animated, {
|
|
||||||
runOnJS,
|
|
||||||
useAnimatedStyle,
|
|
||||||
useSharedValue,
|
|
||||||
withSpring,
|
|
||||||
withTiming,
|
|
||||||
} from "react-native-reanimated";
|
|
||||||
import { haptic } from "../lib/haptics";
|
import { haptic } from "../lib/haptics";
|
||||||
import { PRIORITY_COLOR } from "../lib/priority";
|
import { tasksByStatus, todayTasks } from "../lib/store";
|
||||||
import { parseQuickAdd } from "../lib/quickadd";
|
|
||||||
import { activeProjects, createTask, tasksByStatus, todayTasks, updateTask } from "../lib/store";
|
|
||||||
import { C } from "../lib/theme";
|
import { C } from "../lib/theme";
|
||||||
import { useStore } from "../lib/useStore";
|
import { useStore } from "../lib/useStore";
|
||||||
import type { Task, TaskStatus } from "../lib/types";
|
|
||||||
|
|
||||||
const Q = {
|
const MENU = [
|
||||||
next: { title: "Next up", color: "#3DBF77", bg: "#15301F", border: "#1E4D33" },
|
{ icon: "📅", label: "Today", href: "/today" },
|
||||||
waiting: { title: "Waiting for", color: "#E0A93E", bg: "#33270F", border: "#544019" },
|
{ icon: "▶️", label: "Next", href: "/list/next" },
|
||||||
someday: { title: "Someday", color: "#9D8FE8", bg: "#221E38", border: "#38315C" },
|
{ icon: "⏳", label: "Waiting", href: "/list/waiting" },
|
||||||
projects: { title: "Projects", color: "#5B9DE8", bg: "#152538", border: "#1F3D5C" },
|
{ icon: "💭", label: "Someday", href: "/list/someday" },
|
||||||
};
|
{ icon: "📁", label: "Projects", href: "/projects" },
|
||||||
|
] as const;
|
||||||
type DropZone = Extract<TaskStatus, "inbox" | "next" | "waiting" | "someday">;
|
|
||||||
type Rect = { x: number; y: number; w: number; h: number };
|
|
||||||
type ZoneRects = Partial<Record<DropZone, Rect>>;
|
|
||||||
|
|
||||||
const SPRING = { damping: 18, stiffness: 260, mass: 0.6 };
|
|
||||||
|
|
||||||
/** Long-press-drag wrapper: spring transforms, haptics, window-coord drop. */
|
|
||||||
function Draggable({
|
|
||||||
task,
|
|
||||||
findZone,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
task: Task;
|
|
||||||
findZone: (x: number, y: number) => DropZone | null;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) {
|
|
||||||
const tx = useSharedValue(0);
|
|
||||||
const ty = useSharedValue(0);
|
|
||||||
const active = useSharedValue(false);
|
|
||||||
|
|
||||||
const drop = (x: number, y: number) => {
|
|
||||||
const zone = findZone(x, y);
|
|
||||||
if (zone && zone !== task.status) {
|
|
||||||
haptic.success();
|
|
||||||
updateTask(task.id, { status: zone });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const pan = Gesture.Pan()
|
|
||||||
.activateAfterLongPress(180)
|
|
||||||
.onStart(() => {
|
|
||||||
active.value = true;
|
|
||||||
runOnJS(haptic.pickup)();
|
|
||||||
})
|
|
||||||
.onUpdate((e) => {
|
|
||||||
tx.value = e.translationX;
|
|
||||||
ty.value = e.translationY;
|
|
||||||
})
|
|
||||||
.onEnd((e) => {
|
|
||||||
runOnJS(drop)(e.absoluteX, e.absoluteY);
|
|
||||||
})
|
|
||||||
.onFinalize(() => {
|
|
||||||
active.value = false;
|
|
||||||
tx.value = withSpring(0, SPRING);
|
|
||||||
ty.value = withSpring(0, SPRING);
|
|
||||||
});
|
|
||||||
|
|
||||||
const style = useAnimatedStyle(() => ({
|
|
||||||
transform: [
|
|
||||||
{ translateX: tx.value },
|
|
||||||
{ translateY: ty.value },
|
|
||||||
{ scale: withTiming(active.value ? 1.06 : 1, { duration: 120 }) },
|
|
||||||
],
|
|
||||||
zIndex: active.value ? 100 : 0,
|
|
||||||
elevation: active.value ? 8 : 0,
|
|
||||||
opacity: withTiming(active.value ? 0.92 : 1, { duration: 120 }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<GestureDetector gesture={pan}>
|
|
||||||
<Animated.View style={style}>{children}</Animated.View>
|
|
||||||
</GestureDetector>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function DragRow({ task, findZone }: { task: Task; findZone: (x: number, y: number) => DropZone | null }) {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Draggable task={task} findZone={findZone}>
|
|
||||||
<Pressable style={s.dragRow} onPress={() => router.push(`/task/${task.id}`)}>
|
|
||||||
<View style={[s.priorityDot, { backgroundColor: PRIORITY_COLOR[task.priority] }]} />
|
|
||||||
<Text style={s.dragRowText} numberOfLines={1}>
|
|
||||||
{task.title}
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
</Draggable>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const [draft, setDraft] = useState("");
|
|
||||||
const zones = useRef<ZoneRects>({});
|
|
||||||
const zoneRefs = useRef<Partial<Record<DropZone, View | null>>>({});
|
|
||||||
|
|
||||||
const measureZone = (zone: DropZone) => () => {
|
|
||||||
zoneRefs.current[zone]?.measureInWindow((x, y, w, h) => {
|
|
||||||
zones.current[zone] = { x, y, w, h };
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const findZone = (x: number, y: number): DropZone | null => {
|
|
||||||
for (const [zone, r] of Object.entries(zones.current) as [DropZone, Rect][]) {
|
|
||||||
if (x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h) return zone;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const capture = () => {
|
|
||||||
if (!draft.trim()) return;
|
|
||||||
const parsed = parseQuickAdd(draft, store.projects);
|
|
||||||
if (!parsed.title) return;
|
|
||||||
setDraft("");
|
|
||||||
haptic.tap();
|
|
||||||
createTask({ ...parsed, status: "inbox" });
|
|
||||||
};
|
|
||||||
|
|
||||||
const inbox = tasksByStatus(store, "inbox");
|
|
||||||
const next = tasksByStatus(store, "next");
|
const next = tasksByStatus(store, "next");
|
||||||
const waiting = tasksByStatus(store, "waiting");
|
const { overdue } = todayTasks(store);
|
||||||
const someday = tasksByStatus(store, "someday");
|
|
||||||
const projects = activeProjects(store).filter((p) => p.status === "active");
|
|
||||||
const { overdue, today } = todayTasks(store);
|
|
||||||
|
|
||||||
const quadrant = (zone: Exclude<DropZone, "inbox">, tasks: Task[], onOpen: () => void) => {
|
|
||||||
const q = Q[zone];
|
|
||||||
return (
|
|
||||||
<View
|
|
||||||
ref={(r) => {
|
|
||||||
zoneRefs.current[zone] = r;
|
|
||||||
}}
|
|
||||||
onLayout={measureZone(zone)}
|
|
||||||
style={[s.quad, { backgroundColor: q.bg, borderColor: q.border }]}
|
|
||||||
>
|
|
||||||
<Pressable style={s.quadHead} onPress={onOpen}>
|
|
||||||
<Text style={[s.quadTitle, { color: q.color }]}>{q.title}</Text>
|
|
||||||
<Text style={[s.quadCount, { color: q.color }]}>{tasks.length}</Text>
|
|
||||||
</Pressable>
|
|
||||||
{tasks.slice(0, 3).map((t) => (
|
|
||||||
<DragRow key={t.id} task={t} findZone={findZone} />
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={s.screen}>
|
<View style={s.screen}>
|
||||||
<TextInput
|
<View style={{ flex: 1 }}>
|
||||||
style={s.capture}
|
<Text style={s.sectionTitle}>Next up</Text>
|
||||||
placeholder="Capture… (tomorrow p1 @home #project ~30m)"
|
{next.slice(0, 3).map((t) => (
|
||||||
placeholderTextColor={C.muted}
|
<TaskRow key={t.id} task={t} />
|
||||||
value={draft}
|
))}
|
||||||
onChangeText={setDraft}
|
{next.length === 0 && <Text style={s.empty}>Nothing next. Tap + to add.</Text>}
|
||||||
onSubmitEditing={capture}
|
{next.length > 3 && (
|
||||||
submitBehavior="submit"
|
<Pressable onPress={() => router.push("/list/next")}>
|
||||||
returnKeyType="done"
|
<Text style={s.viewAll}>all next actions ({next.length}) →</Text>
|
||||||
/>
|
|
||||||
<View style={s.pillRow}>
|
|
||||||
<View
|
|
||||||
ref={(r) => {
|
|
||||||
zoneRefs.current.inbox = r;
|
|
||||||
}}
|
|
||||||
onLayout={measureZone("inbox")}
|
|
||||||
style={s.pill}
|
|
||||||
>
|
|
||||||
<Pressable style={s.pillPress} onPress={() => router.push("/list/inbox")}>
|
|
||||||
<Text style={s.pillText}>📥 Inbox</Text>
|
|
||||||
<Text style={[s.pillText, { color: inbox.length ? C.text : C.muted }]}>{inbox.length}</Text>
|
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
)}
|
||||||
<View style={s.pill}>
|
{overdue.length > 0 && (
|
||||||
<Pressable style={s.pillPress} onPress={() => router.push("/today")}>
|
<Pressable onPress={() => router.push("/today")}>
|
||||||
<Text style={s.pillText}>📅 Today</Text>
|
<Text style={s.overdue}>{overdue.length} overdue →</Text>
|
||||||
<Text style={[s.pillText, { color: overdue.length ? C.danger : today.length ? C.text : C.muted }]}>
|
|
||||||
{overdue.length ? `${overdue.length}!` : today.length}
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
)}
|
||||||
|
{store.offline && (
|
||||||
|
<Text style={s.offline}>
|
||||||
|
offline{store.pending > 0 ? ` — ${store.pending} change${store.pending === 1 ? "" : "s"} queued` : ""}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{store.syncError && <Text style={s.error}>{store.syncError}</Text>}
|
||||||
</View>
|
</View>
|
||||||
{inbox.slice(0, 3).map((t) => (
|
<View style={s.menu}>
|
||||||
<DragRow key={t.id} task={t} findZone={findZone} />
|
{MENU.map((m) => (
|
||||||
))}
|
<Pressable key={m.label} style={s.menuItem} onPress={() => router.push(m.href)}>
|
||||||
{store.syncError && <Text style={s.error}>{store.syncError}</Text>}
|
<Text style={s.menuIcon}>{m.icon}</Text>
|
||||||
<View style={s.grid}>
|
<Text style={s.menuLabel}>{m.label}</Text>
|
||||||
<View style={s.gridRow}>
|
</Pressable>
|
||||||
{quadrant("next", next, () => router.push("/list/next"))}
|
))}
|
||||||
{quadrant("waiting", waiting, () => router.push("/list/waiting"))}
|
|
||||||
</View>
|
|
||||||
<View style={s.gridRow}>
|
|
||||||
{quadrant("someday", someday, () => router.push("/list/someday"))}
|
|
||||||
<View style={[s.quad, { backgroundColor: Q.projects.bg, borderColor: Q.projects.border }]}>
|
|
||||||
<Pressable style={{ flex: 1 }} onPress={() => router.push("/projects")}>
|
|
||||||
<View style={s.quadHead}>
|
|
||||||
<Text style={[s.quadTitle, { color: Q.projects.color }]}>{Q.projects.title}</Text>
|
|
||||||
<Text style={[s.quadCount, { color: Q.projects.color }]}>{projects.length}</Text>
|
|
||||||
</View>
|
|
||||||
{projects.slice(0, 3).map((p) => (
|
|
||||||
<Text key={p.id} style={s.quadItem} numberOfLines={1}>
|
|
||||||
{p.name}
|
|
||||||
</Text>
|
|
||||||
))}
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
<Pressable style={s.fab} onPress={() => { haptic.tap(); router.push("/add"); }}>
|
<Pressable
|
||||||
|
style={s.fab}
|
||||||
|
onPress={() => {
|
||||||
|
haptic.tap();
|
||||||
|
router.push("/add");
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Text style={s.fabText}>+</Text>
|
<Text style={s.fabText}>+</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
@@ -228,58 +67,36 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const s = StyleSheet.create({
|
const s = StyleSheet.create({
|
||||||
screen: { flex: 1, backgroundColor: C.bg, padding: 12 },
|
screen: { flex: 1, backgroundColor: C.bg },
|
||||||
capture: {
|
sectionTitle: {
|
||||||
padding: 14,
|
color: C.muted,
|
||||||
borderRadius: 12,
|
fontSize: 13,
|
||||||
backgroundColor: C.surface,
|
textTransform: "uppercase",
|
||||||
color: C.text,
|
letterSpacing: 1,
|
||||||
fontSize: 16,
|
paddingHorizontal: 16,
|
||||||
borderWidth: 1,
|
paddingTop: 18,
|
||||||
borderColor: C.border,
|
paddingBottom: 6,
|
||||||
},
|
},
|
||||||
pillRow: { flexDirection: "row", gap: 10, marginTop: 10 },
|
empty: { color: C.muted, textAlign: "center", marginTop: 48, fontSize: 15 },
|
||||||
pill: {
|
viewAll: { color: C.muted, fontSize: 14, padding: 16 },
|
||||||
flex: 1,
|
overdue: { color: C.danger, fontSize: 14, paddingHorizontal: 16, paddingBottom: 8 },
|
||||||
borderRadius: 12,
|
error: { color: C.danger, paddingHorizontal: 16, paddingTop: 8 },
|
||||||
backgroundColor: C.surface,
|
offline: { color: C.muted, fontSize: 13, paddingHorizontal: 16, paddingTop: 8 },
|
||||||
borderWidth: 1,
|
menu: {
|
||||||
borderColor: C.border,
|
|
||||||
},
|
|
||||||
pillPress: {
|
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
justifyContent: "space-between",
|
borderTopWidth: StyleSheet.hairlineWidth,
|
||||||
alignItems: "center",
|
borderTopColor: C.border,
|
||||||
paddingVertical: 12,
|
paddingTop: 10,
|
||||||
paddingHorizontal: 14,
|
paddingBottom: 18,
|
||||||
|
backgroundColor: C.bg,
|
||||||
},
|
},
|
||||||
pillText: { color: C.text, fontSize: 15, fontWeight: "600" },
|
menuItem: { flex: 1, alignItems: "center", gap: 3 },
|
||||||
dragRow: {
|
menuIcon: { fontSize: 20 },
|
||||||
flexDirection: "row",
|
menuLabel: { color: C.muted, fontSize: 11 },
|
||||||
alignItems: "center",
|
|
||||||
gap: 8,
|
|
||||||
marginTop: 6,
|
|
||||||
paddingVertical: 9,
|
|
||||||
paddingHorizontal: 12,
|
|
||||||
borderRadius: 10,
|
|
||||||
backgroundColor: C.surface2,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: C.border,
|
|
||||||
},
|
|
||||||
dragRowText: { color: C.text, fontSize: 14, flex: 1 },
|
|
||||||
priorityDot: { width: 8, height: 8, borderRadius: 4 },
|
|
||||||
grid: { flex: 1, marginTop: 10, gap: 10 },
|
|
||||||
gridRow: { flex: 1, flexDirection: "row", gap: 10 },
|
|
||||||
quad: { flex: 1, borderRadius: 16, borderWidth: 1, padding: 12, overflow: "visible" },
|
|
||||||
quadHead: { flexDirection: "row", justifyContent: "space-between", marginBottom: 4 },
|
|
||||||
quadTitle: { fontSize: 16, fontWeight: "700" },
|
|
||||||
quadCount: { fontSize: 16, fontWeight: "700" },
|
|
||||||
quadItem: { color: C.muted, fontSize: 13, marginBottom: 4 },
|
|
||||||
error: { color: C.danger, marginTop: 8 },
|
|
||||||
fab: {
|
fab: {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
right: 20,
|
right: 20,
|
||||||
bottom: 24,
|
bottom: 92,
|
||||||
width: 58,
|
width: 58,
|
||||||
height: 58,
|
height: 58,
|
||||||
borderRadius: 29,
|
borderRadius: 29,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import TaskListScreen from "../../components/TaskListScreen";
|
|||||||
import type { TaskStatus } from "../../lib/types";
|
import type { TaskStatus } from "../../lib/types";
|
||||||
|
|
||||||
const TITLES: Record<string, string> = {
|
const TITLES: Record<string, string> = {
|
||||||
inbox: "Inbox",
|
|
||||||
next: "Next up",
|
next: "Next up",
|
||||||
waiting: "Waiting for",
|
waiting: "Waiting for",
|
||||||
scheduled: "Scheduled",
|
scheduled: "Scheduled",
|
||||||
@@ -12,8 +11,7 @@ const TITLES: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const HINTS: Record<string, string> = {
|
const HINTS: Record<string, string> = {
|
||||||
inbox: "Inbox zero. Capture from the home screen.",
|
next: "Nothing next. Tap + on the home screen.",
|
||||||
next: "No next actions. Clarify your inbox.",
|
|
||||||
waiting: "Not waiting on anyone.",
|
waiting: "Not waiting on anyone.",
|
||||||
scheduled: "Nothing scheduled.",
|
scheduled: "Nothing scheduled.",
|
||||||
someday: "No someday/maybe items.",
|
someday: "No someday/maybe items.",
|
||||||
@@ -22,11 +20,11 @@ const HINTS: Record<string, string> = {
|
|||||||
|
|
||||||
export default function ListByStatus() {
|
export default function ListByStatus() {
|
||||||
const { status } = useLocalSearchParams<{ status: string }>();
|
const { status } = useLocalSearchParams<{ status: string }>();
|
||||||
const st = (status in TITLES ? status : "inbox") as TaskStatus;
|
const st = (status in TITLES ? status : "next") as TaskStatus;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={{ title: TITLES[st] }} />
|
<Stack.Screen options={{ title: TITLES[st] }} />
|
||||||
<TaskListScreen status={st} capture={st === "inbox" || st === "next"} emptyHint={HINTS[st]} />
|
<TaskListScreen status={st} emptyHint={HINTS[st]} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ScrollView, Text } from "react-native";
|
import { ScrollView, Text } from "react-native";
|
||||||
|
import DateField from "../../components/DateField";
|
||||||
import PriorityChips from "../../components/PriorityChips";
|
import PriorityChips from "../../components/PriorityChips";
|
||||||
import { Button, Chips, Field } from "../../components/ui";
|
import { Button, Chips, Field } from "../../components/ui";
|
||||||
import { activeProjects, trashTask, updateTask } from "../../lib/store";
|
import { activeProjects, trashTask, updateTask } from "../../lib/store";
|
||||||
@@ -8,7 +9,7 @@ import { C } from "../../lib/theme";
|
|||||||
import { useStore } from "../../lib/useStore";
|
import { useStore } from "../../lib/useStore";
|
||||||
import type { Task, TaskStatus } from "../../lib/types";
|
import type { Task, TaskStatus } from "../../lib/types";
|
||||||
|
|
||||||
const STATUSES: TaskStatus[] = ["inbox", "next", "waiting", "scheduled", "someday", "done"];
|
const STATUSES: TaskStatus[] = ["next", "waiting", "someday", "done"];
|
||||||
|
|
||||||
export default function TaskDetail() {
|
export default function TaskDetail() {
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
@@ -76,20 +77,8 @@ export default function TaskDetail() {
|
|||||||
placeholder="Who or what?"
|
placeholder="Who or what?"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Field
|
<DateField label="Due date" value={draft.due_date} onChange={(v) => set({ due_date: v })} clearable />
|
||||||
label="Due date"
|
<DateField label="Defer until" value={draft.defer_date} onChange={(v) => set({ defer_date: v })} clearable />
|
||||||
value={draft.due_date ?? ""}
|
|
||||||
onChangeText={(v) => set({ due_date: v || null })}
|
|
||||||
placeholder="YYYY-MM-DD"
|
|
||||||
autoCapitalize="none"
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
label="Defer until"
|
|
||||||
value={draft.defer_date ?? ""}
|
|
||||||
onChangeText={(v) => set({ defer_date: v || null })}
|
|
||||||
placeholder="YYYY-MM-DD"
|
|
||||||
autoCapitalize="none"
|
|
||||||
/>
|
|
||||||
<Field
|
<Field
|
||||||
label="Notes"
|
label="Notes"
|
||||||
value={draft.notes}
|
value={draft.notes}
|
||||||
|
|||||||
228
app/src/components/DateField.tsx
Normal file
228
app/src/components/DateField.tsx
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
// Interactive date field: quick chips (Today / Tomorrow / Next week) plus an
|
||||||
|
// expandable month calendar. Pure RN views — identical on Android, iOS, web.
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
||||||
|
import { haptic } from "../lib/haptics";
|
||||||
|
import { C } from "../lib/theme";
|
||||||
|
|
||||||
|
const DAY_MS = 86_400_000;
|
||||||
|
const WEEKDAYS = ["M", "T", "W", "T", "F", "S", "S"];
|
||||||
|
const MONTHS = [
|
||||||
|
"January", "February", "March", "April", "May", "June",
|
||||||
|
"July", "August", "September", "October", "November", "December",
|
||||||
|
];
|
||||||
|
|
||||||
|
function iso(d: Date): string {
|
||||||
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromIso(s: string): Date {
|
||||||
|
const [y, m, d] = s.split("-").map(Number);
|
||||||
|
return new Date(y, m - 1, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pretty(s: string): string {
|
||||||
|
const d = fromIso(s);
|
||||||
|
const today = new Date();
|
||||||
|
const diff = Math.round((d.getTime() - new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime()) / DAY_MS);
|
||||||
|
if (diff === 0) return "Today";
|
||||||
|
if (diff === 1) return "Tomorrow";
|
||||||
|
if (diff === -1) return "Yesterday";
|
||||||
|
const wd = d.toLocaleDateString("en-AU", { weekday: "short" });
|
||||||
|
return `${wd} ${d.getDate()} ${MONTHS[d.getMonth()].slice(0, 3)}${d.getFullYear() !== today.getFullYear() ? ` ${d.getFullYear()}` : ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Calendar({ value, onPick }: { value: string | null; onPick: (v: string) => void }) {
|
||||||
|
const initial = value ? fromIso(value) : new Date();
|
||||||
|
const [year, setYear] = useState(initial.getFullYear());
|
||||||
|
const [month, setMonth] = useState(initial.getMonth());
|
||||||
|
const todayIso = iso(new Date());
|
||||||
|
|
||||||
|
const weeks = useMemo(() => {
|
||||||
|
const first = new Date(year, month, 1);
|
||||||
|
const start = new Date(first);
|
||||||
|
start.setDate(1 - ((first.getDay() + 6) % 7)); // back to Monday
|
||||||
|
return Array.from({ length: 6 }, (_, w) =>
|
||||||
|
Array.from({ length: 7 }, (_, i) => {
|
||||||
|
const d = new Date(start);
|
||||||
|
d.setDate(start.getDate() + w * 7 + i);
|
||||||
|
return d;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}, [year, month]);
|
||||||
|
|
||||||
|
const shift = (delta: number) => {
|
||||||
|
haptic.select();
|
||||||
|
const d = new Date(year, month + delta, 1);
|
||||||
|
setYear(d.getFullYear());
|
||||||
|
setMonth(d.getMonth());
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={s.calendar}>
|
||||||
|
<View style={s.calHead}>
|
||||||
|
<Pressable onPress={() => shift(-1)} hitSlop={10} style={s.arrow}>
|
||||||
|
<Text style={s.arrowText}>‹</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Text style={s.calTitle}>
|
||||||
|
{MONTHS[month]} {year}
|
||||||
|
</Text>
|
||||||
|
<Pressable onPress={() => shift(1)} hitSlop={10} style={s.arrow}>
|
||||||
|
<Text style={s.arrowText}>›</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
<View style={s.week}>
|
||||||
|
{WEEKDAYS.map((w, i) => (
|
||||||
|
<Text key={i} style={s.weekday}>
|
||||||
|
{w}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
{weeks.map((week, wi) => (
|
||||||
|
<View key={wi} style={s.week}>
|
||||||
|
{week.map((d) => {
|
||||||
|
const dIso = iso(d);
|
||||||
|
const inMonth = d.getMonth() === month;
|
||||||
|
const selected = dIso === value;
|
||||||
|
const isToday = dIso === todayIso;
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={dIso}
|
||||||
|
style={[s.day, selected && s.daySelected, !selected && isToday && s.dayToday]}
|
||||||
|
onPress={() => {
|
||||||
|
haptic.select();
|
||||||
|
onPick(dIso);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
s.dayText,
|
||||||
|
!inMonth && { color: C.border },
|
||||||
|
selected && { color: "#FFFFFF", fontWeight: "700" },
|
||||||
|
!selected && isToday && { color: C.accent },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{d.getDate()}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DateField({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
clearable,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
value: string | null;
|
||||||
|
onChange: (v: string | null) => void;
|
||||||
|
clearable?: boolean;
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const today = new Date();
|
||||||
|
const quick = [
|
||||||
|
{ label: "Today", v: iso(today) },
|
||||||
|
{ label: "Tomorrow", v: iso(new Date(today.getTime() + DAY_MS)) },
|
||||||
|
{ label: "Next week", v: iso(new Date(today.getTime() + 7 * DAY_MS)) },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={{ marginBottom: 14 }}>
|
||||||
|
<View style={s.labelRow}>
|
||||||
|
<Text style={s.label}>{label}</Text>
|
||||||
|
{value != null && <Text style={s.chosen}>{pretty(value)}</Text>}
|
||||||
|
</View>
|
||||||
|
<View style={s.rowWrap}>
|
||||||
|
{quick.map((q) => (
|
||||||
|
<Pressable
|
||||||
|
key={q.label}
|
||||||
|
style={[s.chip, value === q.v && s.chipActive]}
|
||||||
|
onPress={() => {
|
||||||
|
haptic.select();
|
||||||
|
onChange(value === q.v && clearable ? null : q.v);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={[s.chipText, value === q.v && { color: C.text }]}>{q.label}</Text>
|
||||||
|
</Pressable>
|
||||||
|
))}
|
||||||
|
<Pressable
|
||||||
|
style={[s.chip, open && s.chipActive]}
|
||||||
|
onPress={() => {
|
||||||
|
haptic.select();
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={[s.chipText, open && { color: C.text }]}>📆 Pick…</Text>
|
||||||
|
</Pressable>
|
||||||
|
{clearable && value != null && (
|
||||||
|
<Pressable
|
||||||
|
style={s.chip}
|
||||||
|
onPress={() => {
|
||||||
|
haptic.tap();
|
||||||
|
onChange(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={s.chipText}>Clear</Text>
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{open && (
|
||||||
|
<Calendar
|
||||||
|
value={value}
|
||||||
|
onPick={(v) => {
|
||||||
|
onChange(v);
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const s = StyleSheet.create({
|
||||||
|
labelRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "baseline", marginBottom: 6 },
|
||||||
|
label: { color: C.muted, fontSize: 13, textTransform: "uppercase", letterSpacing: 0.5 },
|
||||||
|
chosen: { color: C.accent, fontSize: 14, fontWeight: "600" },
|
||||||
|
rowWrap: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
||||||
|
chip: {
|
||||||
|
paddingVertical: 8,
|
||||||
|
paddingHorizontal: 14,
|
||||||
|
borderRadius: 20,
|
||||||
|
backgroundColor: C.surface,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: C.border,
|
||||||
|
},
|
||||||
|
chipActive: { backgroundColor: C.surface2, borderColor: C.accent },
|
||||||
|
chipText: { color: C.muted, fontSize: 14 },
|
||||||
|
calendar: {
|
||||||
|
marginTop: 10,
|
||||||
|
backgroundColor: C.surface,
|
||||||
|
borderRadius: 14,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: C.border,
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
|
calHead: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", marginBottom: 6 },
|
||||||
|
calTitle: { color: C.text, fontSize: 15, fontWeight: "600" },
|
||||||
|
arrow: { paddingHorizontal: 14, paddingVertical: 4 },
|
||||||
|
arrowText: { color: C.accent, fontSize: 22, fontWeight: "600" },
|
||||||
|
week: { flexDirection: "row" },
|
||||||
|
weekday: { flex: 1, textAlign: "center", color: C.muted, fontSize: 11, paddingVertical: 4 },
|
||||||
|
day: {
|
||||||
|
flex: 1,
|
||||||
|
aspectRatio: 1.15,
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
borderRadius: 999,
|
||||||
|
margin: 1,
|
||||||
|
},
|
||||||
|
daySelected: { backgroundColor: C.accent },
|
||||||
|
dayToday: { borderWidth: 1, borderColor: C.accent },
|
||||||
|
dayText: { color: C.text, fontSize: 14 },
|
||||||
|
});
|
||||||
@@ -8,7 +8,7 @@ export default function PriorityChips({
|
|||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
}: {
|
}: {
|
||||||
value: Task["priority"];
|
value: Task["priority"] | null;
|
||||||
onChange: (p: Task["priority"]) => void;
|
onChange: (p: Task["priority"]) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { FlatList, RefreshControl, StyleSheet, Text, TextInput, View } from "react-native";
|
import { RefreshControl, StyleSheet, Text, View } from "react-native";
|
||||||
|
import DraggableFlatList, { ScaleDecorator } from "react-native-draggable-flatlist";
|
||||||
import { haptic } from "../lib/haptics";
|
import { haptic } from "../lib/haptics";
|
||||||
import { parseQuickAdd } from "../lib/quickadd";
|
import { reorderTask, sync, tasksByStatus } from "../lib/store";
|
||||||
import { createTask, sync, tasksByStatus } from "../lib/store";
|
|
||||||
import { C } from "../lib/theme";
|
import { C } from "../lib/theme";
|
||||||
import { useStore } from "../lib/useStore";
|
import { useStore } from "../lib/useStore";
|
||||||
import type { TaskStatus } from "../lib/types";
|
import type { TaskStatus } from "../lib/types";
|
||||||
@@ -10,45 +10,35 @@ import TaskRow from "./TaskRow";
|
|||||||
|
|
||||||
export default function TaskListScreen({
|
export default function TaskListScreen({
|
||||||
status,
|
status,
|
||||||
capture,
|
|
||||||
emptyHint,
|
emptyHint,
|
||||||
}: {
|
}: {
|
||||||
status: TaskStatus;
|
status: TaskStatus;
|
||||||
capture?: boolean;
|
|
||||||
emptyHint: string;
|
emptyHint: string;
|
||||||
}) {
|
}) {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
const [draft, setDraft] = useState("");
|
|
||||||
const tasks = tasksByStatus(store, status);
|
const tasks = tasksByStatus(store, status);
|
||||||
|
|
||||||
const add = () => {
|
|
||||||
if (!draft.trim()) return;
|
|
||||||
const parsed = parseQuickAdd(draft, store.projects);
|
|
||||||
if (!parsed.title) return;
|
|
||||||
setDraft("");
|
|
||||||
haptic.tap();
|
|
||||||
createTask({ ...parsed, status });
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={s.screen}>
|
<View style={s.screen}>
|
||||||
{capture && (
|
<DraggableFlatList
|
||||||
<TextInput
|
|
||||||
style={s.capture}
|
|
||||||
placeholder="Capture anything…"
|
|
||||||
placeholderTextColor={C.muted}
|
|
||||||
value={draft}
|
|
||||||
onChangeText={setDraft}
|
|
||||||
onSubmitEditing={add}
|
|
||||||
submitBehavior="submit"
|
|
||||||
returnKeyType="done"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<FlatList
|
|
||||||
data={tasks}
|
data={tasks}
|
||||||
keyExtractor={(t) => t.id}
|
keyExtractor={(t) => t.id}
|
||||||
renderItem={({ item }) => <TaskRow task={item} uncheckTo={status} />}
|
activationDistance={12}
|
||||||
|
onDragBegin={() => haptic.pickup()}
|
||||||
|
onDragEnd={({ data, from, to }) => {
|
||||||
|
if (from !== to) {
|
||||||
|
haptic.success();
|
||||||
|
reorderTask(data[to].id, status, to);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
renderItem={({ item, drag, isActive }) => (
|
||||||
|
<ScaleDecorator activeScale={1.03}>
|
||||||
|
<View style={isActive && s.activeRow}>
|
||||||
|
<TaskRow task={item} uncheckTo={status} onLongPress={drag} />
|
||||||
|
</View>
|
||||||
|
</ScaleDecorator>
|
||||||
|
)}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
@@ -69,16 +59,6 @@ export default function TaskListScreen({
|
|||||||
|
|
||||||
const s = StyleSheet.create({
|
const s = StyleSheet.create({
|
||||||
screen: { flex: 1, backgroundColor: C.bg },
|
screen: { flex: 1, backgroundColor: C.bg },
|
||||||
capture: {
|
activeRow: { backgroundColor: C.surface2, borderRadius: 12 },
|
||||||
margin: 12,
|
|
||||||
marginBottom: 4,
|
|
||||||
padding: 14,
|
|
||||||
borderRadius: 12,
|
|
||||||
backgroundColor: C.surface,
|
|
||||||
color: C.text,
|
|
||||||
fontSize: 16,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: C.border,
|
|
||||||
},
|
|
||||||
empty: { color: C.muted, textAlign: "center", marginTop: 48, fontSize: 15 },
|
empty: { color: C.muted, textAlign: "center", marginTop: 48, fontSize: 15 },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ export default function TaskRow({
|
|||||||
task,
|
task,
|
||||||
uncheckTo = "next",
|
uncheckTo = "next",
|
||||||
showStatus,
|
showStatus,
|
||||||
|
onLongPress,
|
||||||
}: {
|
}: {
|
||||||
task: Task;
|
task: Task;
|
||||||
/** Status to revert to when un-checking a done task. */
|
/** Status to revert to when un-checking a done task. */
|
||||||
uncheckTo?: TaskStatus;
|
uncheckTo?: TaskStatus;
|
||||||
showStatus?: boolean;
|
showStatus?: boolean;
|
||||||
|
/** Drag handle for reorderable lists. */
|
||||||
|
onLongPress?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const meta = [
|
const meta = [
|
||||||
@@ -37,7 +40,7 @@ export default function TaskRow({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.View entering={FadeIn.duration(150)}>
|
<Animated.View entering={FadeIn.duration(150)}>
|
||||||
<Pressable style={s.row} onPress={() => router.push(`/task/${task.id}`)}>
|
<Pressable style={s.row} onPress={() => router.push(`/task/${task.id}`)} onLongPress={onLongPress} delayLongPress={200}>
|
||||||
<Pressable
|
<Pressable
|
||||||
style={[s.checkbox, { borderColor: PRIORITY_COLOR[task.priority] }]}
|
style={[s.checkbox, { borderColor: PRIORITY_COLOR[task.priority] }]}
|
||||||
hitSlop={10}
|
hitSlop={10}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export interface State {
|
|||||||
hydrated: boolean;
|
hydrated: boolean;
|
||||||
syncing: boolean;
|
syncing: boolean;
|
||||||
pending: number;
|
pending: number;
|
||||||
|
/** True when the last sync failed for network reasons — expected offline. */
|
||||||
|
offline: boolean;
|
||||||
syncError: string | null;
|
syncError: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ let state: State = {
|
|||||||
hydrated: false,
|
hydrated: false,
|
||||||
syncing: false,
|
syncing: false,
|
||||||
pending: 0,
|
pending: 0,
|
||||||
|
offline: false,
|
||||||
syncError: null,
|
syncError: null,
|
||||||
};
|
};
|
||||||
let queue: Op[] = [];
|
let queue: Op[] = [];
|
||||||
@@ -114,7 +117,10 @@ export function createTask(data: Partial<Task> & { title: string }): Task {
|
|||||||
priority: data.priority ?? 4,
|
priority: data.priority ?? 4,
|
||||||
estimate_min: data.estimate_min ?? null,
|
estimate_min: data.estimate_min ?? null,
|
||||||
completed_at: null,
|
completed_at: null,
|
||||||
sort_order: data.sort_order ?? 0,
|
// New tasks land at the top of their list.
|
||||||
|
sort_order:
|
||||||
|
data.sort_order ??
|
||||||
|
Math.min(0, ...state.tasks.filter((t) => t.status === (data.status ?? "next")).map((t) => t.sort_order)) - 1,
|
||||||
created_at: now(),
|
created_at: now(),
|
||||||
updated_at: now(),
|
updated_at: now(),
|
||||||
};
|
};
|
||||||
@@ -190,9 +196,13 @@ export async function sync() {
|
|||||||
setState({});
|
setState({});
|
||||||
}
|
}
|
||||||
await pull();
|
await pull();
|
||||||
setState({ syncError: null });
|
setState({ syncError: null, offline: false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState({ syncError: e instanceof Error ? e.message : String(e) });
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
|
// fetch() network failures (airplane mode, no wifi, DNS) are the expected
|
||||||
|
// offline case, not an error — the queue simply waits for connectivity.
|
||||||
|
const isNetwork = e instanceof TypeError || /network request failed|unable to resolve|fetch failed|timeout/i.test(msg);
|
||||||
|
setState(isNetwork ? { offline: true, syncError: null } : { syncError: msg });
|
||||||
} finally {
|
} finally {
|
||||||
syncRunning = false;
|
syncRunning = false;
|
||||||
setState({ syncing: false });
|
setState({ syncing: false });
|
||||||
@@ -248,8 +258,27 @@ function byPriorityDue(a: Task, b: Task): number {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manual arrangement wins: sort_order is the canonical list order (set by
|
||||||
|
// drag-to-reorder); priority/due only break ties for rows that never moved.
|
||||||
|
function byManualOrder(a: Task, b: Task): number {
|
||||||
|
return a.sort_order - b.sort_order || byPriorityDue(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
export function tasksByStatus(s: State, status: Task["status"]): Task[] {
|
export function tasksByStatus(s: State, status: Task["status"]): Task[] {
|
||||||
return s.tasks.filter((t) => t.status === status).sort(byPriorityDue);
|
return s.tasks.filter((t) => t.status === status).sort(byManualOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Re-slot a task at `index` within its status list (fractional sort_order). */
|
||||||
|
export function reorderTask(id: string, status: Task["status"], index: number) {
|
||||||
|
const list = tasksByStatus(getState(), status).filter((t) => t.id !== id);
|
||||||
|
const prev = list[index - 1]?.sort_order;
|
||||||
|
const next = list[index]?.sort_order;
|
||||||
|
const sort_order =
|
||||||
|
prev !== undefined && next !== undefined ? (prev + next) / 2
|
||||||
|
: prev !== undefined ? prev + 1
|
||||||
|
: next !== undefined ? next - 1
|
||||||
|
: 0;
|
||||||
|
updateTask(id, { sort_order });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Overdue + due-today + deferred-arriving-today, across all open lists. */
|
/** Overdue + due-today + deferred-arriving-today, across all open lists. */
|
||||||
|
|||||||
@@ -31,9 +31,12 @@ function err(message: string, status: number) {
|
|||||||
const TASK_FIELDS = ["title", "notes", "status", "project_id", "context", "waiting_for", "due_date", "defer_date", "priority", "estimate_min", "sort_order"];
|
const TASK_FIELDS = ["title", "notes", "status", "project_id", "context", "waiting_for", "due_date", "defer_date", "priority", "estimate_min", "sort_order"];
|
||||||
const PROJECT_FIELDS = ["name", "status", "notes", "sort_order"];
|
const PROJECT_FIELDS = ["name", "status", "notes", "sort_order"];
|
||||||
|
|
||||||
|
// Only these may be cleared to NULL; notes/title are NOT NULL and keep "".
|
||||||
|
const NULLABLE = new Set(["project_id", "context", "waiting_for", "due_date", "defer_date", "estimate_min"]);
|
||||||
|
|
||||||
function pick(body: Record<string, unknown>, fields: string[]) {
|
function pick(body: Record<string, unknown>, fields: string[]) {
|
||||||
const out: Record<string, unknown> = {};
|
const out: Record<string, unknown> = {};
|
||||||
for (const f of fields) if (f in body) out[f] = body[f] === "" ? null : body[f];
|
for (const f of fields) if (f in body) out[f] = body[f] === "" && NULLABLE.has(f) ? null : body[f];
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +169,10 @@ Bun.serve({
|
|||||||
fetch: (req) =>
|
fetch: (req) =>
|
||||||
handle(req).catch((e) => {
|
handle(req).catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
// Constraint violations are bad input, not server faults — 400 so
|
||||||
|
// offline clients drop the op instead of retrying it forever.
|
||||||
|
const errno = (e as { errno?: string }).errno ?? "";
|
||||||
|
if (errno.startsWith("23")) return err(`constraint violation: ${(e as Error).message}`, 400);
|
||||||
return err("internal error", 500);
|
return err("internal error", 500);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user