adding food logging, phase 0

This commit is contained in:
Joren de Graaf
2026-10-03 20:37:04 +02:00
parent c0eda95f26
commit 11ded97ed1
12 changed files with 227 additions and 5 deletions
+63
View File
@@ -0,0 +1,63 @@
# Food module — v1 design and implementation spec
Source: the supplied `00-overview.md` and five food diary screenshots. The screenshots guide hierarchy and interactions; use original styling, icons, and product imagery. Do not copy the source app's assets or branding.
## Project integration
`food` is a separate Django app in `main/food/`, registered in `INSTALLED_APPS`. Its URL namespace is `food`, mounted at `/food/`; `food:diary` is the entry point. The shared authenticated navigation contains a **Food** item. Food templates can extend `planner/base.html` and use the existing Vite/HTMX setup, but food models, views, forms, services, and tests belong to the `food` app. Every food record is owned by the authenticated user. The app scaffold and route exist; the diary features below are the implementation scope for v1.
## Core flow
Open Food → choose a day → tap the plus beside a meal → pick a recent or favourite food, search local products, scan a barcode, or deliberately search Open Food Facts → review the product → choose a portion and quantity → save → see the meal list and daily totals update. A cached product must be reusable without another external request.
## Screens and behavior
### Diary (`/food/`)
- Mobile: date switcher at top, then a calorie budget card, three macro summary cards, and Breakfast, Lunch, Dinner, Snacks groups. Each group shows its calories and an add button. Food rows show name, optional brand/image, calories, and chosen portion. A floating add action can open meal selection.
- Keep a compact summary visible while scrolling if it does not obscure entries or controls. Desktop: meal list in the main column and a sticky summary sidebar.
- The calorie card shows eaten, goal, and remaining. Macro cards show consumed/goal and progress for carbohydrates, protein, and fat. Empty and over-goal states need readable numbers in addition to color.
- Date changes load that user's entries for the selected local day. Meal headings and totals derive from saved entries. A row opens its entry for editing or deletion; neither action affects another user's records.
### Add food
- Show Favourites, Recent, and All local products as distinct tabs. Search queries the local database while typing. Each row gives a product name, brand if known, calories for a clearly named reference portion, and optional thumbnail.
- Provide explicit **Search Open Food Facts** and **Scan barcode** actions. Do not call the external catalogue on each keystroke. Preserve the selected day and meal throughout search and add flows.
- Browser scanning uses native `BarcodeDetector` when supported and a ZXing browser fallback otherwise. Start the camera only after a user action; stop all tracks on success, cancel, navigation, and error. Offer text barcode entry when camera access fails.
- On barcode entry or scan, look up the local cache first. Query Open Food Facts only for an uncached code or an explicit refresh. Show missing/incomplete data clearly and allow manual entry.
### Product detail and log
- Show product name, brand, optional image, and calories/carbohydrates/protein/fat for the selected amount. Quantity and portion controls update these values before saving. Let users define a named custom portion with its gram or millilitre amount.
- Meal selection defaults to the meal used to launch the flow and remains editable. Show available nutrient data without turning missing values into invented zeros.
- Saving creates a snapshot of name, amount, unit, nutrient values, meal, and date in the log entry. Later catalogue refreshes must not silently change historical entries. Favourites can be toggled here or from search.
### Goals and export
- Per-user daily calorie, carbohydrate, protein, and fat goals are editable. Choose sensible blank states instead of implying personalized recommendations.
- Export the current week or current month as CSV using the user's local dates. Include date, meal, product, brand, quantity, portion, calories, carbohydrates, protein, and fat; restrict the export to the requesting user.
## Data and service boundaries
- `FoodProduct`: user-owned local catalogue entry or cached Open Food Facts item; store barcode/source identifier, display details, nutrients per 100 g or 100 ml, source/refresh timestamp, and optional image URL. Validate units and nullable nutrients. Barcode uniqueness should be scoped appropriately so users' local data stays isolated.
- `FoodPortion`: product-linked label, amount, and unit; record which user created a custom portion. A standard 100 g/ml option must always be available when the source data supports it.
- `FoodLogEntry`: user, local date, meal, product reference if available, chosen quantity/portion, and immutable display/nutrient snapshot. Calculate totals from snapshots with decimal arithmetic.
- `FoodGoal`: one set of daily goals per user. `FoodFavourite` can be a user/product relation. Recents derive from log entries, ordered by latest use and deduplicated.
- Put Open Food Facts HTTP calls in a server-side service with timeouts and explicit error handling. Map only validated catalogue values into local records. Include Open Food Facts attribution and a link to the source product where its data appears.
## Visual system and accessibility
Use the screenshots' information hierarchy: high contrast background, restrained cards, color-coded nutrient accents, compact product rows, prominent add and scan controls. Respect the existing Tasknest appearance setting, including light mode. All actions must be reachable by keyboard and screen reader; icon-only buttons need accessible labels. Do not rely on ring color alone to convey a value. Preserve usable controls at iPhone widths, safe areas, and large text sizes.
## Acceptance criteria
1. A signed-in user can set goals, add a manual food to Breakfast, edit it, and delete it; the diary totals update correctly for that local day.
2. Local search, favourites, and recents return only the user's available foods and never trigger an external request while typing.
3. Barcode flow checks local records first; an uncached barcode fetches and caches an Open Food Facts product; scan cancellation releases the camera.
4. Portion and quantity math uses the same nutrient basis in preview and saved entry; a custom portion can be reused.
5. Week and month CSV files contain only the requesting user's entries and correct local dates.
6. The mobile diary, add-food flow, and product detail remain usable without horizontal scrolling; desktop uses the available width.
## Out of scope for v1
Weight-loss planning, automatic goal recommendations, exercise calorie adjustment, Apple Health, Home Assistant, recipes, meal templates, AI recognition, photo estimates, micronutrient goal dashboards, weekly nutrition reports, automatic grocery lists, diet scoring, and social features.
+60
View File
@@ -0,0 +1,60 @@
# Tasknest settings page design spec
Use this as a visual and interaction reference for another app's `/settings` page. Keep that app's existing setting names and save behavior; apply the layout and component language below.
## Page structure
- Place the page inside the app's normal header and content shell. Tasknest's shell is at most **1180px** wide, with **28px** horizontal padding and **64px** top padding. At widths up to **560px**, horizontal padding becomes **18px** and top padding **40px**.
- Center the settings content in a single column, at most **680px** wide. There is no settings sidebar.
- Begin with a small uppercase eyebrow, then a large `Settings` heading. The eyebrow uses the green accent, **0.74rem**, bold weight, and **0.1em** letter spacing. The heading uses Fraunces (or a similar friendly serif), bold, with `clamp(2.3rem, 4vw, 3.5rem)` and tight letter spacing.
- Stack one card per topic with **24px** between cards. Each card contains a short heading, optional one or two sentence explanation, its fields, and its own Save button. Related settings stay in the same card.
- The actual Tasknest order is Time zone, First-run help, Location & weather, Sick Day Mode, Hydration, Notifications / ntfy, and Fasting. Adapt the order to the other app's features.
## Visual tokens
| Purpose | Light value | Dark value |
| --- | --- | --- |
| Page canvas | `#f7f7f3` | `#151b18` |
| Card surface | `#ffffff` | `#202923` |
| Main text | `#25292e` | `#e8eee9` |
| Muted text | `#6d737a` | `#b8c3bb` |
| Border | `#e6e8e3` | `#38443d` |
| Primary green | `#235943` | Keep green buttons legible on the dark surface |
| Primary hover | `#174333` | A brighter green hover may be used |
| Link/accent in dark mode | — | `#9bd5ae` |
| Positive switch | `#34c76a` | `#34c76a` |
Use **DM Sans** (or a similar clean sans serif) for body text and controls. Use **Fraunces** (or a similar warm serif) for page and card headings. The page should feel calm and spacious, with green as the only strong accent.
## Cards and forms
- Card: **28px** internal padding, **18px** corner radius, a **1px** border, white surface, and a soft shadow equivalent to `0 18px 45px rgba(29,43,37,.08)`. Avoid dense dividers between ordinary fields.
- Card heading: serif, about **1.5rem**, with **7px** bottom margin. Description: muted color and concise copy.
- Form: one vertical grid column with **16px** gaps. Controls and action buttons fill the available card width. Each card saves independently; show confirmation through the app's usual status message.
- Field: label above control with **6px** spacing. Labels are **0.85rem**, bold, and dark gray. Help text is smaller and muted. Input/select minimum height is **42px**, with **9px** rounded corners, **1px** neutral border, and **9px 10px** inner padding.
- Keep field errors beside their controls. Success and failure messages should be visible text, not only a color change.
## Buttons and links
- Primary Save button: full width inside the card form, **46px** minimum height, **19px** horizontal padding, fully rounded pill shape, forest green fill, white bold **0.9rem** text. Hover darkens the green, adds a soft shadow, and lifts by about **1px**.
- Secondary action: same size and pill shape, transparent fill, green text, and a light green border. On hover it fills green and turns white. In dark mode use `#263c2e` fill, `#b9edc8` text, and `#568466` border. Use it for actions such as `Test notification` or `Use my current location`.
- Quiet action: plain, bold green text with an underlined hover/focus treatment. Use sparingly for low emphasis actions such as turning help off.
- Keyboard focus must have a clearly visible outline. Tasknest uses a **3px** green-tinted outline with **3px** offset on buttons.
## Switch rows
Use these for on/off settings, with the native checkbox retained inside a full-row label.
- Row: pale green `#f8fbf8` background, `#e3e9e2` border, **15px** radius, at least **70px** high, **13px 16px** padding, and **18px** gap between text and switch. Hover changes the border/background subtly.
- Left side: bold **0.92rem** setting name and a muted **0.77rem** one-line explanation. Right side: **51 × 31px** rounded track with a **27px** white thumb.
- Off track is `#cfd5d0`; on track is `#34c76a`. The thumb moves **20px**. Keep the entire row tappable and show a visible focus ring on the track when tabbing.
- Dark mode row is `#1b2a20` with `#3a4c3f` border; the off track is `#627168`. Respect reduced-motion preferences by removing thumb/hover transitions.
- A switch changes the form value; the nearby Save button applies it. The interface should make that save step clear.
## Responsive behavior and acceptance
- Stay in one column at all widths. On phones, preserve the **18px** outer gutter and let cards/fields/buttons fill the content width. Long labels may wrap; the switch remains visible on the right.
- Preserve readable contrast and the same card hierarchy in dark mode. Input surfaces are darker than cards; Tasknest uses `#161d19` for dark inputs and `#536159` for their borders.
- Check at a narrow phone width and a desktop width. No horizontal page scrolling; all controls remain tappable. Tab reaches every field, switch, and button in a sensible order. Space toggles switches; Enter or click submits forms. Saved values remain correct after reload.
Source reference: `planner/templates/planner/user_settings.html`, `frontend/src/styles/main.scss`, and `planner/templates/planner/base.html` in this repository.
+1
View File
@@ -0,0 +1 @@
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class FoodConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'food'
+13
View File
@@ -0,0 +1,13 @@
{% extends 'planner/base.html' %}
{% block title %}Food · Tasknest{% endblock %}
{% block content %}
<section class="planner-hero" aria-labelledby="food-heading">
<div>
<p class="eyebrow">Food</p>
<h1 id="food-heading">Food diary</h1>
<p>Food logging is coming soon.</p>
</div>
</section>
{% endblock %}
+9
View File
@@ -0,0 +1,9 @@
from django.urls import path
from . import views
app_name = 'food'
urlpatterns = [
path('', views.diary, name='diary'),
]
+7
View File
@@ -0,0 +1,7 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
@login_required
def diary(request):
return render(request, 'food/diary.html')
+62 -2
View File
@@ -478,8 +478,68 @@ body[data-theme="light"] .hydration-widget__day--partial { color:#704915; backgr
body[data-theme="light"] .hydration-widget__day--goal { color:#245537; background:#d2ead7; }
body[data-theme="light"] .hydration-widget__day--today { outline-color:#537c60; }
body[data-theme="light"] .hydration-widget button:focus-visible, body[data-theme="light"] .hydration-widget summary:focus-visible, body[data-theme="light"] .hydration-widget input:focus-visible { outline-color:#376e49; }
.ntfy-check { display: flex; align-items: center; gap: .6rem; }
.ntfy-check label { margin: 0; }
.settings-switch-row {
border: 1px solid #e3e9e2;
border-radius: 15px;
background: #f8fbf8;
transition: border-color .18s ease, background .18s ease;
&:hover { border-color: #b9d6c1; background: #f3f9f4; }
}
.settings-switch {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
min-height: 70px;
padding: 13px 16px;
cursor: pointer;
}
.settings-switch__copy { display: grid; gap: 2px; min-width: 0; }
.settings-switch__copy strong { color: $ink; font-size: .92rem; line-height: 1.25; }
.settings-switch__copy small { color: $muted; font-size: .77rem; line-height: 1.35; }
.settings-switch input[type='checkbox'] {
position: absolute;
width: 1px;
height: 1px;
margin: 0;
opacity: 0;
}
.settings-switch__track {
position: relative;
flex: 0 0 51px;
width: 51px;
height: 31px;
border-radius: 999px;
background: #cfd5d0;
box-shadow: inset 0 0 0 1px rgba(31, 48, 37, .08);
transition: background .2s ease, box-shadow .2s ease;
&::before {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 27px;
height: 27px;
border-radius: 50%;
background: #fff;
box-shadow: 0 2px 5px rgba(20, 40, 26, .22);
transition: transform .2s ease;
}
}
.settings-switch input:checked + .settings-switch__track { background: #34c76a; }
.settings-switch input:checked + .settings-switch__track::before { transform: translateX(20px); }
.settings-switch input:focus-visible + .settings-switch__track { outline: 3px solid rgba(35, 89, 67, .42); outline-offset: 3px; }
.settings-switch input:disabled + .settings-switch__track { opacity: .5; }
body[data-theme='dark'] .settings-switch-row { border-color: #3a4c3f; background: #1b2a20; }
body[data-theme='dark'] .settings-switch-row:hover { border-color: #568368; background: #213427; }
body[data-theme='dark'] .settings-switch__copy strong { color: #edf5ef; }
body[data-theme='dark'] .settings-switch__copy small { color: #b8c3bb; }
body[data-theme='dark'] .settings-switch__track { background: #627168; }
body[data-theme='dark'] .settings-switch input:checked + .settings-switch__track { background: #34c76a; }
@media (prefers-reduced-motion: reduce) {
.settings-switch-row, .settings-switch__track, .settings-switch__track::before { transition: none; }
}
#ntfy-url { width: 100%; box-sizing: border-box; min-height: 2.8rem; }
.ntfy-result { margin: 0; padding: .75rem; border-radius: .55rem; }
.ntfy-result--success { color: #14532d; background: #d1fae5; }
+1
View File
@@ -23,6 +23,7 @@
<a href="{% url 'planner:task-list' %}">My tasks</a>
<a id="daily-planner-nav" class="{% if onboarding_tour.target == 'daily-planner' %}onboarding-highlight{% endif %}" href="{% url 'planner:daily-planner' %}">Daily planner</a>
<a id="health-nav" class="{% if onboarding_tour.target == 'wellbeing' %}onboarding-highlight{% endif %}" href="{% url 'planner:health' %}">Health</a>
<a href="{% url 'food:diary' %}">Food</a>
<a id="settings-nav" class="{% if onboarding_tour.target == 'settings' %}onboarding-highlight{% endif %}" href="{% url 'planner:user-settings' %}">Settings</a>
<form method="post" action="{% url 'planner:user-settings' %}" class="theme-toggle">{% csrf_token %}<input type="hidden" name="section" value="appearance"><input type="hidden" name="next" value="{{ request.path }}">{% if user_appearance == 'dark' %}<input type="hidden" name="appearance" value="light"><button type="submit" aria-label="Use light mode" title="Use light mode"><span aria-hidden="true">☀</span><span class="sr-only">Use light mode</span></button>{% else %}<input type="hidden" name="appearance" value="dark"><button type="submit" aria-label="Use dark mode" title="Use dark mode"><span aria-hidden="true">☾</span><span class="sr-only">Use dark mode</span></button>{% endif %}</form>
<form method="post" action="{% url 'planner:logout' %}" class="nav-logout">{% csrf_token %}<button type="submit">Log out</button></form>
@@ -6,19 +6,19 @@
<section class="settings-card"><h2>Time zone</h2><p>Dates and displayed times, including fasting, use this time zone. Europe/Amsterdam is the default.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="time-zone">{% for field in time_zone_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save time zone</button></form></section>
<section class="settings-card"><h2>First-run help</h2><p>{% if onboarding_enabled %}The guided tour is ready to continue on your dashboard.{% else %}Help is off. You can run the tour again whenever you want.{% endif %}</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="onboarding"><button class="button" type="submit" name="action" value="restart">Run feature tour</button><button class="text-link" type="submit" name="action" value="disable">Turn help off</button></form></section>
<section class="settings-card"><h2>Location &amp; weather</h2><p>Location is optional and private. It is used only to retrieve your forecast.</p><form method="post" data-geolocation-form>{% csrf_token %}<input type="hidden" name="section" value="location">{% for field in profile_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endfor %}<button class="button button--secondary" type="button" data-use-location>Use my current location</button><span data-location-status role="status"></span><button class="button" type="submit">Save location</button></form></section>
<section class="settings-card"><h2>Sick Day Mode</h2><p>Temporarily defer routine work while you recover.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="sick-day">{% for field in sick_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save Sick Day settings</button></form></section>
<section class="settings-card"><h2>Sick Day Mode</h2><p>Temporarily defer routine work while you recover.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="sick-day">{% for field in sick_form %}{% if field.name == 'enabled' %}<div class="settings-switch-row"><label class="settings-switch"><span class="settings-switch__copy"><strong>Enable Sick Day Mode</strong><small>Give routine tasks a rest while you recover.</small></span>{{ field }}<span class="settings-switch__track" aria-hidden="true"></span></label>{{ field.errors }}</div>{% else %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endif %}{% endfor %}<button class="button" type="submit">Save Sick Day settings</button></form></section>
<section class="settings-card"><h2>Hydration</h2><p>Set your daily water goal.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="hydration">{% for field in hydration_goal_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save water goal</button></form></section>
<section class="settings-card" aria-labelledby="ntfy-title">
<h2 id="ntfy-title">Notifications / ntfy</h2>
<p>Enter your private topic URL, test it, then enable notifications.</p>
<form method="post" data-ntfy-form>{% csrf_token %}<input type="hidden" name="section" value="ntfy">
<div class="form-field">{{ ntfy_form.ntfy_url.label_tag }}{{ ntfy_form.ntfy_url }}{{ ntfy_form.ntfy_url.errors }}</div>
<div class="ntfy-check">{{ ntfy_form.ntfy_enabled }}<label for="{{ ntfy_form.ntfy_enabled.id_for_label }}">Enable ntfy notifications</label></div>
<div class="settings-switch-row"><label class="settings-switch"><span class="settings-switch__copy"><strong>Enable ntfy notifications</strong><small>Send updates to your tested topic.</small></span>{{ ntfy_form.ntfy_enabled }}<span class="settings-switch__track" aria-hidden="true"></span></label>{{ ntfy_form.ntfy_enabled.errors }}</div>
<button class="button button--secondary" type="button" hx-post="{% url 'planner:ntfy-test' %}" hx-include="closest form" hx-target="#ntfy-test-result" hx-swap="innerHTML">Test notification</button>
<div id="ntfy-test-result" role="status" aria-live="polite"></div>
<button class="button" type="submit">Save notification settings</button>
</form>
</section>
<section class="settings-card"><h2>Fasting</h2><form method="post">{% csrf_token %}<input type="hidden" name="section" value="fasting">{% for field in fasting_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save fasting settings</button></form></section>
<section class="settings-card"><h2>Fasting</h2><form method="post">{% csrf_token %}<input type="hidden" name="section" value="fasting">{% for field in fasting_form %}{% if field.name == 'enabled' %}<div class="settings-switch-row"><label class="settings-switch"><span class="settings-switch__copy"><strong>Track fasting</strong><small>Show the daily fasting and eating timer.</small></span>{{ field }}<span class="settings-switch__track" aria-hidden="true"></span></label>{{ field.errors }}</div>{% else %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endif %}{% endfor %}<button class="button" type="submit">Save fasting settings</button></form></section>
</section>
{% endblock %}
+1
View File
@@ -42,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'planner',
'food',
]
MIDDLEWARE = [
+1
View File
@@ -19,5 +19,6 @@ from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('food/', include('food.urls')),
path('', include('planner.urls')),
]