26 Commits

Author SHA1 Message Date
c990ce243b refactor(projects): reuse cardEdges for the project list
Some checks failed
Build & Release APK / check (push) Has been cancelled
Build & Release APK / build (push) Has been cancelled
2026-09-01 23:24:32 +10:00
8019e7c4f0 refactor(ui): one cardEdges helper for the three list card stacks 2026-09-01 22:57:13 +10:00
d951971d59 refactor(task): one TaskForm behind both capture and clarify 2026-09-01 22:55:48 +10:00
e299ab69bd feat(add): collapse the capture form into a title card plus an attribute bar 2026-09-01 22:53:17 +10:00
5638aa9030 refactor(ui): one chip primitive for all four pickers; DateField reuses lib/dates 2026-09-01 22:48:35 +10:00
5f610e506b feat(icons): add flag, repeat, tag and close glyphs 2026-09-01 22:46:57 +10:00
9aba89a2a9 fix(ui): drop unsupported letterSpacing from headerTitleStyle 2026-09-01 22:44:33 +10:00
Claude
1398a5d54b UI: align home-screen widget and TaskRow with the palette tokens
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 22:39:46 +10:00
Claude
31934c7c27 UI: restyle weekly review, project detail and settings
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 22:39:12 +10:00
Claude
b183c2849b UI: restyle task detail onto the new tokens
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 22:37:59 +10:00
Claude
dff9142e2e UI: restyle Today, Add and Projects onto the new tokens
Also fixes Field silently dropping its base input style when a caller
passed their own (the multiline Description box was unstyled).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 22:37:26 +10:00
Claude
1af86cd27c UI: light Things-3 design system — tokens, task rows, chips, home
Replaces the dark navy palette with a light grouped-background system:
- theme.ts: full token set (space/radius/type/shadow) + light+dark palettes
- ui.tsx: Screen/Title/SectionHeader/Card/Separator/Pill/Empty primitives
- TaskRow: rounded-square checkbox carrying priority colour, inset separators
- TaskListScreen: rows grouped into a card, drag lift, refined deferred footer
- Icon.tsx: dependency-free geometric icon set (emoji don't take a tint)
- home: large title, Next-up card, "needs attention" rows, icon tab bar
- Priority/Estimate/Date chips unified on the accent-soft active state

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 22:36:26 +10:00
65efb632db Settings shows the installed build version (CI-stamped versionName) — confirms which release Obtainium delivered
All checks were successful
Build & Release APK / check (push) Successful in 16s
Build & Release APK / build (push) Successful in 2m16s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:53:50 -07:00
b260e4e762 CI hardening: fast-fail check job (lockfile/tsc/eslint) gates the APK build + optional ntfy alerts; config plugin makes 'expo prebuild' preserve release signing/versioning; node 22 pinned with docker lock script + pre-push hook
All checks were successful
Build & Release APK / check (push) Successful in 16s
Build & Release APK / build (push) Successful in 2m27s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:39:29 -07:00
e02ef05c02 Regenerate package-lock with npm 10 (node 22) so CI's npm ci accepts it — local npm 11 omitted top-level @emnapi peer-dep entries
All checks were successful
Build & Release APK / build (push) Successful in 2m26s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:26:27 -07:00
d54d5b32f1 Android home-screen widget: top-3 next actions (4x2 'Next up' card) — tap the priority ring to complete via the offline queue, rows deep-link to Clarify, + opens capture; redraws on every store change plus a 30-min self-refresh
Some checks failed
Build & Release APK / build (push) Failing after 24s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:06:45 -07:00
4ef3f8c63c Repeats, estimates, weekly review: completing a repeating task spawns the next occurrence; estimate chips + quick-add tokens (~30m, monthly); review screen with one-tap triage; server gains repeat column and applies its idempotent schema at boot
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:06:39 -07:00
6ccd417f2a Offline UX: network failures show quiet 'offline, n queued' not errors; auto-sync on connectivity regain + 45s heartbeat
All checks were successful
Build & Release APK / build (push) Successful in 2m10s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 23:50:34 -07:00
64967c19a0 API: don't null-out empty notes/title (NOT NULL columns); constraint violations return 400 so offline clients drop bad ops
All checks were successful
Build & Release APK / build (push) Successful in 2m1s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 23:40:31 -07:00
8091c7d94d Drag-to-reorder lists: manual sort_order is canonical, fractional re-slotting, haptic pickup/drop
All checks were successful
Build & Release APK / build (push) Successful in 2m8s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 20:47:28 -07:00
e7c092f35d Interactive date picker: quick chips + inline month calendar (due & defer)
All checks were successful
Build & Release APK / build (push) Successful in 2m4s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 20:45:15 -07:00
d6bd8500e3 Minimal home: top-3 next actions only, bottom icon menu, FAB-only capture, inbox abolished (priority+due required at creation)
All checks were successful
Build & Release APK / build (push) Successful in 1m52s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 20:27:36 -07:00
0487bc7e4e Todoist-style: priorities P1-P4, estimates, FAB add form, Today view, natural quick add, drag-and-drop with haptics
All checks were successful
Build & Release APK / build (push) Successful in 1m53s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 19:46:11 -07:00
035a114e58 GTD quadrant launcher icon; build speedups: arm64-only, 8G gradle heap, cached SDK step
Some checks failed
Build & Release APK / build (push) Failing after 14m4s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 19:31:46 -07:00
ad16522461 Local-first sync: on-device store + offline mutation queue, idempotent server upserts
All checks were successful
Build & Release APK / build (push) Successful in 10m54s
Screens render synchronously from an AsyncStorage-backed store; every
mutation applies locally and drains to the API in the background
(last-write-wins, client-generated UUIDs). Sydney round-trips are off the
interaction path and the app works fully offline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 19:19:51 -07:00
4d6031d007 Quadrant home screen: Next/Waiting/Someday/Projects grid replaces bottom tabs
Some checks failed
Build & Release APK / build (push) Has been cancelled
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 19:10:59 -07:00
57 changed files with 7721 additions and 526 deletions

View File

@@ -5,7 +5,36 @@ on:
branches: [main]
jobs:
check:
# Fast fail: lockfile sync, types, lint — catches in ~2 min what would
# otherwise kill the APK build twenty minutes in.
runs-on: desktop
container:
image: node:22
steps:
- name: Checkout
run: |
git init -q .
git fetch -q --depth 1 "https://git.rehbock.xyz/${{ github.repository }}.git" "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Lockfile + typecheck + lint
run: |
cd app
npm ci --no-audit --no-fund
npx tsc --noEmit
npx eslint .
- name: Notify failure
if: failure()
env:
NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }}
run: |
[ -n "$NTFY_TOKEN" ] || { echo "NTFY_TOKEN not set — skipping notification"; exit 0; }
curl -s -H "Authorization: Bearer $NTFY_TOKEN" -H "Title: gtd CI: check failed" -H "Priority: high" \
-d "typecheck/lint/lockfile failed at ${{ github.sha }} — https://git.rehbock.xyz/marcus/gtd/actions" \
https://ntfy.rehbock.xyz/gtd-ci
build:
needs: check
# RN/NDK builds starve the 4-core VPS — run on the desktop runner
# (marcusDesktop). Jobs queue while the desktop is off and start when it
# comes online; switch back to ubuntu-latest to build on the VPS.
@@ -28,7 +57,9 @@ jobs:
node --version
- name: Install Android SDK
# $HOME/android-sdk is a persistent runner volume — skip when warm.
run: |
if [ ! -d "$HOME/android-sdk/platforms/android-36" ]; then
mkdir -p "$HOME/android-sdk/cmdline-tools"
curl -sLo /tmp/ct.zip https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
unzip -q /tmp/ct.zip -d /tmp
@@ -36,6 +67,9 @@ jobs:
yes | "$HOME/android-sdk/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$HOME/android-sdk" --licenses >/dev/null 2>&1 || true
"$HOME/android-sdk/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$HOME/android-sdk" \
"platform-tools" "platforms;android-36" "build-tools;36.0.0" >/dev/null
else
echo "SDK cache warm — skipping install"
fi
- name: Install app dependencies
run: cd app && npm ci --no-audit --no-fund
@@ -76,3 +110,13 @@ jobs:
-H "Authorization: token $TOKEN" \
-F "attachment=@$APK;type=application/vnd.android.package-archive" >/dev/null
echo "published $TAG"
- name: Notify failure
if: failure()
env:
NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }}
run: |
[ -n "$NTFY_TOKEN" ] || { echo "NTFY_TOKEN not set — skipping notification"; exit 0; }
curl -s -H "Authorization: Bearer $NTFY_TOKEN" -H "Title: gtd CI: APK build failed" -H "Priority: high" \
-d "release build failed at ${{ github.sha }} — https://git.rehbock.xyz/marcus/gtd/actions" \
https://ntfy.rehbock.xyz/gtd-ci

12
.githooks/pre-push Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
# Reject pushes whose lockfile CI's npm (node 22) would refuse — a lock
# written by a newer local npm fails `npm ci` on the runner half a build in.
# Enable with: git config core.hooksPath .githooks
set -e
root=$(git rev-parse --show-toplevel)
if git diff --quiet origin/main...HEAD -- app/package.json app/package-lock.json 2>/dev/null; then
exit 0
fi
echo "pre-push: package.json/lock changed — validating with CI's npm (node:22)…"
docker run --rm -v "$root/app:/w" -w /w node:22 npm ci --dry-run --no-audit --no-fund >/dev/null
echo "pre-push: lockfile OK"

View File

