Files
2026-03-16 20:12:01 +01:00

218 lines
9.1 KiB
Markdown

---
phase: 02-rooms-and-tasks
plan: 04
type: execute
wave: 3
depends_on: ["02-02", "02-03"]
files_modified:
- lib/features/templates/presentation/template_picker_sheet.dart
- lib/features/rooms/presentation/room_form_screen.dart
- lib/l10n/app_de.arb
autonomous: true
requirements:
- TMPL-01
- TMPL-02
must_haves:
truths:
- "After creating a room whose name matches a known room type, user is prompted to add tasks from templates"
- "Template picker shows a checklist of German-language task templates with all unchecked by default"
- "User can check desired templates and they are created as tasks in the room with correct frequencies and effort levels"
- "If room name does not match any known type, no template prompt appears and room is created directly"
- "All 14 room types from TMPL-02 are covered by the template system"
artifacts:
- path: "lib/features/templates/presentation/template_picker_sheet.dart"
provides: "Bottom sheet with checklist of task templates for a detected room type"
min_lines: 40
key_links:
- from: "lib/features/rooms/presentation/room_form_screen.dart"
to: "lib/features/templates/data/task_templates.dart"
via: "After room save, calls detectRoomType on room name"
pattern: "detectRoomType"
- from: "lib/features/rooms/presentation/room_form_screen.dart"
to: "lib/features/templates/presentation/template_picker_sheet.dart"
via: "Shows template picker bottom sheet if room type detected"
pattern: "TemplatePicker|showModalBottomSheet"
- from: "lib/features/templates/presentation/template_picker_sheet.dart"
to: "lib/features/tasks/presentation/task_providers.dart"
via: "Creates tasks from selected templates via taskActions.createTask"
pattern: "createTask"
---
<objective>
Wire the template selection flow into room creation: detect room type from name, show template picker bottom sheet, and create selected templates as tasks in the newly created room.
Purpose: Delivers TMPL-01 and TMPL-02 -- the template-driven task creation that makes the app immediately useful. Users create a room and get relevant German-language task suggestions.
Output: Template picker bottom sheet, updated room form with template flow integration.
</objective>
<execution_context>
@/home/jlmak/.claude/get-shit-done/workflows/execute-plan.md
@/home/jlmak/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/02-rooms-and-tasks/2-CONTEXT.md
@.planning/phases/02-rooms-and-tasks/02-RESEARCH.md
@.planning/phases/02-rooms-and-tasks/02-01-SUMMARY.md
@.planning/phases/02-rooms-and-tasks/02-02-SUMMARY.md
@.planning/phases/02-rooms-and-tasks/02-03-SUMMARY.md
<interfaces>
<!-- From Plan 01 (template data) -->
From lib/features/templates/data/task_templates.dart:
```dart
class TaskTemplate {
final String name;
final String? description;
final IntervalType intervalType;
final int intervalDays;
final EffortLevel effortLevel;
const TaskTemplate({...});
}
const Map<String, List<TaskTemplate>> roomTemplates = { ... };
String? detectRoomType(String roomName);
```
<!-- From Plan 02 (room form) -->
From lib/features/rooms/presentation/room_form_screen.dart:
```dart
// Full-screen form with name + icon fields
// On save: calls roomActions.createRoom(name, iconName) which returns roomId
// After save: context.pop() currently
// MODIFY: after save for new rooms, check detectRoomType before popping
```
<!-- From Plan 03 (task creation) -->
From lib/features/tasks/presentation/task_providers.dart:
```dart
@riverpod
class TaskActions extends _$TaskActions {
Future<int> createTask({
required int roomId,
required String name,
String? description,
required IntervalType intervalType,
required int intervalDays,
int? anchorDay,
required EffortLevel effortLevel,
required DateTime nextDueDate,
}) async { ... }
}
```
</interfaces>
</context>
<tasks>
<task type="auto">
<name>Task 1: Create template picker bottom sheet</name>
<files>
lib/features/templates/presentation/template_picker_sheet.dart,
lib/l10n/app_de.arb
</files>
<action>
**lib/features/templates/presentation/template_picker_sheet.dart**: Create a `StatefulWidget` (not Consumer -- it receives data via constructor) that displays a checklist of task templates.
Constructor parameters:
- `String roomType` -- the detected room type key
- `List<TaskTemplate> templates` -- the template list for this room type
- `void Function(List<TaskTemplate> selected) onConfirm` -- callback with selected templates
UI structure:
- Title: "Aufgaben aus Vorlagen hinzufuegen?" (from ARB)
- Subtitle hint: the detected room type display name (capitalize first letter)
- `ListView` of `CheckboxListTile` widgets, one per template
- Each tile shows: template name as title, frequency label as subtitle (e.g. "Woechentlich - Mittel")
- **All unchecked by default** per user decision
- Bottom action row: "Ueberspringen" (skip/cancel) button and "Hinzufuegen" (add) button
- "Hinzufuegen" button only enabled when at least one template is checked
- Use `showModalBottomSheet` with `isScrollControlled: true` and `DraggableScrollableSheet` for long lists
- Track checked state with a `Set<int>` (template index)
**lib/l10n/app_de.arb**: Add template-related keys:
- "templatePickerTitle": "Aufgaben aus Vorlagen hinzuf\u00fcgen?"
- "templatePickerSkip": "\u00dcberspringen"
- "templatePickerAdd": "Hinzuf\u00fcgen"
- "templatePickerSelected": "{count} ausgew\u00e4hlt"
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/HouseHoldKeaper && dart analyze lib/features/templates/presentation/ && flutter test</automated>
</verify>
<done>
Template picker bottom sheet displays checklist of templates with frequency/effort info, all unchecked by default. Skip and add buttons. Localized German strings.
</done>
</task>
<task type="auto">
<name>Task 2: Wire template flow into room creation</name>
<files>
lib/features/rooms/presentation/room_form_screen.dart
</files>
<action>
Modify the room form screen's save flow for NEW rooms (not edit) to integrate the template selection:
1. After `roomActions.createRoom(name, iconName)` returns the new `roomId`:
2. Call `detectRoomType(name)` to check if the room name matches a known type
3. **If room type detected** (not null):
- Look up `roomTemplates[roomType]` to get the template list
- Show `TemplatePickerSheet` via `showModalBottomSheet`
- If user selects templates and confirms:
- For each selected `TaskTemplate`, call `taskActions.createTask()` with:
- `roomId`: the newly created room ID
- `name`: template.name
- `description`: template.description
- `intervalType`: template.intervalType
- `intervalDays`: template.intervalDays
- `anchorDay`: set based on interval type (for calendar-anchored: today's day-of-month)
- `effortLevel`: template.effortLevel
- `nextDueDate`: today (first due date = today for all template tasks)
- After creating all tasks, navigate to the new room: `context.go('/rooms/$roomId')`
- If user skips (taps "Ueberspringen"): navigate to `/rooms/$roomId` without creating tasks
4. **If no room type detected** (null):
- Navigate directly to `/rooms/$roomId` (no template prompt per user decision: "Users can create fully custom rooms with no template prompt if no room type matches")
Important per user decision: "The template prompt after room creation should feel like a helpful suggestion, not a required step -- easy to dismiss"
For EDIT mode: no template prompt (only on creation). The save flow for edit stays as-is (update room, pop).
Read `taskActionsProvider` via `ref.read(taskActionsProvider.notifier)` for the mutations (not watch -- this is in a callback).
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/HouseHoldKeaper && dart analyze lib/features/rooms/presentation/ lib/features/templates/presentation/ && flutter test</automated>
</verify>
<done>
Room creation flow: save room -> detect room type -> show template picker if match -> create selected templates as tasks -> navigate to room. Custom rooms skip templates. Edit mode unaffected. All existing tests pass.
</done>
</task>
</tasks>
<verification>
```bash
cd /home/jlmak/Projects/jlmak/HouseHoldKeaper && dart analyze && flutter test
```
All code analyzes clean. All tests pass. Template selection flow is wired into room creation.
</verification>
<success_criteria>
- Creating a room with a recognized name (e.g. "Kueche") triggers template picker
- Template picker shows relevant German task templates, all unchecked
- Checking templates and confirming creates them as tasks in the room
- Skipping creates the room without tasks
- Unrecognized room names skip template prompt entirely
- Edit mode does not show template prompt
- All 14 room types accessible via detectRoomType
</success_criteria>
<output>
After completion, create `.planning/phases/02-rooms-and-tasks/02-04-SUMMARY.md`
</output>