@@ -9,7 +9,11 @@ Minimal Getting Things Done app. One Expo/React Native codebase for iPhone, Andr
## Layout
- `app/` — Expo app (expo-router, TypeScript). Tabs: Inbox / Next / Waiting / Someday / Projects; tap a task to clarify (list, project, context, waiting-for, due/defer dates).
- `app/` — Expo app (expo-router, TypeScript). Home shows the top 3 next actions plus a launcher menu: Today / Next / Waiting / Someday / Projects / Review. There is no inbox — every task is born fully scoped (title, priority, due date). Tap a task to clarify (list, project, context, waiting-for, due/defer dates, repeat).
- **Quick add**: the title field parses tokens live — `Pay rent tmr p1 @home #Sydney ~30m monthly` — and mirrors them into the form.
- **Repeat**: daily / weekdays / weekly / monthly / yearly; completing spawns the next occurrence (lapsed tasks catch up to today).
- **Defer**: deferred tasks are hidden from action lists until their date; a footer link reveals them.
- **Weekly review**: overdue, stalled (14d), aging waiting-fors (7d), someday sweep, deferred preview, stuck projects — with one-tap triage per row. Done and Trash (restorable) live at the bottom of Review.
- `server/` — Bun API + Dockerfile + compose. Deployed at `~/personal/gtd` on rehbock.xyz, joined to `personal-db_default` + `caddy_net`.
## Develop
@@ -18,6 +22,15 @@ Minimal Getting Things Done app. One Expo/React Native codebase for iPhone, Andr
cd app && npx expo start # scan QR with Expo Go (iPhone or Pixel)
```
- **Node 22 only** (`app/.nvmrc`): CI's npm 10 rejects lockfiles written by newer npm. Never run bare `npm install` to change deps — use `npm run lock` (regenerates the lock via a `node:22` container), or run npm from node 22.
- **Hook**: `git config core.hooksPath .githooks` enables a pre-push check that validates the lockfile against CI's npm before it can break a build.
- **Local Android builds** need JDK 21 (AGP chokes on newer): pinned via `org.gradle.java.home` in `~/.gradle/gradle.properties` → `~/.local/share/java/jdk-21.0.12+8`.
- **`expo prebuild` is safe to re-run**: `app/plugins/withAndroidRelease.js` re-injects the release signing, env-driven versionCode/Name, and gradle.properties tuning into the committed `android/`.
## Release (Android APK → Obtainium)
Every push to `main` runs `.gitea/workflows/release.yml` on the desktop runner: fast check job (lockfile/types/lint), then a signed `assembleRelease`, published as Gitea release `v1.<run>` with the APK attached. Phones track it with Obtainium → source `https://git.rehbock.xyz/marcus/gtd` (Forgejo/Gitea source type). CI failures push to ntfy topic `gtd-ci` when the `NTFY_TOKEN` repo secret is set.
## Deploy
```sh

1
app/.nvmrc Normal file
View File

@@ -0,0 +1 @@
22

View File

@@ -16,6 +16,7 @@
<meta-data android:name="expo.modules.updates.ENABLE_BSDIFF_PATCH_SUPPORT" android:value="true"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<service android:name="com.reactnativeandroidwidget.RNWidgetCollectionService" android:permission="android.permission.BIND_REMOTEVIEWS"/>
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize|assetsPaths" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@@ -28,5 +29,12 @@
<data android:scheme="gtd"/>
</intent-filter>
</activity>
<receiver android:name=".widget.NextUp" android:exported="false" android:label="GTD — Next up">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="com.marcus.gtd.WIDGET_CLICK"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widgetprovider_nextup"/>
</receiver>
</application>
</manifest>

View File

@@ -0,0 +1,6 @@
package com.marcus.gtd.widget;
import com.reactnativeandroidwidget.RNWidgetProvider;
public class NextUp extends RNWidgetProvider {
}

View File

@@ -2,4 +2,5 @@
<string name="app_name">GTD</string>
<string name="expo_system_ui_user_interface_style" translatable="false">automatic</string>
<string name="expo_splash_screen_resize_mode" translatable="false">contain</string>
<string name="widget_nextup_description" translatable="false">Your top three next actions</string>
</resources>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="110dp"
android:targetCellWidth="4"
android:targetCellHeight="2"
android:resizeMode="horizontal|vertical"
android:description="@string/widget_nextup_description"
android:initialLayout="@layout/rn_widget"
android:updatePeriodMillis="1800000"
android:widgetCategory="home_screen">
</appwidget-provider>

View File

@@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx8192m -XX:MaxMetaspaceSize=1024m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
@@ -28,7 +28,7 @@ android.enablePngCrunchInReleaseBuilds=true
# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
reactNativeArchitectures=arm64-v8a
# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in

View File

@@ -25,7 +25,26 @@
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"./plugins/withAndroidRelease",
"expo-router",
[
"react-native-android-widget",
{
"widgets": [
{
"name": "NextUp",
"label": "GTD — Next up",
"description": "Your top three next actions",
"minWidth": "250dp",
"minHeight": "110dp",
"targetCellWidth": 4,
"targetCellHeight": 2,
"resizeMode": "horizontal|vertical",
"updatePeriodMillis": 1800000
}
]
}
],
[
"expo-splash-screen",
{

10
app/eslint.config.js Normal file
View File

@@ -0,0 +1,10 @@
// https://docs.expo.dev/guides/using-eslint/
const { defineConfig } = require('eslint/config');
const expoConfig = require("eslint-config-expo/flat");
module.exports = defineConfig([
expoConfig,
{
ignores: ["dist/*"],
}
]);

10
app/index.js Normal file
View File

@@ -0,0 +1,10 @@
// Custom entry: register the widget's headless task handler before the app
// starts, so widget events work even when the app UI never mounts.
import "expo-router/entry";
import { Platform } from "react-native";
import { registerWidgetTaskHandler } from "react-native-android-widget";
import { widgetTaskHandler } from "./src/widget/widget-task-handler";
if (Platform.OS === "android") {
registerWidgetTaskHandler(widgetTaskHandler);
}

4144
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,19 @@
{
"name": "app",
"main": "expo-router/entry",
"main": "index.js",
"version": "1.0.0",
"dependencies": {
"@expo/ui": "~57.0.9",
"@react-native-async-storage/async-storage": "2.2.0",
"@react-native-community/netinfo": "12.0.1",
"expo": "~57.0.11",
"expo-application": "~57.0.2",
"expo-constants": "~57.0.9",
"expo-crypto": "~57.0.1",
"expo-device": "~57.0.1",
"expo-font": "~57.0.1",
"expo-glass-effect": "~57.0.1",
"expo-haptics": "~57.0.1",
"expo-image": "~57.0.2",
"expo-linking": "~57.0.5",
"expo-router": "~57.0.11",
@@ -21,6 +25,8 @@
"react": "19.2.3",
"react-dom": "19.2.3",
"react-native": "0.86.2",
"react-native-android-widget": "^0.22.1",
"react-native-draggable-flatlist": "^4.0.3",
"react-native-gesture-handler": "~2.32.0",
"react-native-reanimated": "4.5.1",
"react-native-safe-area-context": "~5.7.0",
@@ -30,9 +36,15 @@
},
"devDependencies": {
"@types/react": "~19.2.2",
"eslint": "^9.0.0",
"eslint-config-expo": "~57.0.1",
"typescript": "~6.0.3"
},
"engines": {
"node": "22.x"
},
"scripts": {
"lock": "docker run --rm -v $PWD:/w -w /w node:22 npm install --package-lock-only --no-audit --no-fund",
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "expo run:android",

View File

@@ -0,0 +1,59 @@
// Makes `expo prebuild` safe to re-run: re-applies the hand-maintained Android
// release config that a fresh prebuild would otherwise reset to template
// defaults (android/ is committed; CI builds it and relies on all of this).
const { withAppBuildGradle, withGradleProperties } = require("expo/config-plugins");
const RELEASE_SIGNING = ` release {
// Keystore path + password come from env (CI) or ~/.android-keys (local).
def ksPath = System.getenv("KEYSTORE_FILE") ?: "\${System.properties['user.home']}/.android-keys/gtd-release.jks"
def passFile = new File("\${System.properties['user.home']}/.android-keys/gtd-release.password")
def ksPass = System.getenv("KEYSTORE_PASSWORD") ?: (passFile.exists() ? passFile.text.trim() : null)
if (new File(ksPath).exists() && ksPass != null) {
storeFile file(ksPath)
storePassword ksPass
keyAlias System.getenv("KEY_ALIAS") ?: "gtd"
keyPassword System.getenv("KEY_PASSWORD") ?: ksPass
}
}
`;
function patchBuildGradle(gradle) {
gradle = gradle.replace(/versionCode \d+\n/, 'versionCode ((System.getenv("VERSION_CODE") ?: "1").toInteger())\n');
gradle = gradle.replace(/versionName "[^"]*"\n/, 'versionName (System.getenv("VERSION_NAME") ?: "1.0-dev")\n');
if (!gradle.includes("KEYSTORE_FILE")) {
// Insert the release signing config right after the debug one.
gradle = gradle.replace(
/(signingConfigs \{\n debug \{[\s\S]*?\n \}\n)/,
`$1${RELEASE_SIGNING}`,
);
}
// Release builds use the release key when present, debug key otherwise.
gradle = gradle.replace(
/(release \{\n)(?:\s*\/\/[^\n]*\n)*\s*signingConfig signingConfigs\.debug\n/,
"$1 signingConfig signingConfigs.release.storeFile ? signingConfigs.release : signingConfigs.debug\n",
);
return gradle;
}
const GRADLE_PROPS = [
// RN/NDK builds want headroom; the template default is 2 GB.
{ key: "org.gradle.jvmargs", value: "-Xmx8192m -XX:MaxMetaspaceSize=1024m" },
// arm64 only: Pixel is arm64-v8a; x86/v7a builds are wasted time + APK bloat.
{ key: "reactNativeArchitectures", value: "arm64-v8a" },
];
module.exports = function withAndroidRelease(config) {
config = withAppBuildGradle(config, (c) => {
c.modResults.contents = patchBuildGradle(c.modResults.contents);
return c;
});
config = withGradleProperties(config, (c) => {
for (const { key, value } of GRADLE_PROPS) {
const existing = c.modResults.find((p) => p.type === "property" && p.key === key);
if (existing) existing.value = value;
else c.modResults.push({ type: "property", key, value });
}
return c;
});
return config;
};

View File

@@ -1,36 +0,0 @@
import { Link, Tabs } from "expo-router";
import { Text } from "react-native";
import { C } from "../../lib/theme";
function icon(glyph: string) {
return ({ focused }: { focused: boolean }) => (
<Text style={{ fontSize: 20, opacity: focused ? 1 : 0.45 }}>{glyph}</Text>
);
}
export default function TabsLayout() {
return (
<Tabs
screenOptions={{
headerStyle: { backgroundColor: C.bg },
headerTintColor: C.text,
headerShadowVisible: false,
sceneStyle: { backgroundColor: C.bg },
tabBarStyle: { backgroundColor: C.bg, borderTopColor: C.border },
tabBarActiveTintColor: C.text,
tabBarInactiveTintColor: C.muted,
headerRight: () => (
<Link href="/settings" style={{ paddingHorizontal: 16, fontSize: 18 }}>
⚙️
</Link>
),
}}
>
<Tabs.Screen name="index" options={{ title: "Inbox", tabBarIcon: icon("📥") }} />
<Tabs.Screen name="next" options={{ title: "Next", tabBarIcon: icon("▶️") }} />
<Tabs.Screen name="waiting" options={{ title: "Waiting", tabBarIcon: icon("⏳") }} />
<Tabs.Screen name="someday" options={{ title: "Someday", tabBarIcon: icon("💭") }} />
<Tabs.Screen name="projects" options={{ title: "Projects", tabBarIcon: icon("📁") }} />
</Tabs>
);
}

View File

@@ -1,5 +0,0 @@
import TaskListScreen from "../../components/TaskListScreen";
export default function Inbox() {
return <TaskListScreen status="inbox" capture emptyHint="Inbox zero. Capture anything above." />;
}

View File

@@ -1,5 +0,0 @@
import TaskListScreen from "../../components/TaskListScreen";
export default function Next() {
return <TaskListScreen status="next" capture emptyHint="No next actions. Clarify your inbox." />;
}

View File

@@ -1,95 +0,0 @@
import { useFocusEffect, useRouter } from "expo-router";
import { useCallback, useState } from "react";
import { FlatList, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
import { api } from "../../lib/api";
import { C } from "../../lib/theme";
import type { Project } from "../../lib/types";
export default function Projects() {
const router = useRouter();
const [projects, setProjects] = useState<Project[]>([]);
const [draft, setDraft] = useState("");
const [error, setError] = useState<string | null>(null);
const load = useCallback(async () => {
try {
setProjects(await api.projects.list());
setError(null);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
}
}, []);
useFocusEffect(
useCallback(() => {
load();
}, [load]),
);
const add = async () => {
const name = draft.trim();
if (!name) return;
setDraft("");
await api.projects.create({ name });
load();
};
return (
<View style={s.screen}>
<TextInput
style={s.capture}
placeholder="New project…"
placeholderTextColor={C.muted}
value={draft}
onChangeText={setDraft}
onSubmitEditing={add}
returnKeyType="done"
/>
{error && <Text style={s.error}>{error}</Text>}
<FlatList
data={projects}
keyExtractor={(p) => p.id}
renderItem={({ item }) => (
<Pressable style={s.row} onPress={() => router.push(`/project/${item.id}`)}>
<View style={{ flex: 1 }}>
<Text style={s.title}>{item.name}</Text>
<Text style={s.meta}>
{item.status}
{item.open_tasks != null && ` · ${item.open_tasks} open`}
</Text>
</View>
<Text style={{ color: C.muted }}>›</Text>
</Pressable>
)}
ListEmptyComponent={<Text style={s.empty}>No projects yet.</Text>}
/>
</View>
);
}
const s = StyleSheet.create({
screen: { flex: 1, backgroundColor: C.bg },
capture: {
margin: 12,
marginBottom: 4,
padding: 14,
borderRadius: 12,
backgroundColor: C.surface,
color: C.text,
fontSize: 16,
borderWidth: 1,
borderColor: C.border,
},
row: {
flexDirection: "row",
alignItems: "center",
paddingVertical: 14,
paddingHorizontal: 16,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: C.border,
},
title: { color: C.text, fontSize: 16 },
meta: { color: C.muted, fontSize: 13, marginTop: 2 },
empty: { color: C.muted, textAlign: "center", marginTop: 48 },
error: { color: C.danger, marginHorizontal: 16, marginTop: 8 },
});

View File

@@ -1,5 +0,0 @@
import TaskListScreen from "../../components/TaskListScreen";
export default function Someday() {
return <TaskListScreen status="someday" emptyHint="No someday/maybe items." />;
}

View File

@@ -1,5 +0,0 @@
import TaskListScreen from "../../components/TaskListScreen";
export default function Waiting() {
return <TaskListScreen status="waiting" emptyHint="Not waiting on anyone." />;
}

View File

@@ -1,24 +1,79 @@
import { Stack } from "expo-router";
import NetInfo from "@react-native-community/netinfo";
import { Link, Stack } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { C } from "../lib/theme";
import { useEffect } from "react";
import { AppState, Pressable } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { getState, hydrate, subscribe, sync } from "../lib/store";
import Icon from "../components/Icon";
import { C, space } from "../lib/theme";
import { refreshNextUpWidget } from "../widget/refresh";
export default function RootLayout() {
useEffect(() => {
void hydrate();
// Re-sync whenever the app returns to the foreground.
const appState = AppState.addEventListener("change", (s) => {
if (s === "active") void sync();
});
// Drain the queue the moment connectivity returns (wifi/cellular).
const net = NetInfo.addEventListener((s) => {
if (s.isConnected) void sync();
});
// Keep the home-screen widget in step with every mutation and sync.
const widget = subscribe(refreshNextUpWidget);
// 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();
widget();
clearInterval(heartbeat);
};
}, []);
return (
<>
<StatusBar style="light" />
<GestureHandlerRootView style={{ flex: 1 }}>
<StatusBar style="dark" />
<Stack
screenOptions={{
headerStyle: { backgroundColor: C.bg },
headerTintColor: C.text,
// No hairline under the bar: the header should melt into the grouped
// background so the in-content Title carries the hierarchy instead.
headerShadowVisible: false,
headerTitleStyle: { fontSize: 17, fontWeight: "600", color: C.text },
headerBackButtonDisplayMode: "minimal",
contentStyle: { backgroundColor: C.bg },
}}
>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="index"
options={{
title: "GTD",
headerRight: () => (
<Link href="/settings" asChild>
<Pressable
hitSlop={12}
style={({ pressed }) => [{ paddingHorizontal: space.sm }, pressed && { opacity: 0.5 }]}
>
<Icon name="settings" size={22} color={C.textSecondary} />
</Pressable>
</Link>
),
}}
/>
<Stack.Screen name="list/[status]" />
<Stack.Screen name="today" options={{ title: "Today" }} />
<Stack.Screen name="add" options={{ title: "New task", presentation: "modal" }} />
<Stack.Screen name="projects" options={{ title: "Projects" }} />
<Stack.Screen name="task/[id]" options={{ title: "Clarify", presentation: "modal" }} />
<Stack.Screen name="project/[id]" options={{ title: "Project" }} />
<Stack.Screen name="review" options={{ title: "Weekly review" }} />
<Stack.Screen name="settings" options={{ title: "Settings", presentation: "modal" }} />
</Stack>
</>
</GestureHandlerRootView>
);
}

108
app/src/app/add.tsx Normal file
View File

@@ -0,0 +1,108 @@
import { useRouter } from "expo-router";
import { useRef, useState } from "react";
import { Pressable, ScrollView, StyleSheet, Text } from "react-native";
import TaskForm, { BOX_LABEL, emptyDraft, type TaskDraft } from "../components/TaskForm";
import { haptic } from "../lib/haptics";
import { parseQuickAdd, type ParsedQuickAdd } from "../lib/quickadd";
import { activeProjects, createTask } from "../lib/store";
import { C, radius, space } from "../lib/theme";
import { useStore } from "../lib/useStore";
/**
* Capture screen.
*
* Deliberately one card and one row of chips. Everything optional lives behind
* a chip that shows its own value, so the common case — type a title, hit Add —
* is two interactions and never scrolls, while a fully specified task is still
* reachable without leaving the screen.
*/
export default function AddTask() {
const router = useRouter();
const store = useStore();
const [draft, setDraft] = useState<TaskDraft>(emptyDraft);
const projects = activeProjects(store).filter((p) => p.status === "active");
// The title field understands tokens ("Pay rent tmr p1 @home ~30m monthly")
// and mirrors each one into the chips below as you type, so capture is one
// line but every inference stays visible and correctable. A token only
// writes its field when it changes — chips tapped by hand stick.
const prevParsed = useRef<ParsedQuickAdd>({ title: "" });
const change = (patch: Partial<TaskDraft>) => {
if (patch.title === undefined) return setDraft((d) => ({ ...d, ...patch }));
const p = parseQuickAdd(patch.title, projects);
const prev = prevParsed.current;
const mirrored: Partial<TaskDraft> = {};
if (p.priority !== prev.priority && p.priority) mirrored.priority = p.priority;
if (p.due_date !== prev.due_date && p.due_date) mirrored.due_date = p.due_date;
if (p.estimate_min !== prev.estimate_min && p.estimate_min) mirrored.estimate_min = p.estimate_min;
if (p.repeat !== prev.repeat && p.repeat) mirrored.repeat = p.repeat;
if (p.project_id !== prev.project_id && p.project_id) mirrored.project_id = p.project_id;
if (p.context !== prev.context) mirrored.context = p.context ?? null;
prevParsed.current = p;
setDraft((d) => ({ ...d, ...patch, ...mirrored }));
};
// The field keeps the tokens visible; only the saved task loses them.
const cleanTitle = parseQuickAdd(draft.title, projects).title.trim() || draft.title.trim();
const tokensUsed = draft.title.trim() !== cleanTitle;
const ready = cleanTitle.length > 0;
const save = () => {
if (!ready) return;
createTask({
...draft,
title: cleanTitle,
// Unset priority means "ordinary", not "urgent" — pick the middle rung
// rather than blocking capture on a decision that can wait for review.
priority: draft.priority ?? 3,
waiting_for: draft.status === "waiting" ? draft.waiting_for?.trim() || null : null,
});
haptic.success();
router.back();
};
return (
<ScrollView
style={{ flex: 1, backgroundColor: C.bg }}
contentContainerStyle={s.content}
keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
>
<TaskForm
value={draft}
onChange={change}
autoFocus
onSubmitTitle={save}
hint={
tokensUsed
? `Saving as “${cleanTitle}” — tokens moved into the chips below.`
: "Type p1 · tmr · @home · ~30m · #project to fill these in as you go."
}
/>
<Pressable
style={({ pressed }) => [s.save, !ready && s.saveDisabled, pressed && ready && { opacity: 0.85 }]}
onPress={save}
disabled={!ready}
>
<Text style={[s.saveText, !ready && s.saveTextDisabled]}>Add to {BOX_LABEL[draft.status]}</Text>
</Pressable>
</ScrollView>
);
}
const s = StyleSheet.create({
content: { padding: space.lg, paddingBottom: space.xxl },
save: {
backgroundColor: C.accent,
borderRadius: radius.md,
paddingVertical: space.lg - 2,
alignItems: "center",
marginTop: space.xl,
},
saveDisabled: { backgroundColor: C.surface2 },
saveText: { fontSize: 16, fontWeight: "600", color: C.onAccent },
saveTextDisabled: { color: C.muted },
});

195
app/src/app/index.tsx Normal file
View File

@@ -0,0 +1,195 @@
import { useFocusEffect, useRouter } from "expo-router";
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
import Icon, { type IconName } from "../components/Icon";
import TaskRow, { TaskSeparator } from "../components/TaskRow";
import { Card, Empty, Screen, SectionHeader, Title } from "../components/ui";
import { haptic } from "../lib/haptics";
import { daysSince, useLastReview } from "../lib/review";
import { todayTasks, visibleTasksByStatus } from "../lib/store";
import { C, shadow, space, type } from "../lib/theme";
import { useStore } from "../lib/useStore";
const MENU: { icon: IconName; label: string; href: string }[] = [
{ icon: "today", label: "Today", href: "/today" },
{ icon: "next", label: "Next", href: "/list/next" },
{ icon: "waiting", label: "Waiting", href: "/list/waiting" },
{ icon: "someday", label: "Someday", href: "/list/someday" },
{ icon: "projects", label: "Projects", href: "/projects" },
{ icon: "review", label: "Review", href: "/review" },
];
const PREVIEW = 3;
/**
* One tappable line of status — overdue, review due, sync trouble. Rendered as
* a real row with a chevron rather than coloured micro-text, so it reads as
* something you can act on.
*/
function Alert({ tone, text, onPress }: { tone: string; text: string; onPress?: () => void }) {
const body = (
<View style={s.alert}>
<View style={[s.dot, { backgroundColor: tone }]} />
<Text style={[s.alertText, { color: tone }]}>{text}</Text>
{!!onPress && <Icon name="chevron" size={16} color={tone} />}
</View>
);
if (!onPress) return body;
return (
<Pressable onPress={onPress} style={({ pressed }) => pressed && { opacity: 0.6 }}>
{body}
</Pressable>
);
}
export default function Home() {
const router = useRouter();
const store = useStore();
const next = visibleTasksByStatus(store, "next");
const { overdue } = todayTasks(store);
const [lastReview, reloadReview] = useLastReview();
useFocusEffect(reloadReview);
const reviewDays = daysSince(lastReview);
const reviewDue = lastReview === null || (reviewDays !== null && reviewDays >= 7);
const preview = next.slice(0, PREVIEW);
return (
<Screen>
<ScrollView contentContainerStyle={s.content} showsVerticalScrollIndicator={false}>
<Title count={next.length}>Next up</Title>
{preview.length === 0 ? (
<Empty>Nothing queued. Add the next thing on your mind.</Empty>
) : (
<Card>
{preview.map((t, i) => (
<View key={t.id}>
{i > 0 && <TaskSeparator />}
<TaskRow task={t} />
</View>
))}
</Card>
)}
{next.length > PREVIEW && (
<Pressable
onPress={() => router.push("/list/next")}
style={({ pressed }) => [s.viewAll, pressed && { opacity: 0.6 }]}
>
<Text style={s.viewAllText}>All {next.length} next actions</Text>
<Icon name="chevron" size={16} color={C.accent} />
</Pressable>
)}
{(overdue.length > 0 || reviewDue || store.offline || !!store.syncError) && (
<>
<SectionHeader>Needs attention</SectionHeader>
<Card>
{overdue.length > 0 && (
<Alert
tone={C.danger}
text={`${overdue.length} overdue`}
onPress={() => router.push("/today")}
/>
)}
{reviewDue && (
<Alert
tone={C.warn}
text={
lastReview === null
? "No weekly review yet"
: `Weekly review is ${reviewDays} days overdue`
}
onPress={() => router.push("/review")}
/>
)}
{store.offline && (
<Alert
tone={C.textSecondary}
text={
store.pending > 0
? `Offline — ${store.pending} change${store.pending === 1 ? "" : "s"} queued`
: "Offline"
}
/>
)}
{!!store.syncError && <Alert tone={C.danger} text={store.syncError} />}
</Card>
</>
)}
</ScrollView>
<View style={s.tabBar}>
{MENU.map((m) => (
<Pressable
key={m.label}
style={({ pressed }) => [s.tab, pressed && { opacity: 0.5 }]}
onPress={() => {
haptic.tap();
router.push(m.href);
}}
>
<Icon name={m.icon} size={21} color={C.textSecondary} bg={C.surface} />
<Text style={s.tabLabel}>{m.label}</Text>
</Pressable>
))}
</View>
<Pressable
style={({ pressed }) => [s.fab, pressed && { transform: [{ scale: 0.94 }] }]}
onPress={() => {
haptic.tap();
router.push("/add");
}}
>
<Icon name="plus" size={26} color={C.onAccent} />
</Pressable>
</Screen>
);
}
const s = StyleSheet.create({
content: { paddingHorizontal: space.lg, paddingBottom: 120 },
viewAll: {
flexDirection: "row",
alignItems: "center",
gap: space.xs,
paddingVertical: space.md,
paddingHorizontal: space.xs,
},
viewAllText: { ...type.body, color: C.accent, fontWeight: "500" },
alert: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingVertical: space.md + 1,
paddingHorizontal: space.lg,
},
dot: { width: 7, height: 7, borderRadius: 999 },
alertText: { ...type.body, flex: 1, fontWeight: "500" },
tabBar: {
flexDirection: "row",
backgroundColor: C.surface,
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: C.border,
paddingTop: space.md,
paddingBottom: space.xxl,
},
tab: { flex: 1, alignItems: "center", gap: 5 },
tabLabel: { fontSize: 11, color: C.textSecondary, letterSpacing: 0.1 },
fab: {
position: "absolute",
right: space.xl,
bottom: 104,
width: 56,
height: 56,
borderRadius: 28,
backgroundColor: C.accent,
alignItems: "center",
justifyContent: "center",
...shadow.fab,
},
});

View File

@@ -0,0 +1,30 @@
import { Stack, useLocalSearchParams } from "expo-router";
import TaskListScreen from "../../components/TaskListScreen";
import type { TaskStatus } from "../../lib/types";
const TITLES: Record<string, string> = {
next: "Next up",
waiting: "Waiting for",
someday: "Someday",
done: "Done",
trashed: "Trash",
};
const HINTS: Record<string, string> = {
next: "Nothing next. Tap + on the home screen.",
waiting: "Not waiting on anyone.",
someday: "No someday/maybe items.",
done: "Nothing done yet.",
trashed: "Trash is empty.",
};
export default function ListByStatus() {
const { status } = useLocalSearchParams<{ status: string }>();
const st = (status in TITLES ? status : "next") as TaskStatus;
return (
<>
<Stack.Screen options={{ title: TITLES[st] }} />
<TaskListScreen status={st} emptyHint={HINTS[st]} />
</>
);
}

View File

@@ -1,60 +1,46 @@
import { Stack, useFocusEffect, useLocalSearchParams, useRouter } from "expo-router";
import { useCallback, useState } from "react";
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
import { useState } from "react";
import { FlatList, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
import { Button, Chips } from "../../components/ui";
import { api } from "../../lib/api";
import { C } from "../../lib/theme";
import type { Project, ProjectStatus, Task } from "../../lib/types";
import Icon from "../../components/Icon";
import { Button, cardEdges, Chips, Empty, Separator } from "../../components/ui";
import { haptic } from "../../lib/haptics";
import { createTask, dropProject, updateProject, updateTask } from "../../lib/store";
import { C, radius, space, type } from "../../lib/theme";
import { useStore } from "../../lib/useStore";
import type { ProjectStatus } from "../../lib/types";
const STATUSES: ProjectStatus[] = ["active", "someday", "completed"];
export default function ProjectDetail() {
const { id } = useLocalSearchParams<{ id: string }>();
const router = useRouter();
const [project, setProject] = useState<Project | null>(null);
const [tasks, setTasks] = useState<Task[]>([]);
const store = useStore();
const [draft, setDraft] = useState("");
const load = useCallback(async () => {
const [ps, ts] = await Promise.all([api.projects.list(), api.tasks.list({ project_id: id })]);
setProject(ps.find((p) => p.id === id) ?? null);
setTasks(ts.filter((t) => t.status !== "done"));
}, [id]);
const project = store.projects.find((p) => p.id === id);
if (!project) return <Empty>Project not found.</Empty>;
useFocusEffect(
useCallback(() => {
load();
}, [load]),
);
const tasks = store.tasks
.filter((t) => t.project_id === id && t.status !== "done" && t.status !== "trashed")
.sort((a, b) => a.sort_order - b.sort_order || b.created_at.localeCompare(a.created_at));
if (!project) return <Text style={{ color: C.muted, margin: 16 }}>Loading…</Text>;
const add = async () => {
const add = () => {
const title = draft.trim();
if (!title) return;
setDraft("");
await api.tasks.create({ title, status: "next", project_id: id });
load();
};
const complete = async (t: Task) => {
setTasks((cur) => cur.filter((x) => x.id !== t.id));
await api.tasks.update(t.id, { status: "done" });
load();
haptic.success();
createTask({ title, status: "next", project_id: id });
};
return (
<View style={{ flex: 1, backgroundColor: C.bg }}>
<Stack.Screen options={{ title: project.name }} />
<View style={{ padding: 16, paddingBottom: 0 }}>
<View style={{ paddingHorizontal: space.lg, paddingTop: space.md }}>
<Chips
label="Status"
options={STATUSES}
value={project.status}
onChange={async (status) => {
setProject({ ...project, status });
await api.projects.update(project.id, { status });
}}
onChange={(status) => updateProject(project.id, { status })}
/>
</View>
<TextInput
@@ -64,28 +50,49 @@ export default function ProjectDetail() {
value={draft}
onChangeText={setDraft}
onSubmitEditing={add}
submitBehavior="submit"
returnKeyType="done"
/>
<FlatList
data={tasks}
keyExtractor={(t) => t.id}
renderItem={({ item }) => (
<Pressable style={s.row} onPress={() => router.push(`/task/${item.id}`)}>
<Pressable style={s.checkbox} hitSlop={10} onPress={() => complete(item)} />
renderItem={({ item, index }) => (
<Pressable
style={({ pressed }) => [
s.row,
...cardEdges(index, tasks.length),
pressed && { backgroundColor: C.surface2 },
]}
onPress={() => router.push(`/task/${item.id}`)}
>
<Pressable
style={s.checkbox}
hitSlop={10}
onPress={() => {
haptic.success();
updateTask(item.id, { status: "done" });
}}
/>
<View style={{ flex: 1 }}>
<Text style={s.title}>{item.title}</Text>
<Text style={s.title} numberOfLines={2}>
{item.title}
</Text>
<Text style={s.meta}>{[item.status, item.context].filter(Boolean).join(" · ")}</Text>
</View>
<Icon name="chevron" size={16} color={C.muted} />
</Pressable>
)}
ListEmptyComponent={<Text style={s.empty}>No open tasks in this project.</Text>}
ItemSeparatorComponent={() => <Separator inset={space.lg + 21 + space.md} />}
ListEmptyComponent={<Empty>No open tasks in this project.</Empty>}
contentContainerStyle={s.listContent}
showsVerticalScrollIndicator={false}
/>
<View style={{ padding: 16 }}>
<View style={{ paddingHorizontal: space.lg, paddingBottom: space.lg }}>
<Button
title="Drop project"
danger
onPress={async () => {
await api.projects.drop(project.id);
onPress={() => {
dropProject(project.id);
router.back();
}}
/>
@@ -96,27 +103,26 @@ export default function ProjectDetail() {
const s = StyleSheet.create({
capture: {
margin: 12,
marginBottom: 4,
padding: 14,
borderRadius: 12,
marginHorizontal: space.lg,
marginBottom: space.lg,
paddingHorizontal: space.lg,
paddingVertical: space.md + 2,
borderRadius: radius.md,
backgroundColor: C.surface,
color: C.text,
fontSize: 16,
borderWidth: 1,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
},
listContent: { paddingHorizontal: space.lg, paddingBottom: space.lg },
row: {
flexDirection: "row",
alignItems: "center",
gap: 12,
paddingVertical: 14,
paddingHorizontal: 16,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: C.border,
gap: space.md,
paddingVertical: space.md + 2,
paddingHorizontal: space.lg,
},
checkbox: { width: 22, height: 22, borderRadius: 11, borderWidth: 2, borderColor: C.muted },
title: { color: C.text, fontSize: 16 },
meta: { color: C.muted, fontSize: 13, marginTop: 2 },
empty: { color: C.muted, textAlign: "center", marginTop: 48 },
checkbox: { width: 21, height: 21, borderRadius: 7, borderWidth: 1.5, borderColor: C.muted },
title: { ...type.row, color: C.text },
meta: { ...type.meta, color: C.muted, marginTop: 2 },
});

97
app/src/app/projects.tsx Normal file
View File

@@ -0,0 +1,97 @@
import { useRouter } from "expo-router";
import { useState } from "react";
import { FlatList, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
import Icon from "../components/Icon";
import { cardEdges, Empty, Pill, Separator } from "../components/ui";
import { haptic } from "../lib/haptics";
import { activeProjects, createProject, openTaskCount } from "../lib/store";
import { C, radius, space, type } from "../lib/theme";
import { useStore } from "../lib/useStore";
export default function Projects() {
const router = useRouter();
const store = useStore();
const [draft, setDraft] = useState("");
const projects = activeProjects(store);
const add = () => {
const name = draft.trim();
if (!name) return;
setDraft("");
haptic.success();
createProject({ name });
};
return (
<View style={s.screen}>
<TextInput
style={s.capture}
placeholder="New project…"
placeholderTextColor={C.muted}
value={draft}
onChangeText={setDraft}
onSubmitEditing={add}
returnKeyType="done"
/>
<FlatList
data={projects}
keyExtractor={(p) => p.id}
renderItem={({ item, index }) => {
const open = openTaskCount(store, item.id);
return (
<Pressable
style={({ pressed }) => [
s.row,
...cardEdges(index, projects.length),
pressed && { backgroundColor: C.surface2 },
]}
onPress={() => router.push(`/project/${item.id}`)}
>
<View style={{ flex: 1 }}>
<Text style={s.title} numberOfLines={1}>
{item.name}
</Text>
<Text style={s.meta}>
{open === 0 ? "Nothing open" : `${open} open`}
</Text>
</View>
{item.status !== "active" && <Pill label={item.status} />}
<Icon name="chevron" size={16} color={C.muted} />
</Pressable>
);
}}
ItemSeparatorComponent={() => <Separator inset={space.lg} />}
ListEmptyComponent={<Empty>No projects yet. Name one above.</Empty>}
contentContainerStyle={s.content}
showsVerticalScrollIndicator={false}
/>
</View>
);
}
const s = StyleSheet.create({
screen: { flex: 1, backgroundColor: C.bg },
content: { paddingHorizontal: space.lg, paddingBottom: 40 },
capture: {
marginHorizontal: space.lg,
marginTop: space.md,
marginBottom: space.lg,
paddingHorizontal: space.lg,
paddingVertical: space.md + 2,
borderRadius: radius.md,
backgroundColor: C.surface,
color: C.text,
fontSize: 16,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
},
row: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingVertical: space.md + 2,
paddingHorizontal: space.lg,
},
title: { ...type.row, color: C.text },
meta: { ...type.meta, color: C.muted, marginTop: 2 },
});

210
app/src/app/review.tsx Normal file
View File

@@ -0,0 +1,210 @@
// Weekly review — GTD's keystone habit. One pass, one decision per row:
// each row has exactly three quick actions (do next / someday / trash) plus
// done on the checkbox, so nothing needs a trip through the edit modal.
import { useRouter } from "expo-router";
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
import Icon from "../components/Icon";
import { Button, Card, Empty, SectionHeader } from "../components/ui";
import { friendlyDate } from "../lib/dates";
import { haptic } from "../lib/haptics";
import { PRIORITY_COLOR } from "../lib/priority";
import { daysSince, markReviewed, useLastReview } from "../lib/review";
import { reviewBuckets, trashTask, updateTask } from "../lib/store";
import { C, radius, space, type } from "../lib/theme";
import { useStore } from "../lib/useStore";
import type { Task } from "../lib/types";
function ReviewRow({
task,
showDefer,
last,
}: {
task: Task;
showDefer?: boolean;
/** The card already draws the bottom edge — don't double it up. */
last?: boolean;
}) {
const router = useRouter();
const act = (fn: () => void) => () => {
haptic.select();
fn();
};
return (
<View style={[s.row, last && s.rowLast]}>
<Pressable
style={s.check}
hitSlop={8}
onPress={act(() => {
haptic.success();
updateTask(task.id, { status: "done" });
})}
>
<View style={[s.checkbox, { borderColor: PRIORITY_COLOR[task.priority] }]} />
</Pressable>
<Pressable style={{ flex: 1 }} onPress={() => router.push(`/task/${task.id}`)}>
<Text style={s.title} numberOfLines={2}>
{task.title}
</Text>
<Text style={s.meta}>
{[
task.status,
task.waiting_for && `→ ${task.waiting_for}`,
showDefer && task.defer_date && `resurfaces ${friendlyDate(task.defer_date)}`,
]
.filter(Boolean)
.join(" · ")}
</Text>
</Pressable>
{task.status !== "next" && (
<Pressable
style={({ pressed }) => [s.action, pressed && s.actionPressed]}
hitSlop={6}
onPress={act(() => updateTask(task.id, { status: "next" }))}
>
<Icon name="next" size={14} color={C.accent} />
</Pressable>
)}
{task.status !== "someday" && (
<Pressable
style={({ pressed }) => [s.action, pressed && s.actionPressed]}
hitSlop={6}
onPress={act(() => updateTask(task.id, { status: "someday" }))}
>
<Icon name="someday" size={14} color={C.textSecondary} bg={C.surface} />
</Pressable>
)}
<Pressable
style={({ pressed }) => [s.action, pressed && s.actionPressed]}
hitSlop={6}
onPress={act(() => trashTask(task.id))}
>
<Text style={s.dropText}>Drop</Text>
</Pressable>
</View>
);
}
function Section({ title, hint, tasks, showDefer }: { title: string; hint: string; tasks: Task[]; showDefer?: boolean }) {
if (tasks.length === 0) return null;
return (
<View>
<SectionHeader>
{title} ({tasks.length})
</SectionHeader>
<Text style={s.sectionHint}>{hint}</Text>
<Card>
{tasks.map((t, i) => (
<ReviewRow key={t.id} task={t} showDefer={showDefer} last={i === tasks.length - 1} />
))}
</Card>
</View>
);
}
export default function Review() {
const router = useRouter();
const store = useStore();
const buckets = reviewBuckets(store);
const [last, reload] = useLastReview();
const days = daysSince(last);
const empty =
!buckets.overdue.length &&
!buckets.staleNext.length &&
!buckets.agingWaiting.length &&
!buckets.someday.length &&
!buckets.deferred.length &&
!buckets.stuckProjects.length;
return (
<ScrollView style={{ flex: 1, backgroundColor: C.bg }} contentContainerStyle={s.content}>
<Text style={s.lastReview}>
{last ? (days === 0 ? "Last review: today" : `Last review: ${days}d ago`) : "First review — welcome."}
</Text>
<Section title="Overdue" hint="Reschedule, do, or let go." tasks={buckets.overdue} />
<Section title="Stalled" hint="Next actions untouched for 2+ weeks — still the real next step?" tasks={buckets.staleNext} />
<Section title="Waiting too long" hint="A week without movement — time to nudge?" tasks={buckets.agingWaiting} />
<Section title="Someday sweep" hint="Promote what's ripe, trash what's dead." tasks={buckets.someday} />
<Section title="Deferred" hint="Hidden from lists — just so you know they're coming." tasks={buckets.deferred} showDefer />
{buckets.stuckProjects.length > 0 && (
<View>
<SectionHeader>Stuck projects ({buckets.stuckProjects.length})</SectionHeader>
<Text style={s.sectionHint}>Active, but no next action — decide the next step or park them.</Text>
<Card>
{buckets.stuckProjects.map((p, i) => (
<Pressable
key={p.id}
style={({ pressed }) => [
s.row,
i === buckets.stuckProjects.length - 1 && s.rowLast,
pressed && { backgroundColor: C.surface2 },
]}
onPress={() => router.push(`/project/${p.id}`)}
>
<Text style={[s.title, { flex: 1 }]}>{p.name}</Text>
<Icon name="chevron" size={16} color={C.muted} />
</Pressable>
))}
</Card>
</View>
)}
{empty && <Empty>All clear. Nothing needs a decision.</Empty>}
<Button
title="Mark review complete"
onPress={async () => {
haptic.success();
await markReviewed();
reload();
router.back();
}}
/>
<View style={s.archiveRow}>
<Pressable onPress={() => router.push("/list/done")}>
<Text style={s.archiveLink}>Done</Text>
</Pressable>
<Text style={s.archiveDot}>·</Text>
<Pressable onPress={() => router.push("/list/trashed")}>
<Text style={s.archiveLink}>Trash</Text>
</Pressable>
</View>
</ScrollView>
);
}
const s = StyleSheet.create({
content: { padding: space.lg, paddingBottom: 48 },
lastReview: { ...type.meta, color: C.textSecondary, marginBottom: space.xs },
sectionHint: { ...type.meta, color: C.muted, paddingHorizontal: space.xs, marginBottom: space.sm },
row: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingVertical: space.md,
paddingHorizontal: space.lg,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: C.separator,
backgroundColor: C.surface,
},
rowLast: { borderBottomWidth: 0 },
check: { paddingRight: 2 },
checkbox: { width: 21, height: 21, borderRadius: 7, borderWidth: 1.5 },
title: { ...type.body, color: C.text },
meta: { ...type.meta, fontSize: 12, color: C.muted, marginTop: 2 },
action: {
minWidth: 30,
height: 28,
paddingHorizontal: space.sm,
borderRadius: radius.sm,
alignItems: "center",
justifyContent: "center",
},
actionPressed: { backgroundColor: C.surface2 },
dropText: { ...type.meta, color: C.danger, fontWeight: "500" },
archiveRow: { flexDirection: "row", justifyContent: "center", gap: space.sm, marginTop: space.xs },
archiveLink: { ...type.meta, color: C.textSecondary, padding: space.sm },
archiveDot: { color: C.muted, alignSelf: "center" },
});

View File

@@ -1,10 +1,12 @@
import * as Application from "expo-application";
import { useRouter } from "expo-router";
import { useEffect, useState } from "react";
import { ScrollView, Text } from "react-native";
import { ScrollView, StyleSheet, Text } from "react-native";
import { Button, Field } from "../components/ui";
import { api } from "../lib/api";
import { DEFAULT_URL, getConfig, setConfig } from "../lib/config";
import { C } from "../lib/theme";
import { sync } from "../lib/store";
import { C, space, type } from "../lib/theme";
export default function Settings() {
const router = useRouter();
@@ -22,7 +24,8 @@ export default function Settings() {
const save = async () => {
await setConfig(url, token);
try {
await api.tasks.list({ status: "inbox" });
await api.tasks.list({ status: "next" });
void sync();
router.back();
} catch (e) {
setStatus(`Connection failed: ${e instanceof Error ? e.message : e}`);
@@ -30,7 +33,7 @@ export default function Settings() {
};
return (
<ScrollView style={{ flex: 1, backgroundColor: C.bg }} contentContainerStyle={{ padding: 16 }}>
<ScrollView style={{ flex: 1, backgroundColor: C.bg }} contentContainerStyle={s.content}>
<Field label="Server" value={url} onChangeText={setUrl} autoCapitalize="none" autoCorrect={false} />
<Field
label="API token"
@@ -41,7 +44,15 @@ export default function Settings() {
secureTextEntry
/>
<Button title="Save & test" onPress={save} />
{status && <Text style={{ color: C.danger }}>{status}</Text>}
{status && <Text style={s.error}>{status}</Text>}
{/* CI stamps versionName from the release tag — confirms which build Obtainium installed. */}
<Text style={s.version}>GTD v{Application.nativeApplicationVersion ?? "dev"}</Text>
</ScrollView>
);
}
const s = StyleSheet.create({
content: { padding: space.lg },
error: { ...type.meta, color: C.danger, marginTop: space.xs },
version: { ...type.meta, color: C.muted, textAlign: "center", marginTop: space.xxl },
});

View File

@@ -1,109 +1,94 @@
import { useLocalSearchParams, useRouter } from "expo-router";
import { useEffect, useState } from "react";
import { ScrollView, Text } from "react-native";
import { Button, Chips, Field } from "../../components/ui";
import { api } from "../../lib/api";
import { C } from "../../lib/theme";
import type { Project, Task, TaskStatus } from "../../lib/types";
import { useState } from "react";
import { ScrollView, StyleSheet, Text } from "react-native";
import TaskForm, { CAPTURE_BOXES, type TaskDraft } from "../../components/TaskForm";
import { Button, Empty } from "../../components/ui";
import { haptic } from "../../lib/haptics";
import { trashTask, updateTask } from "../../lib/store";
import { C, space, type } from "../../lib/theme";
import { useStore } from "../../lib/useStore";
import type { Task, TaskStatus } from "../../lib/types";
const STATUSES: TaskStatus[] = ["inbox", "next", "waiting", "scheduled", "someday", "done"];
// Clarify can also finish a task outright; capture never needs to.
const BOXES: TaskStatus[] = [...CAPTURE_BOXES, "done"];
const toDraft = (t: Task): TaskDraft => ({
title: t.title,
notes: t.notes,
status: t.status,
project_id: t.project_id,
context: t.context,
waiting_for: t.waiting_for,
due_date: t.due_date,
defer_date: t.defer_date,
estimate_min: t.estimate_min,
repeat: t.repeat,
priority: t.priority,
});
export default function TaskDetail() {
const { id } = useLocalSearchParams<{ id: string }>();
const router = useRouter();
const [task, setTask] = useState<Task | null>(null);
const [projects, setProjects] = useState<Project[]>([]);
const [error, setError] = useState<string | null>(null);
const store = useStore();
const original = store.tasks.find((t) => t.id === id);
// Draft is local to the screen; nothing is written until Save.
const [draft, setDraft] = useState<TaskDraft | null>(original ? toDraft(original) : null);
useEffect(() => {
Promise.all([api.tasks.get(id), api.projects.list()])
.then(([t, ps]) => {
setTask(t);
setProjects(ps.filter((p) => p.status === "active" || p.id === t.project_id));
})
.catch((e) => setError(e instanceof Error ? e.message : String(e)));
}, [id]);
if (!original || !draft) return <Empty>Task not found.</Empty>;
if (error) return <Text style={{ color: C.danger, margin: 16 }}>{error}</Text>;
if (!task) return <Text style={{ color: C.muted, margin: 16 }}>Loading…</Text>;
const set = (patch: Partial<Task>) => setTask({ ...task, ...patch });
const save = async () => {
try {
await api.tasks.update(task.id, {
title: task.title,
notes: task.notes,
status: task.status,
project_id: task.project_id,
context: task.context,
waiting_for: task.waiting_for,
due_date: task.due_date,
defer_date: task.defer_date,
});
const save = () => {
updateTask(original.id, { ...draft, priority: draft.priority ?? 3 });
haptic.success();
router.back();
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
};
if (original.status === "trashed") {
return (
<ScrollView style={{ flex: 1, backgroundColor: C.bg }} contentContainerStyle={s.content}>
<Text style={s.trashedTitle}>{original.title}</Text>
<Text style={s.trashedMeta}>In the trash.</Text>
<Button
title="Restore to Next"
onPress={() => {
haptic.success();
updateTask(original.id, { status: "next" });
router.back();
}}
/>
</ScrollView>
);
}
};
const trash = async () => {
await api.tasks.trash(task.id);
router.back();
};
const projectOptions = ["none", ...projects.map((p) => p.id)];
const projectLabels = Object.fromEntries([["none", "None"], ...projects.map((p) => [p.id, p.name])]);
return (
<ScrollView style={{ flex: 1, backgroundColor: C.bg }} contentContainerStyle={{ padding: 16 }}>
<Field label="Title" value={task.title} onChangeText={(v) => set({ title: v })} />
<Chips label="List" options={STATUSES} value={task.status} onChange={(status) => set({ status })} />
<Chips
label="Project"
options={projectOptions}
labels={projectLabels}
value={task.project_id ?? "none"}
onChange={(v) => set({ project_id: v === "none" ? null : v })}
<ScrollView
style={{ flex: 1, backgroundColor: C.bg }}
contentContainerStyle={s.content}
keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
>
<TaskForm
value={draft}
onChange={(patch) => setDraft({ ...draft, ...patch })}
boxes={BOXES}
showDefer
onSubmitTitle={save}
/>
<Field
label="Context"
value={task.context ?? ""}
onChangeText={(v) => set({ context: v || null })}
placeholder="@home, @computer, @errands…"
autoCapitalize="none"
<Button title="Save" onPress={save} style={s.save} />
<Button
title="Delete"
danger
onPress={() => {
trashTask(original.id);
router.back();
}}
/>
{task.status === "waiting" && (
<Field
label="Waiting for"
value={task.waiting_for ?? ""}
onChangeText={(v) => set({ waiting_for: v || null })}
placeholder="Who or what?"
/>
)}
<Field
label="Due date"
value={task.due_date ?? ""}
onChangeText={(v) => set({ due_date: v || null })}
placeholder="YYYY-MM-DD"
autoCapitalize="none"
/>
<Field
label="Defer until"
value={task.defer_date ?? ""}
onChangeText={(v) => set({ defer_date: v || null })}
placeholder="YYYY-MM-DD"
autoCapitalize="none"
/>
<Field
label="Notes"
value={task.notes}
onChangeText={(v) => set({ notes: v })}
multiline
style={{ minHeight: 80, textAlignVertical: "top" }}
/>
<Button title="Save" onPress={save} />
<Button title="Delete" onPress={trash} danger />
</ScrollView>
);
}
const s = StyleSheet.create({
content: { padding: space.lg, paddingBottom: space.xxl },
save: { marginTop: space.xl },
trashedTitle: { ...type.title, fontSize: 22, color: C.text, marginBottom: space.xs },
trashedMeta: { ...type.body, color: C.muted, marginBottom: space.xl },
});

44
app/src/app/today.tsx Normal file
View File

@@ -0,0 +1,44 @@
import { SectionList, StyleSheet, View } from "react-native";
import TaskRow, { TaskSeparator } from "../components/TaskRow";
import { cardEdges, Empty, SectionHeader } from "../components/ui";
import { todayTasks } from "../lib/store";
import { C, space } from "../lib/theme";
import { useStore } from "../lib/useStore";
export default function Today() {
const store = useStore();
const { overdue, today } = todayTasks(store);
const sections = [
...(overdue.length ? [{ title: "Overdue", data: overdue, color: C.danger }] : []),
{ title: "Today", data: today, color: C.textSecondary },
];
const empty = overdue.length === 0 && today.length === 0;
return (
<SectionList
style={s.screen}
sections={sections}
keyExtractor={(t) => t.id}
// Each section is its own rounded card, so the first and last rows in a
// section round their outer corners.
renderItem={({ item, index, section }) => (
<View style={cardEdges(index, section.data.length)}>
<TaskRow task={item} showStatus />
</View>
)}
renderSectionHeader={({ section }) => (
<SectionHeader tone={section.color}>{section.title}</SectionHeader>
)}
ItemSeparatorComponent={TaskSeparator}
ListFooterComponent={empty ? <Empty>Nothing due. Clear runway.</Empty> : null}
contentContainerStyle={s.content}
stickySectionHeadersEnabled={false}
showsVerticalScrollIndicator={false}
/>
);
}
const s = StyleSheet.create({
screen: { flex: 1, backgroundColor: C.bg },
content: { paddingHorizontal: space.lg, paddingBottom: 40 },
});

View File

@@ -0,0 +1,126 @@
// The attribute bar: one wrapping row of chips that doubles as the task's
// summary and as the entry point to every optional field.
//
// The old form stacked seven labelled control groups down the screen, so
// capturing "call Sam" meant scrolling past a calendar, a repeat picker and an
// estimate picker to reach the save button. Here each field collapses to a
// single chip: unset chips read as a quiet placeholder, set chips show their
// value in the accent. Exactly one panel is open at a time, so the screen
// never grows past roughly a phone height.
import { useState } from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { haptic } from "../lib/haptics";
import { C, radius, space, type } from "../lib/theme";
import Icon, { type IconName } from "./Icon";
export type Attr = {
key: string;
icon: IconName;
/** Chip label while the field is unset. */
placeholder: string;
/** Chip label once set — this is what makes the bar readable as a summary. */
value?: string | null;
/** Chip accent when set. Defaults to the app accent. */
tone?: string;
/** Revealed under the bar when the chip is tapped. */
panel: React.ReactNode;
/** Offered as "Clear" in the open panel's header. Omit for required fields. */
onClear?: () => void;
};
export default function AttrBar({ attrs }: { attrs: Attr[] }) {
const [open, setOpen] = useState<string | null>(null);
const active = attrs.find((a) => a.key === open) ?? null;
return (
<View>
<View style={s.row}>
{attrs.map((a) => {
const set = !!a.value;
const tone = a.tone ?? C.accent;
const isOpen = a.key === open;
return (
<Pressable
key={a.key}
onPress={() => {
haptic.tap();
setOpen(isOpen ? null : a.key);
}}
style={({ pressed }) => [
s.chip,
set && { borderColor: tone, backgroundColor: `${tone}14` },
isOpen && { borderColor: tone, backgroundColor: `${tone}22` },
pressed && { opacity: 0.7 },
]}
>
<Icon name={a.icon} size={15} color={set || isOpen ? tone : C.muted} bg={C.bg} />
<Text style={[s.chipText, (set || isOpen) && { color: tone, fontWeight: "600" }]}>
{a.value || a.placeholder}
</Text>
</Pressable>
);
})}
</View>
{!!active && (
<View style={s.panel}>
<View style={s.panelHead}>
<Text style={s.panelTitle}>{active.placeholder}</Text>
{!!active.onClear && !!active.value && (
<Pressable
onPress={() => {
haptic.select();
active.onClear?.();
}}
hitSlop={8}
style={({ pressed }) => pressed && { opacity: 0.6 }}
>
<Text style={s.clear}>Clear</Text>
</Pressable>
)}
<Pressable onPress={() => setOpen(null)} hitSlop={10} style={({ pressed }) => pressed && { opacity: 0.6 }}>
<Icon name="close" size={17} color={C.muted} />
</Pressable>
</View>
{active.panel}
</View>
)}
</View>
);
}
const s = StyleSheet.create({
row: { flexDirection: "row", flexWrap: "wrap", gap: space.sm },
chip: {
flexDirection: "row",
alignItems: "center",
gap: 6,
paddingVertical: space.sm - 1,
paddingLeft: space.md - 2,
paddingRight: space.lg - 2,
borderRadius: radius.pill,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
backgroundColor: C.surface,
},
chipText: { ...type.chip, color: C.textSecondary },
panel: {
marginTop: space.md,
backgroundColor: C.surface,
borderRadius: radius.lg,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
paddingHorizontal: space.lg,
paddingBottom: space.md,
},
panelHead: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingTop: space.md,
paddingBottom: space.xs,
},
panelTitle: { ...type.section, color: C.textSecondary, flex: 1 },
clear: { ...type.meta, color: C.accent, fontWeight: "600" },
});

View File

@@ -0,0 +1,194 @@
// 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 { friendlyDate, fromIso, toIso as iso, todayIso } from "../lib/dates";
import { C, radius, space, type } from "../lib/theme";
import { ChipRow, OptionChip, SectionHeader } from "./ui";
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 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 today = todayIso();
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 === today;
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.muted, opacity: 0.45 },
selected && { color: C.onAccent, 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={label ? { marginBottom: space.lg } : undefined}>
{!!label && (
<View style={s.labelRow}>
<SectionHeader>{label}</SectionHeader>
{value != null && <Text style={s.chosen}>{friendlyDate(value)}</Text>}
</View>
)}
<ChipRow>
{quick.map((q) => (
<OptionChip
key={q.label}
label={q.label}
active={value === q.v}
onPress={() => {
haptic.select();
onChange(value === q.v && clearable ? null : q.v);
}}
/>
))}
<OptionChip
label={value && !quick.some((q) => q.v === value) ? friendlyDate(value) : "Pick a date…"}
active={open}
onPress={() => {
haptic.select();
setOpen(!open);
}}
/>
{/* Standalone only — inside an AttrBar panel the header owns "Clear". */}
{clearable && !!label && value != null && (
<OptionChip label="Clear" onPress={() => {
haptic.tap();
onChange(null);
}} />
)}
</ChipRow>
{open && (
<Calendar
value={value}
onPick={(v) => {
onChange(v);
setOpen(false);
}}
/>
)}
</View>
);
}
const s = StyleSheet.create({
labelRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "center" },
chosen: { ...type.chip, color: C.accent, fontWeight: "600" },
calendar: {
marginTop: space.md,
backgroundColor: C.surface,
borderRadius: radius.lg,
borderWidth: 1,
borderColor: C.border,
padding: space.md,
},
calHead: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", marginBottom: space.sm },
calTitle: { color: C.text, fontSize: 16, fontWeight: "600", letterSpacing: -0.2 },
arrow: { paddingHorizontal: 14, paddingVertical: 4 },
arrowText: { color: C.accent, fontSize: 24, fontWeight: "500" },
week: { flexDirection: "row" },
weekday: { flex: 1, textAlign: "center", color: C.muted, fontSize: 11, fontWeight: "600", letterSpacing: 0.4, paddingVertical: 6 },
day: {
flex: 1,
aspectRatio: 1.15,
alignItems: "center",
justifyContent: "center",
borderRadius: 999,
margin: 1,
},
daySelected: { backgroundColor: C.accent },
dayToday: { backgroundColor: C.accentSoft },
dayText: { color: C.text, fontSize: 15 },
});

View File

@@ -0,0 +1,41 @@
// Preset estimate chips — one tap beats a numeric keyboard. A non-preset
// value (from quick-add, e.g. ~25m) shows up as its own chip so it's never
// invisible or lost.
import { View } from "react-native";
import { haptic } from "../lib/haptics";
import { formatEstimate } from "../lib/priority";
import { space } from "../lib/theme";
import { ChipRow, OptionChip, SectionHeader } from "./ui";
const PRESETS = [15, 30, 45, 60, 90, 120];
/** Omit `label` when the surrounding panel already titles the group. */
export default function EstimateChips({
value,
onChange,
label,
}: {
value: number | null;
onChange: (v: number | null) => void;
label?: string;
}) {
const options = value && !PRESETS.includes(value) ? [...PRESETS, value].sort((a, b) => a - b) : PRESETS;
return (
<View style={label ? { marginBottom: space.lg } : undefined}>
{!!label && <SectionHeader>{label}</SectionHeader>}
<ChipRow>
{options.map((m) => (
<OptionChip
key={m}
label={formatEstimate(m) ?? ""}
active={value === m}
onPress={() => {
haptic.select();
onChange(value === m ? null : m);
}}
/>
))}
</ChipRow>
</View>
);
}

322
app/src/components/Icon.tsx Normal file
View File

@@ -0,0 +1,322 @@
// A tiny geometric icon set drawn from plain Views.
//
// The app ships no vector-icon dependency and emoji render differently on
// every platform (and can't take the accent colour), so these are built from
// borders and rectangles instead: monochrome, tintable, pixel-identical on
// Android and web, and zero bytes of new dependency.
import { StyleSheet, View } from "react-native";
import { C } from "../lib/theme";
export type IconName =
| "today"
| "next"
| "waiting"
| "someday"
| "projects"
| "review"
| "settings"
| "flag"
| "repeat"
| "tag"
| "plus"
| "close"
| "chevron";
type Props = {
name: IconName;
size?: number;
color?: string;
/** Used to carve the crescent out of the "someday" moon. */
bg?: string;
};
export default function Icon({ name, size = 22, color = C.textSecondary, bg = C.bg }: Props) {
const box = { width: size, height: size };
const w = 1.7; // one consistent stroke weight across the whole set
switch (name) {
case "today":
return (
<View style={[box, s.center]}>
<View
style={{
width: size * 0.86,
height: size * 0.82,
borderWidth: w,
borderColor: color,
borderRadius: 5,
overflow: "hidden",
}}
>
<View style={{ height: size * 0.2, backgroundColor: color }} />
<View style={[s.center, { flex: 1 }]}>
<View
style={{ width: w * 2, height: w * 2, borderRadius: 999, backgroundColor: color }}
/>
</View>
</View>
</View>
);
case "next":
return (
<View style={[box, s.center]}>
<View
style={{
width: 0,
height: 0,
borderTopWidth: size * 0.32,
borderBottomWidth: size * 0.32,
borderLeftWidth: size * 0.52,
borderTopColor: "transparent",
borderBottomColor: "transparent",
borderLeftColor: color,
marginLeft: size * 0.12,
}}
/>
</View>
);
case "waiting":
return (
<View style={[box, s.center]}>
<View
style={{
width: size * 0.84,
height: size * 0.84,
borderRadius: 999,
borderWidth: w,
borderColor: color,
}}
>
{/* hour hand, then minute hand — anchored at the dial centre */}
<View
style={{
position: "absolute",
left: size * 0.42 - w / 2,
top: size * 0.2,
width: w,
height: size * 0.22,
backgroundColor: color,
borderRadius: w,
}}
/>
<View
style={{
position: "absolute",
left: size * 0.42 - w / 2,
top: size * 0.42 - w / 2,
width: size * 0.24,
height: w,
backgroundColor: color,
borderRadius: w,
}}
/>
</View>
</View>
);
case "someday":
return (
<View style={[box, s.center]}>
<View
style={{
width: size * 0.84,
height: size * 0.84,
borderRadius: 999,
backgroundColor: color,
overflow: "hidden",
}}
>
<View
style={{
position: "absolute",
right: -size * 0.22,
top: -size * 0.26,
width: size * 0.84,
height: size * 0.84,
borderRadius: 999,
backgroundColor: bg,
}}
/>
</View>
</View>
);
case "projects":
return (
<View style={[box, s.center]}>
<View style={{ width: size * 0.86, height: size * 0.78 }}>
<View
style={{
width: size * 0.4,
height: size * 0.16,
borderTopLeftRadius: 3,
borderTopRightRadius: 3,
backgroundColor: color,
}}
/>
<View
style={{
flex: 1,
borderWidth: w,
borderColor: color,
borderRadius: 5,
borderTopLeftRadius: 0,
}}
/>
</View>
</View>
);
case "review":
return (
<View style={[box, s.center]}>
{/* an open ring plus an arrowhead reads as "cycle" without an SVG path */}
<View
style={{
width: size * 0.82,
height: size * 0.82,
borderRadius: 999,
borderWidth: w,
borderColor: color,
borderTopColor: "transparent",
transform: [{ rotate: "45deg" }],
}}
/>
<View
style={{
position: "absolute",
top: size * 0.06,
right: size * 0.12,
width: 0,
height: 0,
borderLeftWidth: size * 0.16,
borderRightWidth: size * 0.16,
borderBottomWidth: size * 0.2,
borderLeftColor: "transparent",
borderRightColor: "transparent",
borderBottomColor: color,
transform: [{ rotate: "115deg" }],
}}
/>
</View>
);
case "settings":
// Sliders, not a cog: three strokes with offset knobs stays legible at 20px.
return (
<View style={[box, s.center]}>
<View style={{ width: size * 0.88, gap: size * 0.16 }}>
{[0.62, 0.3, 0.48].map((knob, i) => (
<View key={i} style={s.sliderRow}>
<View style={{ flex: 1, height: w, backgroundColor: color, borderRadius: w }} />
<View
style={{
position: "absolute",
left: `${knob * 100}%`,
width: w * 3,
height: w * 3,
marginLeft: -w * 1.5,
marginTop: -w,
borderRadius: 999,
borderWidth: w,
borderColor: color,
backgroundColor: bg,
}}
/>
</View>
))}
</View>
</View>
);
case "flag":
return (
<View style={box}>
{/* Pole plus a pennant — reads as a priority flag at 20px where a
detailed banner outline would smear into a blob. */}
<View style={{ position: "absolute", left: size * 0.26, top: size * 0.12, width: w, height: size * 0.76, borderRadius: 1, backgroundColor: color }} />
<View
style={{
position: "absolute",
left: size * 0.26 + w,
top: size * 0.14,
width: size * 0.44,
height: size * 0.34,
borderTopRightRadius: 2,
borderBottomRightRadius: 2,
backgroundColor: color,
}}
/>
</View>
);
case "repeat":
return (
<View style={box}>
{/* Two offset bars with opposing arrowheads: a loop, without the
anti-aliasing mush a thin circular arc gets at this size. */}
<View style={{ position: "absolute", left: size * 0.2, top: size * 0.3, width: size * 0.5, height: w, backgroundColor: color }} />
<View style={{ position: "absolute", left: size * 0.62, top: size * 0.3 - size * 0.09 + w / 2, width: size * 0.18, height: size * 0.18, borderRightWidth: w, borderTopWidth: w, borderColor: color, transform: [{ rotate: "45deg" }] }} />
<View style={{ position: "absolute", left: size * 0.3, top: size * 0.66, width: size * 0.5, height: w, backgroundColor: color }} />
<View style={{ position: "absolute", left: size * 0.2, top: size * 0.66 - size * 0.09 + w / 2, width: size * 0.18, height: size * 0.18, borderLeftWidth: w, borderBottomWidth: w, borderColor: color, transform: [{ rotate: "45deg" }] }} />
</View>
);
case "tag":
return (
<View style={[box, s.center]}>
<View
style={{
width: size * 0.6,
height: size * 0.6,
borderWidth: w,
borderColor: color,
borderRadius: 3,
transform: [{ rotate: "45deg" }],
}}
/>
<View style={{ position: "absolute", left: size * 0.3, top: size * 0.3, width: w + 0.6, height: w + 0.6, borderRadius: 999, backgroundColor: color }} />
</View>
);
case "close":
return (
<View style={[box, s.center]}>
<View style={{ position: "absolute", width: size * 0.6, height: w, borderRadius: 2, backgroundColor: color, transform: [{ rotate: "45deg" }] }} />
<View style={{ position: "absolute", width: size * 0.6, height: w, borderRadius: 2, backgroundColor: color, transform: [{ rotate: "-45deg" }] }} />
</View>
);
case "plus":
return (
<View style={[box, s.center]}>
<View style={{ position: "absolute", width: size * 0.7, height: w + 0.5, borderRadius: 2, backgroundColor: color }} />
<View style={{ position: "absolute", width: w + 0.5, height: size * 0.7, borderRadius: 2, backgroundColor: color }} />
</View>
);
case "chevron":
return (
<View style={[box, s.center]}>
<View
style={{
width: size * 0.34,
height: size * 0.34,
borderRightWidth: w,
borderTopWidth: w,
borderColor: color,
transform: [{ rotate: "45deg" }],
marginLeft: -size * 0.06,
}}
/>
</View>
);
}
}
const s = StyleSheet.create({
center: { alignItems: "center", justifyContent: "center" },
sliderRow: { justifyContent: "center" },
});

View File

@@ -0,0 +1,43 @@
import { StyleSheet, View } from "react-native";
import { haptic } from "../lib/haptics";
import { PRIORITIES, PRIORITY_COLOR, PRIORITY_LABEL, PRIORITY_TINT } from "../lib/priority";
import { C, space } from "../lib/theme";
import type { Task } from "../lib/types";
import { ChipRow, OptionChip, SectionHeader } from "./ui";
/** Omit `label` when the surrounding panel already titles the group. */
export default function PriorityChips({
value,
onChange,
label,
}: {
value: Task["priority"] | null;
onChange: (p: Task["priority"]) => void;
label?: string;
}) {
return (
<View style={label ? { marginBottom: space.lg } : undefined}>
{!!label && <SectionHeader>{label}</SectionHeader>}
<ChipRow>
{PRIORITIES.map((p) => (
<OptionChip
key={p}
label={PRIORITY_LABEL[p]}
active={value === p}
tone={PRIORITY_COLOR[p]}
tint={PRIORITY_TINT[p]}
leading={<View style={[s.flag, { backgroundColor: PRIORITY_COLOR[p] }]} />}
onPress={() => {
haptic.select();
onChange(p);
}}
/>
))}
</ChipRow>
</View>
);
}
const s = StyleSheet.create({
flag: { width: 9, height: 9, borderRadius: 999, backgroundColor: C.muted },
});

View File

@@ -0,0 +1,287 @@
// The task editor, shared by capture and clarify.
//
// Both screens are the same object seen at two moments, so they get the same
// shape: a title/notes card, then one wrapping row of attribute chips. Keeping
// it in one file means a change to how "When" or "Repeat" is picked lands in
// both places at once, and the two screens can never drift into looking like
// different apps.
import { StyleSheet, Text, TextInput, View } from "react-native";
import AttrBar, { type Attr } from "./AttrBar";
import DateField from "./DateField";
import EstimateChips from "./EstimateChips";
import PriorityChips from "./PriorityChips";
import { Chips, Separator } from "./ui";
import { friendlyDate } from "../lib/dates";
import { haptic } from "../lib/haptics";
import { formatEstimate, PRIORITY_COLOR, PRIORITY_LABEL } from "../lib/priority";
import { REPEAT_LABEL, REPEATS } from "../lib/repeat";
import { activeProjects, knownContexts } from "../lib/store";
import { C, radius, space, type } from "../lib/theme";
import { useStore } from "../lib/useStore";
import type { Task, TaskStatus } from "../lib/types";
/** Everything a task screen edits. Priority is nullable while undecided. */
export type TaskDraft = Pick<
Task,
"title" | "notes" | "status" | "project_id" | "context" | "waiting_for" | "due_date" | "defer_date" | "estimate_min" | "repeat"
> & { priority: Task["priority"] | null };
export const BOX_LABEL: Record<string, string> = {
next: "Next up",
waiting: "Waiting",
someday: "Someday",
done: "Done",
};
/** The boxes a task can be filed into by hand. */
export const CAPTURE_BOXES: TaskStatus[] = ["next", "waiting", "someday"];
export const emptyDraft = (): TaskDraft => ({
title: "",
notes: "",
status: "next",
project_id: null,
context: null,
waiting_for: null,
due_date: null,
defer_date: null,
estimate_min: null,
repeat: null,
priority: null,
});
export default function TaskForm({
value: d,
onChange,
boxes = CAPTURE_BOXES,
showDefer = false,
autoFocus = false,
onSubmitTitle,
hint,
}: {
value: TaskDraft;
onChange: (patch: Partial<TaskDraft>) => void;
boxes?: TaskStatus[];
/** Clarify offers a start date; capture keeps the bar short. */
showDefer?: boolean;
autoFocus?: boolean;
onSubmitTitle?: () => void;
hint?: string;
}) {
const store = useStore();
// Keep a project that has since been archived visible, or editing an old task
// would silently drop it.
const projects = activeProjects(store).filter((p) => p.status === "active" || p.id === d.project_id);
const contexts = knownContexts(store);
const projectName = projects.find((p) => p.id === d.project_id)?.name ?? null;
const attrs: Attr[] = [
{
key: "when",
icon: "today",
placeholder: "When",
value: d.due_date ? friendlyDate(d.due_date) : null,
panel: <DateField value={d.due_date} onChange={(due_date) => onChange({ due_date })} clearable />,
onClear: () => onChange({ due_date: null }),
},
{
key: "priority",
icon: "flag",
placeholder: "Priority",
value: d.priority ? PRIORITY_LABEL[d.priority] : null,
tone: d.priority ? PRIORITY_COLOR[d.priority] : undefined,
panel: <PriorityChips value={d.priority} onChange={(priority) => onChange({ priority })} />,
onClear: () => onChange({ priority: null }),
},
{
key: "box",
icon: "next",
// "Next up" is the default, so it reads as a placeholder until changed —
// only a deliberate choice earns the accent.
placeholder: BOX_LABEL.next,
value: d.status === "next" ? null : BOX_LABEL[d.status],
panel: (
<View>
<Chips
options={boxes}
labels={BOX_LABEL}
value={d.status}
onChange={(status) => {
haptic.select();
onChange({ status });
}}
/>
{d.status === "waiting" && (
<TextInput
style={s.panelInput}
value={d.waiting_for ?? ""}
onChangeText={(v) => onChange({ waiting_for: v || null })}
placeholder="Waiting for who or what?"
placeholderTextColor={C.muted}
/>
)}
</View>
),
},
{
key: "project",
icon: "projects",
placeholder: "Project",
value: projectName,
panel:
projects.length === 0 ? (
<Text style={s.panelEmpty}>No active projects yet.</Text>
) : (
<Chips
options={projects.map((p) => p.id)}
labels={Object.fromEntries(projects.map((p) => [p.id, p.name]))}
value={d.project_id}
onChange={(v) => {
haptic.select();
onChange({ project_id: v === d.project_id ? null : v });
}}
/>
),
onClear: () => onChange({ project_id: null }),
},
{
key: "estimate",
icon: "waiting",
placeholder: "Estimate",
value: formatEstimate(d.estimate_min),
panel: <EstimateChips value={d.estimate_min} onChange={(estimate_min) => onChange({ estimate_min })} />,
onClear: () => onChange({ estimate_min: null }),
},
{
key: "repeat",
icon: "repeat",
placeholder: "Repeat",
value: d.repeat ? REPEAT_LABEL[d.repeat] : null,
panel: (
<Chips
options={REPEATS}
labels={REPEAT_LABEL}
value={d.repeat}
onChange={(v) => {
haptic.select();
onChange({ repeat: v === d.repeat ? null : v });
}}
/>
),
onClear: () => onChange({ repeat: null }),
},
];
if (showDefer) {
attrs.push({
key: "defer",
icon: "someday",
placeholder: "Start",
value: d.defer_date ? friendlyDate(d.defer_date) : null,
panel: (
<View>
<DateField value={d.defer_date} onChange={(defer_date) => onChange({ defer_date })} clearable />
<Text style={s.panelEmpty}>Hidden from lists until then — it resurfaces on the day.</Text>
</View>
),
onClear: () => onChange({ defer_date: null }),
});
}
// Only offer the tag picker once there's something to pick — an empty chip
// that opens an empty panel is worse than no chip.
if (contexts.length > 0 || d.context) {
const options = d.context && !contexts.includes(d.context) ? [...contexts, d.context] : contexts;
attrs.push({
key: "context",
icon: "tag",
placeholder: "Tag",
value: d.context,
panel: (
<Chips
options={options}
value={d.context}
onChange={(v) => {
haptic.select();
onChange({ context: v === d.context ? null : v });
}}
/>
),
onClear: () => onChange({ context: null }),
});
}
return (
<View>
<View style={s.card}>
<TextInput
style={s.titleInput}
value={d.title}
onChangeText={(title) => onChange({ title })}
placeholder="New to-do"
placeholderTextColor={C.muted}
autoFocus={autoFocus}
returnKeyType="done"
onSubmitEditing={onSubmitTitle}
/>
<Separator />
<TextInput
style={s.notesInput}
value={d.notes}
onChangeText={(notes) => onChange({ notes })}
placeholder="Notes"
placeholderTextColor={C.muted}
multiline
/>
</View>
{!!hint && <Text style={s.hint}>{hint}</Text>}
<AttrBar attrs={attrs} />
</View>
);
}
const s = StyleSheet.create({
card: {
backgroundColor: C.surface,
borderRadius: radius.lg,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
overflow: "hidden",
},
titleInput: {
color: C.text,
fontSize: 20,
fontWeight: "600",
letterSpacing: -0.3,
paddingHorizontal: space.lg,
paddingVertical: space.lg - 2,
},
notesInput: {
color: C.text,
fontSize: 15,
minHeight: 76,
textAlignVertical: "top",
paddingHorizontal: space.lg,
paddingVertical: space.md,
},
hint: {
...type.meta,
color: C.muted,
paddingHorizontal: space.xs,
paddingVertical: space.md,
},
panelInput: {
backgroundColor: C.surface2,
color: C.text,
borderRadius: radius.md,
paddingHorizontal: space.md,
paddingVertical: space.md - 2,
fontSize: 15,
marginTop: space.md,
},
panelEmpty: { ...type.meta, color: C.muted, paddingBottom: space.sm },
});

View File

@@ -1,121 +1,99 @@
import { useFocusEffect, useRouter } from "expo-router";
import { useCallback, useState } from "react";
import {
FlatList,
Pressable,
RefreshControl,
StyleSheet,
Text,
TextInput,
View,
} from "react-native";
import { api } from "../lib/api";
import { C } from "../lib/theme";
import type { Task, TaskStatus } from "../lib/types";
import { useState } from "react";
import { Pressable, RefreshControl, StyleSheet, Text, View } from "react-native";
import DraggableFlatList, { ScaleDecorator } from "react-native-draggable-flatlist";
import { haptic } from "../lib/haptics";
import { reorderTask, sync, tasksByStatus, visibleTasksByStatus } from "../lib/store";
import { C, radius, shadow, space, type } from "../lib/theme";
import { useStore } from "../lib/useStore";
import type { TaskStatus } from "../lib/types";
import TaskRow, { TaskSeparator } from "./TaskRow";
import { cardEdges } from "./ui";
function TaskRow({ task, onToggle }: { task: Task; onToggle: (t: Task) => void }) {
const router = useRouter();
const meta = [task.context, task.waiting_for && `→ ${task.waiting_for}`, task.due_date && `due ${task.due_date}`]
.filter(Boolean)
.join(" · ");
return (
<Pressable style={s.row} onPress={() => router.push(`/task/${task.id}`)}>
<Pressable style={s.checkbox} hitSlop={10} onPress={() => onToggle(task)}>
{task.status === "done" && <View style={s.checkboxFill} />}
</Pressable>
<View style={{ flex: 1 }}>
<Text style={s.title} numberOfLines={2}>
{task.title}
</Text>
{!!meta && <Text style={s.meta}>{meta}</Text>}
</View>
</Pressable>
);
}
// Deferred tasks are hidden from these lists until their date — you can't act
// on them yet, so they shouldn't cost attention. A one-line footer keeps them
// discoverable (trust needs "hidden, not gone").
const HIDES_DEFERRED: TaskStatus[] = ["next", "waiting", "someday"];
// Archives read newest-first and aren't hand-ordered.
const ARCHIVE: TaskStatus[] = ["done", "trashed"];
export default function TaskListScreen({
status,
capture,
emptyHint,
}: {
status: TaskStatus;
capture?: boolean;
emptyHint: string;
}) {
const [tasks, setTasks] = useState<Task[]>([]);
const store = useStore();
const [refreshing, setRefreshing] = useState(false);
const [error, setError] = useState<string | null>(null);
const [draft, setDraft] = useState("");
const [showDeferred, setShowDeferred] = useState(false);
const hidesDeferred = HIDES_DEFERRED.includes(status);
const archive = ARCHIVE.includes(status);
const load = useCallback(async () => {
try {
setTasks(await api.tasks.list({ status }));
setError(null);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
}
}, [status]);
useFocusEffect(
useCallback(() => {
load();
}, [load]),
const all = tasksByStatus(store, status);
let tasks = hidesDeferred && !showDeferred ? visibleTasksByStatus(store, status) : all;
if (archive) {
tasks = [...all].sort((a, b) =>
(b.completed_at ?? b.updated_at).localeCompare(a.completed_at ?? a.updated_at),
);
const add = async () => {
const title = draft.trim();
if (!title) return;
setDraft("");
setTasks((cur) => [{ id: `tmp-${title}`, title, status } as Task, ...cur]);
try {
await api.tasks.create({ title, status });
} finally {
load();
}
};
const toggle = async (task: Task) => {
const done = task.status !== "done";
setTasks((cur) => cur.filter((t) => t.id !== task.id));
try {
await api.tasks.update(task.id, { status: done ? "done" : status });
} finally {
load();
}
};
const hiddenCount = all.length - tasks.length;
return (
<View style={s.screen}>
{capture && (
<TextInput
style={s.capture}
placeholder="Capture anything…"
placeholderTextColor={C.muted}
value={draft}
onChangeText={setDraft}
onSubmitEditing={add}
submitBehavior="submit"
returnKeyType="done"
/>
)}
{error && <Text style={s.error}>{error}</Text>}
<FlatList
<DraggableFlatList
data={tasks}
keyExtractor={(t) => t.id}
renderItem={({ item }) => <TaskRow task={item} onToggle={toggle} />}
activationDistance={12}
onDragBegin={() => haptic.pickup()}
onDragEnd={({ data, from, to }) => {
if (!archive && from !== to) {
haptic.success();
reorderTask(data[to].id, status, to);
}
}}
// The card is drawn by the rows themselves so drag-and-drop still owns
// the whole list: first/last rows round their outer corners, and a
// lifted row goes full-radius so it reads as detached from the stack.
renderItem={({ item, drag, isActive, getIndex }) => {
const i = getIndex() ?? 0;
return (
<ScaleDecorator activeScale={1.02}>
<View style={[...cardEdges(i, tasks.length), isActive && s.lifted]}>
<TaskRow
task={item}
uncheckTo={status === "done" ? "next" : status}
onLongPress={archive ? undefined : drag}
/>
</View>
</ScaleDecorator>
);
}}
ItemSeparatorComponent={TaskSeparator}
refreshControl={
<RefreshControl
refreshing={refreshing}
tintColor={C.muted}
onRefresh={async () => {
setRefreshing(true);
await load();
await sync();
setRefreshing(false);
}}
/>
}
ListEmptyComponent={<Text style={s.empty}>{emptyHint}</Text>}
contentContainerStyle={{ paddingBottom: 32 }}
ListFooterComponent={
hidesDeferred && (hiddenCount > 0 || showDeferred) ? (
<Pressable
onPress={() => setShowDeferred((v) => !v)}
style={({ pressed }) => [s.deferredBtn, pressed && { opacity: 0.6 }]}
>
<Text style={s.deferredText}>
{showDeferred ? "Hide deferred" : `${hiddenCount} deferred — show`}
</Text>
</Pressable>
) : null
}
contentContainerStyle={s.content}
/>
</View>
);
@@ -123,38 +101,16 @@ export default function TaskListScreen({
const s = StyleSheet.create({
screen: { flex: 1, backgroundColor: C.bg },
capture: {
margin: 12,
marginBottom: 4,
padding: 14,
borderRadius: 12,
backgroundColor: C.surface,
color: C.text,
fontSize: 16,
borderWidth: 1,
borderColor: C.border,
content: { paddingHorizontal: space.lg, paddingTop: space.md, paddingBottom: 96 },
lifted: { borderRadius: radius.lg, ...shadow.fab },
empty: {
...type.body,
color: C.muted,
textAlign: "center",
marginTop: 72,
paddingHorizontal: space.xxl,
lineHeight: 22,
},
row: {
flexDirection: "row",
alignItems: "center",
gap: 12,
paddingVertical: 14,
paddingHorizontal: 16,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: C.border,
},
checkbox: {
width: 22,
height: 22,
borderRadius: 11,
borderWidth: 2,
borderColor: C.muted,
alignItems: "center",
justifyContent: "center",
},
checkboxFill: { width: 12, height: 12, borderRadius: 6, backgroundColor: C.done },
title: { color: C.text, fontSize: 16 },
meta: { color: C.muted, fontSize: 13, marginTop: 2 },
empty: { color: C.muted, textAlign: "center", marginTop: 48, fontSize: 15 },
error: { color: C.danger, marginHorizontal: 16, marginTop: 8 },
deferredBtn: { paddingVertical: space.lg, alignItems: "center" },
deferredText: { ...type.meta, color: C.textSecondary, fontWeight: "500" },
});

View File

@@ -0,0 +1,125 @@
import { useRouter } from "expo-router";
import { Pressable, StyleSheet, Text, View } from "react-native";
import Animated, { FadeIn } from "react-native-reanimated";
import { dueMeta, friendlyDate, isDeferred } from "../lib/dates";
import { haptic } from "../lib/haptics";
import { formatEstimate, PRIORITY_COLOR } from "../lib/priority";
import { updateTask } from "../lib/store";
import { C, radius, space, type } from "../lib/theme";
import type { Task, TaskStatus } from "../lib/types";
export default function TaskRow({
task,
uncheckTo = "next",
showStatus,
onLongPress,
}: {
task: Task;
/** Status to revert to when un-checking a done task. */
uncheckTo?: TaskStatus;
showStatus?: boolean;
/** Drag handle for reorderable lists. */
onLongPress?: () => void;
}) {
const router = useRouter();
const done = task.status === "done";
// Due date is rendered separately so it can carry a tone color; the reader
// sees "due today" in amber, never does date math on an ISO string.
const due = task.due_date ? dueMeta(task.due_date) : null;
const dueColor = due?.tone === "overdue" ? C.danger : due?.tone === "today" ? C.warn : C.muted;
const base = [
showStatus ? task.status : null,
task.repeat && "↻",
task.context,
task.waiting_for && `→ ${task.waiting_for}`,
formatEstimate(task.estimate_min),
isDeferred(task.defer_date) && `⏸ until ${friendlyDate(task.defer_date!)}`,
]
.filter(Boolean)
.join(" · ");
const meta = base || due;
const flag = PRIORITY_COLOR[task.priority];
const toggle = () => {
const next = task.status !== "done";
if (next) haptic.success();
else haptic.tap();
updateTask(task.id, { status: next ? "done" : uncheckTo });
};
return (
<Animated.View entering={FadeIn.duration(150)}>
<Pressable
style={({ pressed }) => [s.row, pressed && s.rowPressed]}
onPress={() => router.push(`/task/${task.id}`)}
onLongPress={onLongPress}
delayLongPress={200}
>
{/* Rounded square rather than a circle — the Things checkbox shape.
The border carries the priority colour, so priority is legible at a
glance without spending a whole column on a flag. */}
<Pressable
style={[s.checkbox, { borderColor: done ? C.done : flag }, done && s.checkboxDone]}
hitSlop={10}
onPress={toggle}
>
{done && <Text style={s.check}>✓</Text>}
</Pressable>
<View style={{ flex: 1 }}>
<Text style={[s.title, done && s.titleDone]} numberOfLines={2}>
{task.title}
</Text>
{!!meta && (
<Text style={s.meta} numberOfLines={1}>
{base}
{!!base && !!due && " · "}
{due && <Text style={{ color: dueColor, fontWeight: "500" }}>{due.label}</Text>}
</Text>
)}
</View>
</Pressable>
</Animated.View>
);
}
const s = StyleSheet.create({
row: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingVertical: space.md + 2,
paddingHorizontal: space.lg,
backgroundColor: C.surface,
},
rowPressed: { backgroundColor: C.surface2 },
checkbox: {
width: 22,
height: 22,
borderRadius: 7,
borderWidth: 1.5,
alignItems: "center",
justifyContent: "center",
},
checkboxDone: { backgroundColor: C.done },
check: { color: C.onAccent, fontSize: 13, lineHeight: 16, fontWeight: "700" },
title: { ...type.row, color: C.text },
titleDone: { color: C.muted, textDecorationLine: "line-through" },
meta: { ...type.meta, color: C.muted, marginTop: 3 },
});
/** Inset hairline sized to line up under the task title, not the checkbox. */
export const TASK_ROW_INSET = space.lg + 22 + space.md;
export function TaskSeparator() {
return (
<View
style={{
height: StyleSheet.hairlineWidth,
backgroundColor: C.separator,
marginLeft: TASK_ROW_INSET,
// Keeps the hairline from showing through a card's rounded corner.
borderRadius: radius.sm,
}}
/>
);
}

View File

@@ -1,15 +1,121 @@
import { Pressable, StyleSheet, Text, TextInput, View, type TextInputProps } from "react-native";
import { C } from "../lib/theme";
import { Pressable, StyleSheet, Text, TextInput, View, type TextInputProps, type StyleProp, type ViewStyle } from "react-native";
import { C, radius, shadow, space, type } from "../lib/theme";
export function Field({ label, ...props }: TextInputProps & { label: string }) {
/**
* Screen background + consistent gutter. Every screen sits on the grouped
* background so white cards read as raised paper.
*/
export function Screen({ children, style }: { children: React.ReactNode; style?: ViewStyle }) {
return <View style={[u.screen, style]}>{children}</View>;
}
/**
* Large in-content heading. Nav-bar titles are tiny and centred; Things puts
* the screen name in the content at display size, which is what gives each
* screen its sense of place.
*/
export function Title({ children, count }: { children: React.ReactNode; count?: number }) {
return (
<View style={{ marginBottom: 14 }}>
<Text style={u.label}>{label}</Text>
<TextInput style={u.input} placeholderTextColor={C.muted} {...props} />
<View style={u.titleRow}>
<Text style={u.title}>{children}</Text>
{count !== undefined && count > 0 && <Text style={u.titleCount}>{count}</Text>}
</View>
);
}
/** Small caps label above a group. Sentence case — SHOUTING CAPS reads dated. */
export function SectionHeader({ children, tone }: { children: React.ReactNode; tone?: string }) {
return <Text style={[u.sectionHeader, !!tone && { color: tone }]}>{children}</Text>;
}
/**
* Rounded white group. Rows inside are separated by inset hairlines rather
* than full-bleed dividers, so the card keeps a clean silhouette.
*/
export function Card({ children, style }: { children: React.ReactNode; style?: ViewStyle }) {
return <View style={[u.card, style]}>{children}</View>;
}
/**
* Row background plus rounded outer corners for the first and last row of a
* list, so a plain FlatList reads as one card without wrapping it in a `Card`
* (which would break drag-and-drop and section headers).
*/
export function cardEdges(index: number, count: number) {
return [u.cardRow, index === 0 && u.cardTop, index === count - 1 && u.cardBottom];
}
/** Inset hairline for use between rows inside a `Card`. */
export function Separator({ inset = 0 }: { inset?: number }) {
return <View style={[u.separator, { marginLeft: inset }]} />;
}
/** Compact count/status pill. */
export function Pill({ label, tone }: { label: string; tone?: string }) {
return (
<View style={[u.pill, !!tone && { backgroundColor: `${tone}18` }]}>
<Text style={[u.pillText, !!tone && { color: tone }]}>{label}</Text>
</View>
);
}
/** Centred empty state. One quiet line — no illustration, no exclamation. */
export function Empty({ children }: { children: React.ReactNode }) {
return <Text style={u.empty}>{children}</Text>;
}
export function Field({ label, style, ...props }: TextInputProps & { label: string }) {
return (
<View style={{ marginBottom: space.lg }}>
<Text style={u.label}>{label}</Text>
{/* style last so callers can extend the input (e.g. multiline height)
without silently dropping the base styling. */}
<TextInput style={[u.input, style]} placeholderTextColor={C.muted} {...props} />
</View>
);
}
/** One wrapping row of option chips. The single source of chip geometry. */
export function ChipRow({ children }: { children: React.ReactNode }) {
return <View style={u.chipRow}>{children}</View>;
}
/**
* A single selectable chip. `tone` colours the selected border/text and `tint`
* its fill — priority chips pass their flag colour, everything else falls back
* to the app accent.
*/
export function OptionChip({
label,
active,
onPress,
tone = C.accent,
tint = C.accentSoft,
leading,
}: {
label: string;
active?: boolean;
onPress: () => void;
tone?: string;
tint?: string;
leading?: React.ReactNode;
}) {
return (
<Pressable
style={({ pressed }) => [
u.chip,
active && { borderColor: tone, backgroundColor: tint },
pressed && !active && u.chipPressed,
]}
onPress={onPress}
>
{leading}
<Text style={[u.chipText, active && { color: tone, fontWeight: "600" }]}>{label}</Text>
</Pressable>
);
}
/** Labelled chip group. Omit `label` when the surrounding panel already titles it. */
export function Chips<T extends string>({
label,
options,
@@ -17,26 +123,25 @@ export function Chips<T extends string>({
onChange,
labels,
}: {
label: string;
label?: string;
options: T[];
value: T | null;
onChange: (v: T) => void;
labels?: Record<string, string>;
}) {
return (
<View style={{ marginBottom: 14 }}>
<Text style={u.label}>{label}</Text>
<View style={u.chipRow}>
<View style={label ? { marginBottom: space.lg } : undefined}>
{!!label && <Text style={u.label}>{label}</Text>}
<ChipRow>
{options.map((o) => (
<Pressable
<OptionChip
key={o}
style={[u.chip, value === o && u.chipActive]}
label={labels?.[o] ?? o}
active={value === o}
onPress={() => onChange(o)}
>
<Text style={[u.chipText, value === o && { color: C.text }]}>{labels?.[o] ?? o}</Text>
</Pressable>
/>
))}
</View>
</ChipRow>
</View>
);
}
@@ -45,50 +150,119 @@ export function Button({
title,
onPress,
danger,
secondary,
style,
}: {
title: string;
onPress: () => void;
danger?: boolean;
secondary?: boolean;
style?: StyleProp<ViewStyle>;
}) {
const variant = danger ? u.buttonDanger : secondary ? u.buttonSecondary : null;
const textVariant = danger ? u.buttonTextDanger : secondary ? u.buttonTextSecondary : null;
return (
<Pressable
style={[u.button, danger && { backgroundColor: "transparent", borderColor: C.danger, borderWidth: 1 }]}
style={({ pressed }) => [u.button, variant, style, pressed && { opacity: 0.75 }]}
onPress={onPress}
>
<Text style={[u.buttonText, danger && { color: C.danger }]}>{title}</Text>
<Text style={[u.buttonText, textVariant]}>{title}</Text>
</Pressable>
);
}
const u = StyleSheet.create({
label: { color: C.muted, fontSize: 13, marginBottom: 6, textTransform: "uppercase", letterSpacing: 0.5 },
screen: { flex: 1, backgroundColor: C.bg },
cardRow: { backgroundColor: C.surface },
cardTop: { borderTopLeftRadius: radius.lg, borderTopRightRadius: radius.lg },
cardBottom: {
borderBottomLeftRadius: radius.lg,
borderBottomRightRadius: radius.lg,
...shadow.card,
},
titleRow: {
flexDirection: "row",
alignItems: "center",
gap: space.md,
paddingHorizontal: space.lg,
paddingTop: space.md,
paddingBottom: space.lg,
},
title: { ...type.title, color: C.text },
titleCount: { ...type.title, color: C.muted, fontWeight: "600" },
sectionHeader: {
...type.section,
color: C.textSecondary,
paddingHorizontal: space.xs,
paddingTop: space.xl,
paddingBottom: space.sm,
},
card: {
backgroundColor: C.surface,
borderRadius: radius.lg,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
overflow: "hidden",
...shadow.card,
},
separator: { height: StyleSheet.hairlineWidth, backgroundColor: C.separator },
pill: {
paddingHorizontal: space.sm,
paddingVertical: 3,
borderRadius: radius.pill,
backgroundColor: C.surface2,
},
pillText: { ...type.meta, color: C.textSecondary, fontWeight: "500" },
empty: { color: C.muted, textAlign: "center", marginTop: 56, ...type.body },
label: {
...type.section,
color: C.textSecondary,
marginBottom: space.sm,
},
input: {
backgroundColor: C.surface,
color: C.text,
borderRadius: 10,
borderWidth: 1,
borderRadius: radius.md,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
padding: 12,
paddingHorizontal: space.md,
paddingVertical: space.md,
fontSize: 16,
},
chipRow: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
chipRow: { flexDirection: "row", flexWrap: "wrap", gap: space.sm },
chip: {
paddingVertical: 8,
paddingHorizontal: 14,
borderRadius: 20,
flexDirection: "row",
alignItems: "center",
gap: 7,
paddingVertical: 9,
paddingHorizontal: 15,
borderRadius: radius.pill,
backgroundColor: C.surface,
borderWidth: 1,
borderWidth: StyleSheet.hairlineWidth,
borderColor: C.border,
},
chipActive: { backgroundColor: C.surface2, borderColor: C.accent },
chipText: { color: C.muted, fontSize: 14 },
chipPressed: { backgroundColor: C.surface2 },
chipText: { ...type.chip, color: C.textSecondary },
button: {
backgroundColor: C.accent,
borderRadius: 10,
padding: 14,
borderRadius: radius.md,
paddingVertical: space.lg - 2,
alignItems: "center",
marginTop: 8,
marginBottom: 12,
marginTop: space.sm,
marginBottom: space.md,
},
buttonText: { color: C.text, fontSize: 16, fontWeight: "600" },
buttonDanger: { backgroundColor: "transparent", borderWidth: StyleSheet.hairlineWidth, borderColor: C.danger },
buttonSecondary: { backgroundColor: C.surface, borderWidth: StyleSheet.hairlineWidth, borderColor: C.border },
buttonText: { fontSize: 16, fontWeight: "600", color: C.onAccent },
buttonTextDanger: { color: C.danger },
buttonTextSecondary: { color: C.text },
});

View File

@@ -34,7 +34,7 @@ export const api = {
return req<Task[]>(`/v1/tasks${q ? `?${q}` : ""}`);
},
get: (id: string) => req<Task>(`/v1/tasks/${id}`),
create: (data: Partial<Task> & { title: string }) =>
create: (data: Partial<Task> & { title: string; id?: string }) =>
req<Task>("/v1/tasks", { method: "POST", body: JSON.stringify(data) }),
update: (id: string, data: Partial<Task>) =>
req<Task>(`/v1/tasks/${id}`, { method: "PATCH", body: JSON.stringify(data) }),
@@ -42,7 +42,7 @@ export const api = {
},
projects: {
list: () => req<Project[]>("/v1/projects"),
create: (data: Partial<Project> & { name: string }) =>
create: (data: Partial<Project> & { name: string; id?: string }) =>
req<Project>("/v1/projects", { method: "POST", body: JSON.stringify(data) }),
update: (id: string, data: Partial<Project>) =>
req<Project>(`/v1/projects/${id}`, { method: "PATCH", body: JSON.stringify(data) }),

51
app/src/lib/dates.ts Normal file
View File

@@ -0,0 +1,51 @@
// Date helpers for human-friendly display. All task dates are local ISO
// "YYYY-MM-DD" strings; comparisons are lexicographic.
const DAY_MS = 86_400_000;
export function todayIso(): string {
const d = new Date();
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
}
export function fromIso(s: string): Date {
const [y, m, d] = s.split("-").map(Number);
return new Date(y, m - 1, d);
}
export function toIso(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
}
/** Deferred = hidden from action lists until the date arrives. */
export function isDeferred(deferDate: string | null, today = todayIso()): boolean {
return !!deferDate && deferDate > today;
}
export function daysFromToday(dateIso: string): number {
return Math.round((fromIso(dateIso).getTime() - fromIso(todayIso()).getTime()) / DAY_MS);
}
/** "Today" / "Tomorrow" / "Mon 18 Aug" — no ISO date math for the reader. */
export function friendlyDate(dateIso: string): string {
const diff = daysFromToday(dateIso);
if (diff === 0) return "Today";
if (diff === 1) return "Tomorrow";
if (diff === -1) return "Yesterday";
const d = fromIso(dateIso);
const wd = d.toLocaleDateString("en-AU", { weekday: "short" });
const mo = d.toLocaleDateString("en-AU", { month: "short" });
const yr = d.getFullYear() !== new Date().getFullYear() ? ` ${d.getFullYear()}` : "";
return `${wd} ${d.getDate()} ${mo}${yr}`;
}
export type DueTone = "overdue" | "today" | "later";
/** Row label for a due date, with a tone the UI can color. */
export function dueMeta(dueIso: string): { label: string; tone: DueTone } {
const diff = daysFromToday(dueIso);
if (diff < 0) return { label: diff === -1 ? "1d overdue" : `${-diff}d overdue`, tone: "overdue" };
if (diff === 0) return { label: "due today", tone: "today" };
if (diff === 1) return { label: "due tomorrow", tone: "later" };
return { label: `due ${friendlyDate(dueIso)}`, tone: "later" };
}

24
app/src/lib/haptics.ts Normal file
View File

@@ -0,0 +1,24 @@
// Haptics that silently no-op on web.
import * as Haptics from "expo-haptics";
import { Platform } from "react-native";
const canBuzz = Platform.OS !== "web";
export const haptic = {
/** Light tick — captures, small confirmations. */
tap: () => {
if (canBuzz) void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
},
/** Medium thunk — picking up a draggable. */
pickup: () => {
if (canBuzz) void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
},
/** Success notification — completing a task, landing a drop. */
success: () => {
if (canBuzz) void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
},
/** Selection change — flicking through chips. */
select: () => {
if (canBuzz) void Haptics.selectionAsync();
},
};

34
app/src/lib/priority.ts Normal file
View File

@@ -0,0 +1,34 @@
import type { Task } from "./types";
export const PRIORITIES: Task["priority"][] = [1, 2, 3, 4];
export const PRIORITY_LABEL: Record<Task["priority"], string> = {
1: "Urgent",
2: "High",
3: "Medium",
4: "Low",
};
// Todoist's flag mapping (urgent red → low grey), retuned to sit calmly on a
// light canvas. `PRIORITY_TINT` is the same hue at wash strength, for the
// selected state of a chip — a saturated fill would shout on a white card.
export const PRIORITY_COLOR: Record<Task["priority"], `#${string}`> = {
1: "#E5484D",
2: "#D98324",
3: "#2F6FED",
4: "#9A9AA2",
};
export const PRIORITY_TINT: Record<Task["priority"], `#${string}`> = {
1: "#FDECEC",
2: "#FBF0E2",
3: "#E8F0FE",
4: "#F0F0F3",
};
export function formatEstimate(min: number | null): string | null {
if (!min) return null;
const h = Math.floor(min / 60);
const m = min % 60;
return h ? (m ? `${h}h${m}` : `${h}h`) : `${m}m`;
}

110
app/src/lib/quickadd.ts Normal file
View File

@@ -0,0 +1,110 @@
// Natural-language quick add, Todoist style:
// "Pay rent tomorrow p1 @home #Sydney ~30m monthly"
// → title "Pay rent", due tomorrow, priority 1, context @home,
// project "Sydney" (matched by name prefix), estimate 30 min, repeats monthly.
//
// The add form parses the title field live and mirrors every recognized token
// into a visible form control, so a false positive (e.g. "fri" in a name) is
// seen and fixable, never silent.
import type { Project, Repeat, Task } from "./types";
export interface ParsedQuickAdd {
title: string;
priority?: Task["priority"];
due_date?: string;
context?: string;
project_id?: string;
estimate_min?: number;
repeat?: Repeat;
}
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
const REPEAT_WORDS: Record<string, Repeat> = {
daily: "daily",
weekdays: "weekdays",
weekly: "weekly",
monthly: "monthly",
yearly: "yearly",
};
function iso(d: Date): string {
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${y}-${m}-${day}`;
}
function parseDateWord(word: string): string | undefined {
const w = word.toLowerCase();
const today = new Date();
if (w === "today" || w === "tod") return iso(today);
// No "tom" alias — it's a name far more often than a date.
if (w === "tomorrow" || w === "tmr") {
const d = new Date(today);
d.setDate(d.getDate() + 1);
return iso(d);
}
if (/^\d{4}-\d{2}-\d{2}$/.test(w)) return w;
const wd = WEEKDAYS.findIndex((n) => n === w || n.slice(0, 3) === w);
if (wd >= 0) {
const d = new Date(today);
const delta = (wd - d.getDay() + 7) % 7 || 7; // always the *next* occurrence
d.setDate(d.getDate() + delta);
return iso(d);
}
return undefined;
}
function parseEstimate(token: string): number | undefined {
const m = token.match(/^~(?:(\d+)h)?(\d+)?m?$/i);
if (!m || (!m[1] && !m[2])) return undefined;
return (Number(m[1] ?? 0) * 60 + Number(m[2] ?? 0)) || undefined;
}
export function parseQuickAdd(input: string, projects: Project[]): ParsedQuickAdd {
const out: ParsedQuickAdd = { title: "" };
const rest: string[] = [];
for (const token of input.trim().split(/\s+/)) {
const p = token.match(/^p([1-4])$/i);
if (p && out.priority === undefined) {
out.priority = Number(p[1]) as Task["priority"];
continue;
}
if (token.startsWith("@") && token.length > 1 && out.context === undefined) {
out.context = token;
continue;
}
if (token.startsWith("#") && token.length > 1 && out.project_id === undefined) {
const name = token.slice(1).toLowerCase();
const match = projects.find(
(pr) => pr.status === "active" && pr.name.toLowerCase().startsWith(name),
);
if (match) {
out.project_id = match.id;
continue;
}
}
const est = parseEstimate(token);
if (est && out.estimate_min === undefined) {
out.estimate_min = est;
continue;
}
const rep = REPEAT_WORDS[token.toLowerCase()];
if (rep && out.repeat === undefined) {
out.repeat = rep;
continue;
}
if (out.due_date === undefined) {
const due = parseDateWord(token);
if (due) {
out.due_date = due;
continue;
}
}
rest.push(token);
}
out.title = rest.join(" ");
return out;
}

65
app/src/lib/repeat.ts Normal file
View File

@@ -0,0 +1,65 @@
// Recurrence rules. Completing a repeating task spawns the next occurrence
// (see store.updateTask) — the done row keeps its history, the clone carries
// the rule forward.
import { fromIso, toIso } from "./dates";
import type { Repeat } from "./types";
export const REPEATS: Repeat[] = ["daily", "weekdays", "weekly", "monthly", "yearly"];
export const REPEAT_LABEL: Record<Repeat, string> = {
daily: "Daily",
weekdays: "Weekdays",
weekly: "Weekly",
monthly: "Monthly",
yearly: "Yearly",
};
function addDays(d: Date, n: number): Date {
const r = new Date(d);
r.setDate(r.getDate() + n);
return r;
}
/** Same day-of-month n months later, clamped to the month's last day. */
function addMonthsClamped(d: Date, n: number): Date {
const r = new Date(d.getFullYear(), d.getMonth() + n, 1);
const last = new Date(r.getFullYear(), r.getMonth() + 1, 0).getDate();
r.setDate(Math.min(d.getDate(), last));
return r;
}
function step(d: Date, repeat: Repeat): Date {
switch (repeat) {
case "daily":
return addDays(d, 1);
case "weekdays": {
let n = addDays(d, 1);
while (n.getDay() === 0 || n.getDay() === 6) n = addDays(n, 1);
return n;
}
case "weekly":
return addDays(d, 7);
case "monthly":
return addMonthsClamped(d, 1);
case "yearly":
return addMonthsClamped(d, 12);
}
}
/**
* Next occurrence strictly after the base date, catching up to today for
* lapsed tasks (a monthly bill 3 months overdue advances to the next
* anchor-day on or after today, not three stale dates in the past).
*/
export function nextOccurrence(baseIso: string | null, repeat: Repeat, todayIsoStr: string): string {
let d = fromIso(baseIso ?? todayIsoStr);
let guard = 0;
do {
d = step(d, repeat);
} while (toIso(d) < todayIsoStr && ++guard < 5000);
return toIso(d);
}
export function shiftDays(dateIso: string, n: number): string {
return toIso(addDays(fromIso(dateIso), n));
}

29
app/src/lib/review.ts Normal file
View File

@@ -0,0 +1,29 @@
// Last-completed-review timestamp, local only — the review is a habit, not
// synced data.
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useCallback, useEffect, useState } from "react";
const KEY = "review_last_v1";
export async function getLastReview(): Promise<string | null> {
return AsyncStorage.getItem(KEY);
}
export async function markReviewed(): Promise<void> {
await AsyncStorage.setItem(KEY, new Date().toISOString());
}
export function daysSince(iso: string | null): number | null {
if (!iso) return null;
return Math.floor((Date.now() - new Date(iso).getTime()) / 86_400_000);
}
/** [lastReviewIso, reload] — call reload on focus to pick up changes. */
export function useLastReview(): [string | null, () => void] {
const [last, setLast] = useState<string | null>(null);
const reload = useCallback(() => {
void getLastReview().then(setLast);
}, []);
useEffect(reload, [reload]);
return [last, reload];
}

409
app/src/lib/store.ts Normal file
View File

@@ -0,0 +1,409 @@
// Local-first store — the single source of truth for the UI.
//
// Screens render synchronously from the in-memory state (hydrated from
// AsyncStorage at launch). Mutations apply locally immediately and enqueue an
// op; a background worker drains the queue to the API and then pulls the
// server state, so the network is never on the interaction path. Single-user
// last-write-wins: rows with queued local ops keep their local version during
// a pull; everything else takes the server's.
import AsyncStorage from "@react-native-async-storage/async-storage";
import * as Crypto from "expo-crypto";
import { api } from "./api";
import { getConfig } from "./config";
import { daysFromToday, isDeferred, todayIso } from "./dates";
import { nextOccurrence, shiftDays } from "./repeat";
import type { Project, Task } from "./types";
export interface State {
tasks: Task[];
projects: Project[];
hydrated: boolean;
syncing: boolean;
pending: number;
/** True when the last sync failed for network reasons — expected offline. */
offline: boolean;
syncError: string | null;
}
type Op =
| { kind: "task.create" | "task.update"; id: string; data: Partial<Task> }
| { kind: "project.create" | "project.update"; id: string; data: Partial<Project> };
const DATA_KEY = "store_v1";
const QUEUE_KEY = "queue_v1";
let state: State = {
tasks: [],
projects: [],
hydrated: false,
syncing: false,
pending: 0,
offline: false,
syncError: null,
};
let queue: Op[] = [];
const listeners = new Set<() => void>();
export function getState(): State {
return state;
}
export function subscribe(listener: () => void): () => void {
listeners.add(listener);
return () => listeners.delete(listener);
}
function setState(patch: Partial<State>) {
state = { ...state, ...patch, pending: queue.length };
for (const l of listeners) l();
}
function persistData() {
void AsyncStorage.setItem(DATA_KEY, JSON.stringify({ tasks: state.tasks, projects: state.projects }));
}
function persistQueue() {
void AsyncStorage.setItem(QUEUE_KEY, JSON.stringify(queue));
}
export async function hydrate() {
if (state.hydrated) return;
const [data, q] = await Promise.all([AsyncStorage.getItem(DATA_KEY), AsyncStorage.getItem(QUEUE_KEY)]);
if (q) queue = JSON.parse(q);
const parsed = data ? JSON.parse(data) : { tasks: [], projects: [] };
setState({ tasks: parsed.tasks, projects: parsed.projects, hydrated: true });
void sync();
}
// ---- mutations (instant; network happens later) ----
function now() {
return new Date().toISOString();
}
// Fields the API accepts — everything else (timestamps, completed_at) is local
// bookkeeping until the server's authoritative row arrives via pull().
const TASK_FIELDS = ["title", "notes", "status", "project_id", "context", "waiting_for", "due_date", "defer_date", "priority", "estimate_min", "repeat", "sort_order"] as const;
const PROJECT_FIELDS = ["name", "status", "notes", "sort_order"] as const;
function pickFields<T>(data: Partial<T>, fields: readonly (keyof T & string)[]): Partial<T> {
const out: Partial<T> = {};
for (const f of fields) if (f in data) out[f] = data[f];
return out;
}
function enqueue(op: Op) {
// Coalesce consecutive updates to the same row into one op.
const last = queue[queue.length - 1];
if (last && op.kind === last.kind && op.kind.endsWith("update") && last.id === op.id) {
last.data = { ...last.data, ...op.data };
} else {
queue.push(op);
}
persistQueue();
setState({});
void sync();
}
export function createTask(data: Partial<Task> & { title: string }): Task {
// "next" — this app has no inbox; a task without an explicit box is actionable.
const status = data.status ?? "next";
const task: Task = {
id: Crypto.randomUUID(),
title: data.title,
notes: data.notes ?? "",
status,
project_id: data.project_id ?? null,
context: data.context ?? null,
waiting_for: data.waiting_for ?? null,
due_date: data.due_date ?? null,
defer_date: data.defer_date ?? null,
priority: data.priority ?? 4,
estimate_min: data.estimate_min ?? null,
repeat: data.repeat ?? null,
completed_at: null,
// New tasks land at the top of their list.
sort_order:
data.sort_order ??
Math.min(0, ...state.tasks.filter((t) => t.status === status).map((t) => t.sort_order)) - 1,
created_at: now(),
updated_at: now(),
};
setState({ tasks: [task, ...state.tasks] });
persistData();
enqueue({ kind: "task.create", id: task.id, data: pickFields(task, TASK_FIELDS) });
return task;
}
export function updateTask(id: string, patch: Partial<Task>) {
const before = state.tasks.find((t) => t.id === id);
setState({
tasks: state.tasks.map((t) => {
if (t.id !== id) return t;
const next = { ...t, ...patch, updated_at: now() };
// Mirror the server's completed_at rule so the UI is right pre-sync.
next.completed_at = next.status === "done" ? (t.completed_at ?? now()) : null;
return next;
}),
});
persistData();
enqueue({ kind: "task.update", id, data: pickFields(patch, TASK_FIELDS) });
// Completing a repeating task spawns the next occurrence. Un-checking the
// done row later leaves the spawn in place — it's one tap to trash, versus
// silently deleting a row the user may have edited.
if (before && before.repeat && before.status !== "done" && patch.status === "done") {
spawnNextOccurrence(before);
}
}
function spawnNextOccurrence(t: Task) {
const today = todayIso();
const due = t.due_date ? nextOccurrence(t.due_date, t.repeat!, today) : null;
// Keep the same lead time between defer and due (e.g. "surfaces 3 days before").
const defer =
due && t.due_date && t.defer_date
? shiftDays(t.defer_date, daysFromToday(due) - daysFromToday(t.due_date))
: t.due_date
? null
: t.defer_date
? nextOccurrence(t.defer_date, t.repeat!, today)
: null;
createTask({
title: t.title,
notes: t.notes,
status: t.status,
project_id: t.project_id,
context: t.context,
waiting_for: t.waiting_for,
due_date: due,
defer_date: defer,
priority: t.priority,
estimate_min: t.estimate_min,
repeat: t.repeat,
});
}
export function trashTask(id: string) {
updateTask(id, { status: "trashed" });
}
export function createProject(data: Partial<Project> & { name: string }): Project {
const project: Project = {
id: Crypto.randomUUID(),
name: data.name,
status: data.status ?? "active",
notes: data.notes ?? "",
sort_order: data.sort_order ?? 0,
created_at: now(),
updated_at: now(),
};
setState({ projects: [project, ...state.projects] });
persistData();
enqueue({ kind: "project.create", id: project.id, data: pickFields(project, PROJECT_FIELDS) });
return project;
}
export function updateProject(id: string, patch: Partial<Project>) {
setState({ projects: state.projects.map((p) => (p.id === id ? { ...p, ...patch, updated_at: now() } : p)) });
persistData();
enqueue({ kind: "project.update", id, data: pickFields(patch, PROJECT_FIELDS) });
}
export function dropProject(id: string) {
updateProject(id, { status: "dropped" });
}
// ---- sync ----
let syncRunning = false;
let syncAgain = false;
export async function sync() {
if (syncRunning) {
syncAgain = true;
return;
}
const { token } = await getConfig();
if (!token) return;
syncRunning = true;
setState({ syncing: true });
try {
while (queue.length) {
await push(queue[0]);
queue.shift();
persistQueue();
setState({});
}
await pull();
setState({ syncError: null, offline: false });
} catch (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 {
syncRunning = false;
setState({ syncing: false });
if (syncAgain) {
syncAgain = false;
void sync();
}
}
}
async function push(op: Op) {
try {
if (op.kind === "task.create") await api.tasks.create({ id: op.id, ...op.data } as never);
else if (op.kind === "task.update") await api.tasks.update(op.id, op.data as Partial<Task>);
else if (op.kind === "project.create") await api.projects.create({ id: op.id, ...op.data } as never);
else await api.projects.update(op.id, op.data as Partial<Project>);
} catch (e) {
// 4xx (bad data, row gone) would poison the queue forever — drop the op.
// Anything else (offline, 5xx) rethrows and we retry on the next sync.
const status = (e as { status?: number }).status;
if (status && status >= 400 && status < 500 && status !== 401) return;
throw e;
}
}
async function pull() {
// The default list excludes trashed; fetch trash separately so the Trash
// screen (and restore) survive a sync.
const [open, trashed, projects] = await Promise.all([
api.tasks.list(),
api.tasks.list({ status: "trashed" }),
api.projects.list(),
]);
const tasks = [...open, ...trashed];
// Rows with ops still queued keep their local version; the next sync pass
// pushes those ops and then this merge converges to the server state.
const dirty = new Set(queue.map((o) => o.id));
const keepLocal = <T extends { id: string }>(local: T[], server: T[]) => {
const serverIds = new Set(server.map((r) => r.id));
return [
...server.map((r) => (dirty.has(r.id) ? local.find((l) => l.id === r.id) ?? r : r)),
...local.filter((l) => dirty.has(l.id) && !serverIds.has(l.id)),
];
};
setState({
tasks: keepLocal(state.tasks, tasks),
projects: keepLocal(state.projects, projects),
});
persistData();
}
// ---- selectors ----
function byPriorityDue(a: Task, b: Task): number {
return (
a.priority - b.priority ||
(a.due_date ?? "9999").localeCompare(b.due_date ?? "9999") ||
a.sort_order - b.sort_order ||
b.created_at.localeCompare(a.created_at)
);
}
// 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[] {
return s.tasks.filter((t) => t.status === status).sort(byManualOrder);
}
/**
* The action lists hide deferred tasks until their date arrives — that's the
* whole point of a tickler. Review and the "show deferred" toggle see them.
*/
export function visibleTasksByStatus(s: State, status: Task["status"]): Task[] {
const today = todayIso();
return tasksByStatus(s, status).filter((t) => !isDeferred(t.defer_date, today));
}
/** 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. */
export function todayTasks(s: State): { overdue: Task[]; today: Task[] } {
const now = new Date();
const todayIso = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
const open = s.tasks.filter((t) => t.status !== "done" && t.status !== "trashed");
return {
overdue: open.filter((t) => t.due_date && t.due_date < todayIso).sort(byPriorityDue),
today: open
.filter((t) => t.due_date === todayIso || (t.defer_date === todayIso && !t.due_date))
.sort(byPriorityDue),
};
}
export function activeProjects(s: State): Project[] {
return s.projects
.filter((p) => p.status !== "dropped")
.sort((a, b) => a.sort_order - b.sort_order || b.created_at.localeCompare(a.created_at));
}
export function openTaskCount(s: State, projectId: string): number {
return s.tasks.filter((t) => t.project_id === projectId && t.status !== "done" && t.status !== "trashed").length;
}
/** Distinct contexts on open tasks — suggestion chips beat retyping "@homr". */
export function knownContexts(s: State): string[] {
const set = new Set<string>();
for (const t of s.tasks) {
if (t.context && t.status !== "done" && t.status !== "trashed") set.add(t.context);
}
return [...set].sort();
}
// ---- weekly review ----
const STALE_DAYS = 14;
const WAITING_DAYS = 7;
function olderThanDays(ts: string, days: number): boolean {
return Date.now() - new Date(ts).getTime() > days * 86_400_000;
}
export interface ReviewBuckets {
overdue: Task[];
staleNext: Task[];
agingWaiting: Task[];
someday: Task[];
deferred: Task[];
stuckProjects: Project[];
}
export function reviewBuckets(s: State): ReviewBuckets {
const today = todayIso();
const open = s.tasks.filter((t) => t.status !== "done" && t.status !== "trashed");
const overdue = open.filter((t) => t.due_date && t.due_date < today).sort(byPriorityDue);
const overdueIds = new Set(overdue.map((t) => t.id));
const actionable = new Set(["next", "waiting"]);
return {
overdue,
staleNext: open
.filter((t) => t.status === "next" && !overdueIds.has(t.id) && olderThanDays(t.updated_at, STALE_DAYS))
.sort(byPriorityDue),
agingWaiting: open
.filter((t) => t.status === "waiting" && olderThanDays(t.updated_at, WAITING_DAYS))
.sort((a, b) => a.updated_at.localeCompare(b.updated_at)),
someday: tasksByStatus(s, "someday"),
deferred: open.filter((t) => isDeferred(t.defer_date, today)).sort((a, b) => a.defer_date!.localeCompare(b.defer_date!)),
stuckProjects: activeProjects(s).filter(
(p) => p.status === "active" && !s.tasks.some((t) => t.project_id === p.id && actionable.has(t.status)),
),
};
}

View File

@@ -1,11 +1,115 @@
export const C = {
bg: "#0F1115",
surface: "#1A1D24",
surface2: "#232733",
border: "#2C313D",
text: "#E6E8EC",
muted: "#8A909C",
accent: "#5B8DEF",
done: "#4CAF7D",
danger: "#E05B5B",
};
// Design tokens.
//
// The look is modelled on Things 3: a light, calm canvas, generous whitespace,
// hairline inset separators instead of boxes, and exactly one accent colour
// used sparingly. Everything visual in the app resolves through this file —
// no component hard-codes a hex value (priority flags are the one exception,
// and they live in `priority.ts` alongside their labels).
/** Named palette. `dark` is complete and ready to wire to a theme toggle. */
const light = {
/** Screen background behind grouped content. */
bg: "#F7F7F9",
/** Card / row surface that sits on `bg`. */
surface: "#FFFFFF",
/** Inputs, pressed states, subtle fills. */
surface2: "#EFEFF3",
/** Card outline. Deliberately barely-there. */
border: "#E6E6EB",
/** Inset hairline between rows inside a card. */
separator: "#ECECF0",
/** Primary reading colour. Near-black, never pure #000. */
text: "#16161A",
/** Supporting copy that should still be comfortably readable. */
textSecondary: "#6E6E76",
/** Metadata, placeholders, de-emphasised chrome. */
muted: "#9A9AA2",
accent: "#2F6FED",
/** Tinted accent wash for selected chips and active states. */
accentSoft: "#E8F0FE",
done: "#2FA36B",
danger: "#E5484D",
warn: "#D98324",
/** Text that sits on top of `accent`. */
onAccent: "#FFFFFF",
} as const;
const dark = {
bg: "#0C0C0F",
surface: "#17171B",
surface2: "#212127",
border: "#2A2A31",
separator: "#26262C",
text: "#F2F2F5",
textSecondary: "#A6A6B0",
muted: "#7A7A85",
accent: "#4C86F0",
accentSoft: "#1B2740",
done: "#3FBF84",
danger: "#F0605F",
warn: "#E0A93E",
onAccent: "#FFFFFF",
} as const;
export const PALETTES = { light, dark } as const;
/**
* Active palette. Styles are created at module scope (StyleSheet.create) so
* this is a static choice rather than a hook — switching themes at runtime
* would mean moving every stylesheet inside its component.
*/
export const C = light;
/** 4pt spacing grid. Screen gutter is `space.lg`. */
export const space = {
xs: 4,
sm: 8,
md: 12,
lg: 16,
xl: 20,
xxl: 28,
} as const;
export const radius = {
sm: 8,
md: 12,
/** Cards and grouped lists. */
lg: 16,
/** Chips and pills. */
pill: 999,
} as const;
/**
* Type scale. `title` is the large in-content screen heading that replaces a
* cramped nav-bar title; `row` is the task title size — 17pt, matching the
* platform body size Things and Todoist both settle on.
*/
export const type = {
title: { fontSize: 30, fontWeight: "700", letterSpacing: -0.6 },
section: { fontSize: 13, fontWeight: "600", letterSpacing: 0.3 },
row: { fontSize: 17, letterSpacing: -0.2 },
body: { fontSize: 15 },
meta: { fontSize: 13 },
chip: { fontSize: 14, fontWeight: "500" },
} as const;
/**
* Card elevation. Kept extremely soft — a Things-like surface reads as paper,
* not as a floating panel.
*/
export const shadow = {
card: {
shadowColor: "#0B0B12",
shadowOpacity: 0.05,
shadowRadius: 10,
shadowOffset: { width: 0, height: 2 },
elevation: 1,
},
fab: {
shadowColor: "#0B0B12",
shadowOpacity: 0.22,
shadowRadius: 14,
shadowOffset: { width: 0, height: 6 },
elevation: 6,
},
} as const;

View File

@@ -1,5 +1,6 @@
export type TaskStatus = "inbox" | "next" | "waiting" | "scheduled" | "someday" | "done" | "trashed";
export type ProjectStatus = "active" | "someday" | "completed" | "dropped";
export type Repeat = "daily" | "weekdays" | "weekly" | "monthly" | "yearly";
export interface Task {
id: string;
@@ -11,6 +12,9 @@ export interface Task {
waiting_for: string | null;
due_date: string | null;
defer_date: string | null;
priority: 1 | 2 | 3 | 4;
estimate_min: number | null;
repeat: Repeat | null;
completed_at: string | null;
sort_order: number;
created_at: string;

8
app/src/lib/useStore.ts Normal file
View File

@@ -0,0 +1,8 @@
import { useSyncExternalStore } from "react";
import { getState, subscribe, type State } from "./store";
// Subscribe a component to the local-first store. The whole state object is
// the snapshot (replaced immutably on every change), so derive lists inline.
export function useStore(): State {
return useSyncExternalStore(subscribe, getState, getState);
}

View File

@@ -0,0 +1,98 @@
"use no memo"; // widget trees are built by calling the component as a plain function — the React Compiler must not transform it
// Home-screen widget: the same top-three "Next up" list as the home screen.
// Built only from react-native-android-widget primitives (no RN views, no
// hooks) — it renders to Android RemoteViews in a headless task.
//
// Interactions mirror the app: tap the checkbox to complete, tap the row to
// open Clarify, tap + to capture, tap anywhere else to open the app.
import { FlexWidget, TextWidget } from "react-native-android-widget";
import { dueMeta, type DueTone } from "../lib/dates";
import { formatEstimate, PRIORITY_COLOR } from "../lib/priority";
import { C } from "../lib/theme";
import type { Task } from "../lib/types";
const DUE_COLOR: Record<DueTone, `#${string}`> = { overdue: C.danger, today: C.warn, later: C.muted };
function Row({ task }: { task: Task }) {
const due = task.due_date ? dueMeta(task.due_date) : null;
// One line per row so three rows fit the 2-cell height: right-side meta is
// the due label when there is one, otherwise context/estimate.
const side = due ? due.label : [task.context, formatEstimate(task.estimate_min)].filter(Boolean).join(" · ");
return (
<FlexWidget
style={{ width: "match_parent", flex: 1, flexDirection: "row", alignItems: "center" }}
clickAction="OPEN_URI"
clickActionData={{ uri: `gtd://task/${task.id}` }}
>
<FlexWidget
clickAction="COMPLETE_TASK"
clickActionData={{ taskId: task.id }}
accessibilityLabel={`Complete ${task.title}`}
style={{ width: 32, height: 32, alignItems: "center", justifyContent: "center" }}
>
<FlexWidget
style={{ width: 19, height: 19, borderRadius: 6, borderWidth: 2, borderColor: PRIORITY_COLOR[task.priority] }}
/>
</FlexWidget>
<FlexWidget style={{ flex: 1, marginLeft: 6 }}>
<TextWidget text={task.title} truncate="END" maxLines={1} style={{ fontSize: 15, color: C.text }} />
</FlexWidget>
{!!side && <TextWidget text={side} truncate="END" maxLines={1} style={{ fontSize: 11, color: due ? DUE_COLOR[due.tone] : C.muted, marginLeft: 8 }} />}
</FlexWidget>
);
}
export function NextUpWidget({ tasks, totalNext, overdueCount }: { tasks: Task[]; totalNext: number; overdueCount: number }) {
return (
<FlexWidget
clickAction="OPEN_APP"
style={{
width: "match_parent",
height: "match_parent",
flexDirection: "column",
backgroundColor: C.surface,
borderRadius: 24,
paddingHorizontal: 16,
paddingVertical: 12,
}}
>
<FlexWidget
style={{ width: "match_parent", flexDirection: "row", alignItems: "center", justifyContent: "space-between", marginBottom: 4 }}
>
<FlexWidget style={{ flexDirection: "row", alignItems: "center" }}>
<TextWidget text="Next up" style={{ fontSize: 13, fontWeight: "600", letterSpacing: 0.3, color: C.textSecondary }} />
{totalNext > tasks.length && (
<TextWidget text={` +${totalNext - tasks.length} more`} style={{ fontSize: 12, color: C.muted }} />
)}
{overdueCount > 0 && (
<TextWidget
text={` · ${overdueCount} overdue`}
clickAction="OPEN_URI"
clickActionData={{ uri: "gtd://today" }}
style={{ fontSize: 12, color: C.danger }}
/>
)}
</FlexWidget>
<FlexWidget
clickAction="OPEN_URI"
clickActionData={{ uri: "gtd://add" }}
accessibilityLabel="Add task"
style={{ width: 28, height: 28, borderRadius: 14, backgroundColor: C.accent, alignItems: "center", justifyContent: "center" }}
>
<TextWidget text="+" style={{ fontSize: 16, color: C.onAccent }} />
</FlexWidget>
</FlexWidget>
{tasks.length === 0 ? (
<FlexWidget style={{ width: "match_parent", flex: 1, alignItems: "center", justifyContent: "center" }}>
<TextWidget text="Nothing next. Tap + to add." style={{ fontSize: 14, color: C.muted }} />
</FlexWidget>
) : (
<FlexWidget style={{ width: "match_parent", flex: 1, flexDirection: "column" }}>
{tasks.map((t) => (
<Row key={t.id} task={t} />
))}
</FlexWidget>
)}
</FlexWidget>
);
}

18
app/src/widget/refresh.ts Normal file
View File

@@ -0,0 +1,18 @@
import { Platform } from "react-native";
import { requestWidgetUpdate } from "react-native-android-widget";
import { renderNextUpWidget, WIDGET_NAME } from "./render";
let timer: ReturnType<typeof setTimeout> | undefined;
/**
* Redraw the home-screen widget from current store state. Debounced because
* it's driven by the store listener, which fires on every mutation and sync
* step; drawing RemoteViews once per burst is plenty.
*/
export function refreshNextUpWidget() {
if (Platform.OS !== "android") return;
clearTimeout(timer);
timer = setTimeout(() => {
void requestWidgetUpdate({ widgetName: WIDGET_NAME, renderWidget: renderNextUpWidget });
}, 300);
}

14
app/src/widget/render.tsx Normal file
View File

@@ -0,0 +1,14 @@
"use no memo";
// One source of truth for what the widget shows: the same selectors the home
// screen uses, so widget and app always agree on the top three.
import { getState, todayTasks, visibleTasksByStatus } from "../lib/store";
import { NextUpWidget } from "./NextUpWidget";
/** Must match the widget `name` in app.json's react-native-android-widget plugin config. */
export const WIDGET_NAME = "NextUp";
export function renderNextUpWidget() {
const s = getState();
const next = visibleTasksByStatus(s, "next");
return <NextUpWidget tasks={next.slice(0, 3)} totalNext={next.length} overdueCount={todayTasks(s).overdue.length} />;
}

View File

@@ -0,0 +1,19 @@
// Headless entry point for widget events. When the app's JS context is
// alive this shares the in-memory store; when launched cold, hydrate() loads
// AsyncStorage — so completing from the widget goes through the exact same
// local-first mutation path (instant local write, op queued, synced later).
import type { WidgetTaskHandlerProps } from "react-native-android-widget";
import { hydrate, updateTask } from "../lib/store";
import { renderNextUpWidget } from "./render";
export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
if (props.widgetAction === "WIDGET_DELETED") return;
await hydrate();
if (props.widgetAction === "WIDGET_CLICK") {
// OPEN_APP / OPEN_URI are handled natively; only completion reaches JS.
if (props.clickAction !== "COMPLETE_TASK") return;
const taskId = props.clickActionData?.taskId;
if (typeof taskId === "string") updateTask(taskId, { status: "done" });
}
props.renderWidget(renderNextUpWidget());
}

View File

@@ -5,13 +5,19 @@ const sql = new SQL(process.env.DATABASE_URL!);
const API_TOKEN = process.env.API_TOKEN!;
if (!API_TOKEN) throw new Error("API_TOKEN not set");
// schema.sql is idempotent (create/alter-if-not-exists) — apply it at boot so
// a deployed server is never newer than the database it queries.
await sql.unsafe(await Bun.file(new URL("schema.sql", import.meta.url)).text());
const TASK_COLS = `id, title, notes, status, project_id, context, waiting_for,
due_date::text as due_date, defer_date::text as defer_date,
completed_at, sort_order, created_at, updated_at`;
priority, estimate_min, repeat, completed_at, sort_order, created_at, updated_at`;
const PROJECT_COLS = `id, name, status, notes, sort_order, created_at, updated_at`;
const TASK_STATUSES = ["inbox", "next", "waiting", "scheduled", "someday", "done", "trashed"];
const REPEATS = ["daily", "weekdays", "weekly", "monthly", "yearly"];
const PROJECT_STATUSES = ["active", "someday", "completed", "dropped"];
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
const CORS = {
"Access-Control-Allow-Origin": "*",
@@ -27,12 +33,15 @@ function err(message: string, status: number) {
}
// Fields a client may set. completed_at is derived from status server-side.
const TASK_FIELDS = ["title", "notes", "status", "project_id", "context", "waiting_for", "due_date", "defer_date", "sort_order"];
const TASK_FIELDS = ["title", "notes", "status", "project_id", "context", "waiting_for", "due_date", "defer_date", "priority", "estimate_min", "repeat", "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", "repeat"]);
function pick(body: Record<string, unknown>, fields: string[]) {
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;
}
@@ -69,13 +78,20 @@ async function handle(req: Request): Promise<Response> {
const t = pick(body, TASK_FIELDS);
if (typeof t.title !== "string" || !t.title.trim()) return err("title required", 400);
if (t.status && !TASK_STATUSES.includes(t.status as string)) return err("bad status", 400);
if (t.repeat && !REPEATS.includes(t.repeat as string)) return err("bad repeat", 400);
const id = typeof body.id === "string" && UUID_RE.test(body.id) ? body.id : null;
// Client-supplied id + on-conflict no-op make offline-queue retries idempotent.
const rows = await sql.unsafe(
`insert into tasks (title, notes, status, project_id, context, waiting_for, due_date, defer_date, sort_order)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
`insert into tasks (id, title, notes, status, project_id, context, waiting_for, due_date, defer_date, priority, estimate_min, repeat, sort_order)
values (coalesce($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
on conflict (id) do nothing
returning ${TASK_COLS}`,
[t.title, t.notes ?? "", t.status ?? "inbox", t.project_id ?? null, t.context ?? null,
t.waiting_for ?? null, t.due_date ?? null, t.defer_date ?? null, t.sort_order ?? 0]);
return json(rows[0], 201);
[id, t.title, t.notes ?? "", t.status ?? "next", t.project_id ?? null, t.context ?? null,
t.waiting_for ?? null, t.due_date ?? null, t.defer_date ?? null, t.priority ?? 4,
t.estimate_min ?? null, t.repeat ?? null, t.sort_order ?? 0]);
if (rows.length) return json(rows[0], 201);
const existing = await sql.unsafe(`select ${TASK_COLS} from tasks where id = $1`, [id]);
return json(existing[0], 200);
}
let m = path.match(/^\/v1\/tasks\/([0-9a-f-]{36})$/);
@@ -87,16 +103,18 @@ async function handle(req: Request): Promise<Response> {
const id = m[1];
const patch = method === "DELETE" ? { status: "trashed" } : pick(body, TASK_FIELDS);
if (patch.status && !TASK_STATUSES.includes(patch.status as string)) return err("bad status", 400);
if (patch.repeat && !REPEATS.includes(patch.repeat as string)) return err("bad repeat", 400);
const existing = await sql.unsafe(`select ${TASK_COLS} from tasks where id = $1`, [id]);
if (!existing.length) return err("not found", 404);
const cur = { ...existing[0], ...patch };
const completedAt = cur.status === "done" ? (existing[0].completed_at ?? new Date()) : null;
const rows = await sql.unsafe(
`update tasks set title=$2, notes=$3, status=$4, project_id=$5, context=$6, waiting_for=$7,
due_date=$8, defer_date=$9, completed_at=$10, sort_order=$11, updated_at=now()
due_date=$8, defer_date=$9, priority=$10, estimate_min=$11, repeat=$12, completed_at=$13,
sort_order=$14, updated_at=now()
where id=$1 returning ${TASK_COLS}`,
[id, cur.title, cur.notes, cur.status, cur.project_id, cur.context, cur.waiting_for,
cur.due_date, cur.defer_date, completedAt, cur.sort_order]);
cur.due_date, cur.defer_date, cur.priority, cur.estimate_min, cur.repeat, completedAt, cur.sort_order]);
return json(rows[0]);
}
@@ -115,11 +133,16 @@ async function handle(req: Request): Promise<Response> {
const p = pick(body, PROJECT_FIELDS);
if (typeof p.name !== "string" || !p.name.trim()) return err("name required", 400);
if (p.status && !PROJECT_STATUSES.includes(p.status as string)) return err("bad status", 400);
const id = typeof body.id === "string" && UUID_RE.test(body.id) ? body.id : null;
const rows = await sql.unsafe(
`insert into projects (name, status, notes, sort_order) values ($1, $2, $3, $4)
`insert into projects (id, name, status, notes, sort_order)
values (coalesce($1::uuid, gen_random_uuid()), $2, $3, $4, $5)
on conflict (id) do nothing
returning ${PROJECT_COLS}`,
[p.name, p.status ?? "active", p.notes ?? "", p.sort_order ?? 0]);
return json(rows[0], 201);
[id, p.name, p.status ?? "active", p.notes ?? "", p.sort_order ?? 0]);
if (rows.length) return json(rows[0], 201);
const existing = await sql.unsafe(`select ${PROJECT_COLS} from projects where id = $1`, [id]);
return json(existing[0], 200);
}
m = path.match(/^\/v1\/projects\/([0-9a-f-]{36})$/);
@@ -153,6 +176,10 @@ Bun.serve({
fetch: (req) =>
handle(req).catch((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);
}),
});

View File

@@ -23,6 +23,9 @@ create table if not exists tasks (
waiting_for text, -- who/what is being waited on when status = 'waiting'
due_date date,
defer_date date, -- hide from lists until this date
priority int not null default 4 check (priority between 1 and 4), -- 1=urgent … 4=low
estimate_min int check (estimate_min > 0),
repeat text check (repeat in ('daily', 'weekdays', 'weekly', 'monthly', 'yearly')),
completed_at timestamptz,
sort_order double precision not null default 0,
created_at timestamptz not null default now(),
@@ -31,3 +34,7 @@ create table if not exists tasks (
create index if not exists tasks_status_idx on tasks (status);
create index if not exists tasks_project_idx on tasks (project_id);
-- Columns added after the initial deploy (create-if-not-exists won't alter).
alter table tasks add column if not exists repeat text
check (repeat in ('daily', 'weekdays', 'weekly', 'monthly', 'yearly'));