feat(todo): To-Do in the look of the packing list, detail pane always in reach

Rows get the packing list's filled checkbox, priority, due date and list
as quiet badges, and the assignee as an avatar with the name as its
tooltip. The tasks sit in a card whose head names the filter and holds
the sort, Priority or Due date, which moved out of the sidebar; a second
click on the active one goes back to the manual order. The progress card
matches the packing list's.

The detail pane is a card with a box in its head that ticks the task
off, and Delete and Save changes stay in sight: the To-Do view now fills
the space under the Lists bar instead of a fixed height that pushed the
pane's foot off screen. The detail pane and the new-task form share one
set of fields, and a new list is named in a dialog, from the sidebar
and from the form; the dialog moved to shared/NameDialog for both lists.

The To-Do help pictures are re-rendered, the texts that described the
old sidebar and form follow in all 27 languages, and the wiki page is
updated. The phone screens are unchanged.
This commit is contained in:
Maurice
2026-09-25 13:29:06 +02:00
parent dc60f39554
commit 1f79776070
51 changed files with 654 additions and 713 deletions
@@ -2,7 +2,7 @@ import {
CheckCheck, Luggage, Package, FolderPlus, Download, Trash2,
} from 'lucide-react'
import type { PackingState } from './usePackingListPanel'
import PackingNameDialog from './PackingNameDialog'
import NameDialog from '../shared/NameDialog'
export function PackingHeader(S: PackingState) {
const {
@@ -199,7 +199,7 @@ export function PackingHeader(S: PackingState) {
{/* Naming a new list or a template happens in a dialog of its own, not in a
field pushed into the page. */}
<PackingNameDialog
<NameDialog
open={canEdit && addingCategory}
title={t('packing.addCategory')}
placeholder={t('packing.newCategoryPlaceholder')}
@@ -209,7 +209,7 @@ export function PackingHeader(S: PackingState) {
onConfirm={handleAddNewCategory}
onClose={() => { setAddingCategory(false); setNewCatName('') }}
/>
<PackingNameDialog
<NameDialog
open={canEdit && isAdmin && items.length > 0 && showSaveTemplate}
title={t('packing.saveAsTemplate')}
placeholder={t('packing.templateName')}
@@ -502,7 +502,7 @@ describe('TodoListPanel — sidebar', () => {
const done = screen.getByRole('button', { name: /^Done/ });
fireEvent.mouseEnter(done);
expect(done.style.background).toBe('var(--bg-hover)');
expect(done.style.background).toBe('var(--bg-secondary)');
fireEvent.mouseLeave(done);
expect(done.style.background).toBe('transparent');
});
@@ -513,23 +513,27 @@ describe('TodoListPanel — sidebar', () => {
fireEvent.mouseLeave(all);
// 'all' is the active filter, so the hover handlers must leave it alone.
expect(all.style.background).toBe('var(--bg-hover)');
expect(all.style.background).toBe('var(--bg-tertiary)');
});
it('FE-COMP-TODO-032: hovering the priority sort toggles its background only while off', async () => {
it('FE-COMP-TODO-032: the sort track in the list head switches between priority, due date and the manual order', async () => {
const user = userEvent.setup();
render(<TodoListPanel tripId={1} items={[]} />);
const sort = screen.getByRole('button', { name: 'Priority' });
const prio = screen.getByRole('button', { name: 'Priority' });
const due = screen.getByRole('button', { name: 'Due date' });
fireEvent.mouseEnter(sort);
expect(sort.style.background).toBe('var(--bg-hover)');
fireEvent.mouseLeave(sort);
expect(sort.style.background).toBe('transparent');
await user.click(prio);
expect(prio).toHaveAttribute('aria-pressed', 'true');
expect(prio.style.background).toBe('var(--text-primary)');
await user.click(sort);
fireEvent.mouseEnter(sort);
// Active sort keeps its amber tint instead of the neutral hover.
expect(sort.style.background).toBe('rgba(245, 158, 11, 0.07)');
await user.click(due);
expect(prio).toHaveAttribute('aria-pressed', 'false');
expect(due).toHaveAttribute('aria-pressed', 'true');
// A second click on the active one goes back to the manual order.
await user.click(due);
expect(due).toHaveAttribute('aria-pressed', 'false');
expect(due.style.background).toBe('transparent');
});
it('FE-COMP-TODO-033: Escape abandons the new-list input', async () => {
@@ -554,7 +558,7 @@ describe('TodoListPanel — sidebar', () => {
await user.click(screen.getByRole('button', { name: 'Add list' }));
const input = await screen.findByPlaceholderText('List name');
await user.type(input, 'Errands');
fireEvent.click(input.nextElementSibling as HTMLElement);
fireEvent.click(screen.getByRole('button', { name: 'Add' }));
expect(posted).toBe(false);
expect(screen.queryByPlaceholderText('List name')).not.toBeInTheDocument();
@@ -687,11 +691,11 @@ describe('TodoListPanel — detail pane', () => {
);
await openDetail(user);
await user.click(screen.getByRole('button', { name: 'List name' }));
await user.click(within(screen.getByRole('region', { name: 'Task' })).getByRole('button', { name: 'Add list' }));
await user.type(await screen.findByPlaceholderText('List name'), 'Logistics');
await user.keyboard('{Enter}');
// Enter closes the inline editor and the typed list is offered as a new option.
// Enter confirms the name dialog and the typed list is offered as a new option.
expect(screen.queryByPlaceholderText('List name')).not.toBeInTheDocument();
expect(screen.getByText(/^Logistics/)).toBeInTheDocument();
@@ -705,7 +709,7 @@ describe('TodoListPanel — detail pane', () => {
withMembers();
await openDetail(user);
await user.click(screen.getByRole('button', { name: 'List name' }));
await user.click(within(screen.getByRole('region', { name: 'Task' })).getByRole('button', { name: 'Add list' }));
await user.type(await screen.findByPlaceholderText('List name'), 'Logistics');
await user.keyboard('{Escape}');
@@ -725,7 +729,7 @@ describe('TodoListPanel — detail pane', () => {
await user.click(screen.getByText('Plan route'));
await screen.findByText('Task');
const pane = screen.getByText('Task').closest('div[style*="border-left"]') as HTMLElement;
const pane = screen.getByRole('region', { name: 'Task' });
await user.click(within(pane).getByRole('button', { name: 'No list' }));
pickOption('Errands');
@@ -864,7 +868,7 @@ describe('TodoListPanel — new task pane', () => {
await user.type(screen.getByPlaceholderText('Task name'), 'Pack bags');
await user.type(screen.getByPlaceholderText('Description (optional)'), 'rain gear');
await user.click(screen.getByRole('button', { name: 'List name' }));
await user.click(within(screen.getByRole('region', { name: 'New task' })).getByRole('button', { name: 'Add list' }));
await user.type(await screen.findByPlaceholderText('List name'), 'Prep ');
await user.keyboard('{Enter}');
await user.click(screen.getByRole('button', { name: 'P1' }));
@@ -886,7 +890,7 @@ describe('TodoListPanel — new task pane', () => {
const user = userEvent.setup();
await openNew();
await user.click(screen.getByRole('button', { name: 'List name' }));
await user.click(within(screen.getByRole('region', { name: 'New task' })).getByRole('button', { name: 'Add list' }));
await user.type(await screen.findByPlaceholderText('List name'), 'Prep');
await user.keyboard('{Escape}');
@@ -999,7 +1003,7 @@ describe('TodoListPanel — mobile layout', () => {
await user.click(header);
expect(screen.getByText('Save changes')).toBeInTheDocument();
await user.click(header.parentElement!.querySelectorAll('button')[0]);
await user.click(within(screen.getByRole('region', { name: 'Task' })).getByRole('button', { name: 'Close' }));
await waitFor(() => expect(screen.queryByText('Save changes')).not.toBeInTheDocument());
});
@@ -1083,12 +1087,12 @@ describe('TodoListPanel — remaining paths', () => {
const all = screen.getByRole('button', { name: /^All/ });
fireEvent.mouseEnter(all);
expect(all.style.background).toBe('var(--bg-hover)');
expect(all.style.background).toBe('var(--bg-tertiary)');
const sort = screen.getByRole('button', { name: 'Priority' });
await user.click(sort);
fireEvent.mouseLeave(sort);
expect(sort.style.background).toBe('rgba(245, 158, 11, 0.07)');
expect(sort.style.background).toBe('var(--text-primary)');
});
it('FE-COMP-TODO-065: clearing the task name blocks the save', async () => {
@@ -1104,24 +1108,24 @@ describe('TodoListPanel — remaining paths', () => {
expect(put).toBe(false);
});
it('FE-COMP-TODO-066: the check button closes the inline list editor in both panes', async () => {
it('FE-COMP-TODO-066: the name dialog adds a new list in both panes', async () => {
const user = userEvent.setup();
const { rerender } = render(<TodoListPanel tripId={1} items={[buildTodoItem({ id: 40, name: 'Plan route', checked: 0 })]} addItemSignal={0} />);
await user.click(screen.getByText('Plan route'));
await user.click(await screen.findByRole('button', { name: 'List name' }));
await user.click(within(await screen.findByRole('region', { name: 'Task' })).getByRole('button', { name: 'Add list' }));
let input = await screen.findByPlaceholderText('List name');
await user.type(input, 'Logistics');
fireEvent.click(input.nextElementSibling as HTMLElement);
fireEvent.click(screen.getByRole('button', { name: 'Add' }));
expect(screen.queryByPlaceholderText('List name')).not.toBeInTheDocument();
expect(screen.getByText(/^Logistics/)).toBeInTheDocument();
rerender(<TodoListPanel tripId={1} items={[buildTodoItem({ id: 40, name: 'Plan route', checked: 0 })]} addItemSignal={1} />);
await screen.findByText('Create task');
await user.click(screen.getByRole('button', { name: 'List name' }));
await user.click(within(screen.getByRole('region', { name: 'New task' })).getByRole('button', { name: 'Add list' }));
input = await screen.findByPlaceholderText('List name');
await user.type(input, 'Prep');
fireEvent.click(input.nextElementSibling as HTMLElement);
fireEvent.click(screen.getByRole('button', { name: 'Add' }));
expect(screen.queryByPlaceholderText('List name')).not.toBeInTheDocument();
expect(screen.getByText(/^Prep/)).toBeInTheDocument();
});
@@ -1289,3 +1293,23 @@ describe('TodoListPanel — plugin contributions', () => {
expect(screen.getByText('Rainy')).toBeInTheDocument();
});
});
describe('TodoListPanel — detail pane head', () => {
it('FE-COMP-TODO-090: the box in the pane head ticks the task off', async () => {
const user = userEvent.setup();
let body: Record<string, unknown> | null = null;
server.use(http.put('/api/trips/1/todo/60', async ({ request }) => {
body = (await request.json()) as Record<string, unknown>;
return HttpResponse.json({ item: buildTodoItem({ id: 60, name: 'Buy SIM', checked: 1 }) });
}));
render(<TodoListPanel tripId={1} items={[buildTodoItem({ id: 60, name: 'Buy SIM', checked: 0 })]} />);
await user.click(screen.getByText('Buy SIM'));
const box = within(await screen.findByRole('region', { name: 'Task' })).getByRole('button', { name: 'Done' });
expect(box).toHaveAttribute('aria-pressed', 'false');
await user.click(box);
await waitFor(() => expect(body).toMatchObject({ checked: true }));
});
});
+214 -470
View File
@@ -1,33 +1,35 @@
import { Fragment, useState, useMemo, useEffect, useRef } from 'react'
import { avatarSrc } from '../../utils/avatarSrc'
import { Fragment, useState, useEffect, type CSSProperties } from 'react'
import { createPortal } from 'react-dom'
import { useTripStore } from '../../store/tripStore'
import { useCanDo } from '../../store/permissionsStore'
import { useToast } from '../shared/Toast'
import { useTranslation } from '../../i18n'
import { tripsApi } from '../../api/client'
import apiClient from '../../api/client'
import CustomSelect from '../shared/CustomSelect'
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
import { formatDate as fmtDate } from '../../utils/formatters'
import {
CheckSquare, Square, Plus, ChevronRight, Flag,
X, Check, Calendar, User, FolderPlus, AlertCircle, ListChecks, Inbox, CheckCheck, Trash2,
} from 'lucide-react'
import { Check, Plus, Flag, X, Calendar, User, AlertCircle, Inbox, CheckCheck, Trash2 } from 'lucide-react'
import type { TodoItem } from '../../types'
import { KAT_COLORS, PRIO_CONFIG, katColor, type FilterType, type Member } from './todoListModel'
import { katColor, taskInputStyle, type FilterType, type Member, type TaskFieldValues } from './todoListModel'
import { useTodoList } from './useTodoList'
import TodoRow from './TodoRow'
import TodoTaskFields from './TodoTaskFields'
import { usePluginViewContributions, PluginCardFooter } from '../Plugins/PluginContributions'
import EmptyState from '../shared/EmptyState'
import NameDialog from '../shared/NameDialog'
/** The card the list and the detail pane sit in, the packing list's category card. */
const CARD: CSSProperties = {
background: 'var(--bg-card)', border: '1px solid var(--border-secondary)', borderRadius: 16,
display: 'flex', flexDirection: 'column', overflow: 'hidden',
}
const HEAD_BAND: CSSProperties = {
display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px 10px 16px', background: 'var(--bg-tertiary)', flexShrink: 0,
}
// Sidebar filter row. Declared at module level so React keeps the same component
// type across renders — inline it and every re-render remounts the buttons,
// which drops clicks that are already in flight.
function SidebarItem({ id, icon: Icon, label, count, color, active, compact, onSelect }: {
id: string
icon: any
icon: React.ComponentType<{ size?: number; style?: CSSProperties }> | null
label: string
count: number
color?: string
@@ -40,23 +42,23 @@ function SidebarItem({ id, icon: Icon, label, count, color, active, compact, onS
title={compact ? label : undefined}
style={{
display: 'flex', alignItems: 'center', justifyContent: compact ? 'center' : 'flex-start',
gap: compact ? 0 : 8, width: '100%', padding: compact ? '8px 0' : '7px 12px',
border: 'none', borderRadius: 8, cursor: 'pointer', fontFamily: 'inherit', fontSize: 'calc(13px * var(--fs-scale-body, 1))',
background: active ? 'var(--bg-hover)' : 'transparent',
gap: compact ? 0 : 9, width: '100%', padding: compact ? '8px 0' : '8px 12px',
border: 'none', borderRadius: 10, cursor: 'pointer', fontFamily: 'inherit', fontSize: 'calc(13px * var(--fs-scale-body, 1))',
background: active ? 'var(--bg-tertiary)' : 'transparent',
color: active ? 'var(--text-primary)' : 'var(--text-secondary)',
fontWeight: active ? 600 : 400, transition: 'all 0.1s',
fontWeight: active ? 600 : 500, transition: 'all 0.1s',
position: 'relative',
}}
onMouseEnter={e => { if (!active) e.currentTarget.style.background = 'var(--bg-hover)' }}
onMouseEnter={e => { if (!active) e.currentTarget.style.background = 'var(--bg-secondary)' }}
onMouseLeave={e => { if (!active) e.currentTarget.style.background = 'transparent' }}>
{color ? (
<span style={{ width: compact ? 12 : 10, height: compact ? 12 : 10, borderRadius: '50%', background: color, flexShrink: 0 }} />
) : (
) : Icon ? (
<Icon size={compact ? 18 : 15} style={{ flexShrink: 0, opacity: 0.7 }} />
)}
) : null}
{!compact && <span style={{ flex: 1, textAlign: 'left' }}>{label}</span>}
{!compact && count > 0 && (
<span style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', background: 'var(--bg-hover)', borderRadius: 10, padding: '1px 7px', minWidth: 20, textAlign: 'center' }}>
<span style={{ fontSize: 'calc(10.5px * var(--fs-scale-caption, 1))', fontWeight: 700, color: 'var(--text-faint)', background: active ? 'var(--bg-card)' : 'var(--bg-tertiary)', borderRadius: 99, padding: '1px 7px', minWidth: 20, textAlign: 'center' }}>
{count}
</span>
)}
@@ -69,6 +71,14 @@ function SidebarItem({ id, icon: Icon, label, count, color, active, compact, onS
)
}
function SidebarCaption({ children }: { children: React.ReactNode }) {
return (
<div style={{ fontSize: 'calc(10.5px * var(--fs-scale-caption, 1))', fontWeight: 700, color: 'var(--text-faint)', padding: '14px 12px 4px', textTransform: 'uppercase', letterSpacing: '0.05em' }}>
{children}
</div>
)
}
export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tripId: number; items: TodoItem[]; addItemSignal?: number }) {
// Layout component: state/effects/derived/handlers live in useTodoList.
const {
@@ -110,6 +120,7 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
}
const selectFilter = (id: string) => setFilter(id as FilterType)
const pct = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0
// Filter title
const filterTitle = (() => {
@@ -120,125 +131,95 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
return filter
})()
// One segment of the sort track in the list's head band; a second click on the
// active one goes back to the manual order.
const sortSegment = (active: boolean): CSSProperties => ({
display: 'inline-flex', alignItems: 'center', gap: 5, height: 26, padding: isMobile ? '0 9px' : '0 11px', borderRadius: 99,
border: 'none', cursor: 'pointer', fontFamily: 'inherit', fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600,
background: active ? 'var(--text-primary)' : 'transparent', color: active ? 'var(--bg-primary)' : 'var(--text-muted)',
transition: 'all 0.12s',
})
return (
<div style={{ display: 'flex', height: 'calc(100vh - 180px)', minHeight: 400 }}>
<div style={{ display: 'flex', gap: 16, height: '100%', minHeight: 420 }}>
{/* ── Left Sidebar ── */}
<div style={{
width: isMobile ? 52 : 220, flexShrink: 0, borderRight: '1px solid var(--border-faint)',
padding: isMobile ? '12px 6px' : '16px 12px 16px 0', display: 'flex', flexDirection: 'column', gap: 2, overflowY: 'auto',
width: isMobile ? 52 : 220, flexShrink: 0,
display: 'flex', flexDirection: 'column', gap: 2, overflowY: 'auto',
transition: 'width 0.2s',
}}>
{/* Progress Card */}
{!isMobile && <div style={{
margin: '0 0 12px', padding: '14px 14px 12px', borderRadius: 14,
background: 'var(--bg-hover)',
border: '1px solid var(--border-primary)',
boxShadow: '0 1px 2px rgba(0,0,0,0.02)',
}}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4, marginBottom: 8 }}>
<span style={{ fontSize: 'calc(18px * var(--fs-scale-subtitle, 1))', fontWeight: 700, color: 'var(--text-primary)', lineHeight: 1, letterSpacing: '-0.02em' }}>
{totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0}%
</span>
{/* Progress card, the packing list's: done of all, the share, the bar */}
{!isMobile && (
<div style={{ margin: '0 0 8px', padding: '14px 16px', borderRadius: 16, background: 'var(--bg-card)', border: '1px solid var(--border-secondary)' }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
<span style={{ display: 'inline-flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 'calc(22px * var(--fs-scale-title, 1))', fontWeight: 700, color: 'var(--text-primary)', lineHeight: 1, letterSpacing: '-0.02em', fontVariantNumeric: 'tabular-nums' }}>{doneCount}</span>
<span style={{ fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 500, color: 'var(--text-faint)', lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>/{totalCount}</span>
</span>
<span style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 600, padding: '2px 7px', borderRadius: 99, background: 'var(--bg-tertiary)', color: 'var(--text-muted)', fontVariantNumeric: 'tabular-nums' }}>{pct}%</span>
</div>
<div style={{ height: 6, background: 'var(--bg-tertiary)', borderRadius: 99, overflow: 'hidden', marginTop: 12 }}>
<div style={{ height: '100%', width: `${pct}%`, background: 'var(--accent)', borderRadius: 99, transition: 'width 0.3s' }} />
</div>
<div style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', marginTop: 6 }}>
{doneCount} / {totalCount} {t('todo.completed')}
</div>
</div>
<div style={{ height: 4, background: 'var(--border-faint)', borderRadius: 2, overflow: 'hidden', marginBottom: 6 }}>
<div style={{ height: '100%', width: totalCount > 0 ? `${Math.round((doneCount / totalCount) * 100)}%` : '0%', background: '#22c55e', borderRadius: 2, transition: 'width 0.3s' }} />
</div>
<div style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)' }}>
{doneCount} / {totalCount} {t('todo.completed')}
</div>
</div>}
)}
{/* Smart filters */}
{!isMobile && <div style={{ fontSize: 'calc(10px * var(--fs-scale-caption, 1))', fontWeight: 600, color: 'var(--text-faint)', padding: '8px 12px 4px', textTransform: 'uppercase', letterSpacing: '0.05em' }}>
{t('todo.sidebar.tasks')}
</div>}
{!isMobile && <SidebarCaption>{t('todo.sidebar.tasks')}</SidebarCaption>}
<SidebarItem id="all" icon={Inbox} label={t('todo.filter.all')} count={items.filter(i => !i.checked).length} active={filter === 'all'} compact={isMobile} onSelect={selectFilter} />
<SidebarItem id="my" icon={User} label={t('todo.filter.my')} count={myCount} active={filter === 'my'} compact={isMobile} onSelect={selectFilter} />
<SidebarItem id="overdue" icon={AlertCircle} label={t('todo.filter.overdue')} count={overdueCount} active={filter === 'overdue'} compact={isMobile} onSelect={selectFilter} />
<SidebarItem id="done" icon={CheckCheck} label={t('todo.filter.done')} count={doneCount} active={filter === 'done'} compact={isMobile} onSelect={selectFilter} />
{/* Sort by */}
{!isMobile && <div style={{ fontSize: 'calc(10px * var(--fs-scale-caption, 1))', fontWeight: 600, color: 'var(--text-faint)', padding: '16px 12px 4px', textTransform: 'uppercase', letterSpacing: '0.05em' }}>
{t('todo.sidebar.sortBy')}
</div>}
<button type="button" onClick={() => { setSortByDue(false); setSortByPrio(v => !v) }}
title={isMobile ? t('todo.priority') : undefined}
style={{
display: 'flex', alignItems: 'center', justifyContent: isMobile ? 'center' : 'flex-start',
gap: isMobile ? 0 : 8, width: '100%', padding: isMobile ? '8px 0' : '7px 12px',
border: 'none', borderRadius: 8, cursor: 'pointer', fontFamily: 'inherit', fontSize: 'calc(13px * var(--fs-scale-body, 1))',
background: sortByPrio ? '#f59e0b12' : 'transparent',
color: sortByPrio ? '#f59e0b' : 'var(--text-secondary)',
fontWeight: sortByPrio ? 600 : 400, transition: 'all 0.1s',
}}
onMouseEnter={e => { if (!sortByPrio) e.currentTarget.style.background = 'var(--bg-hover)' }}
onMouseLeave={e => { if (!sortByPrio) e.currentTarget.style.background = 'transparent' }}>
<Flag size={isMobile ? 18 : 15} style={{ flexShrink: 0, opacity: 0.7 }} />
{!isMobile && <span style={{ flex: 1, textAlign: 'left' }}>{t('todo.priority')}</span>}
</button>
<button type="button" onClick={() => { setSortByPrio(false); setSortByDue(v => !v) }}
title={isMobile ? t('todo.detail.dueDate') : undefined}
style={{
display: 'flex', alignItems: 'center', justifyContent: isMobile ? 'center' : 'flex-start',
gap: isMobile ? 0 : 8, width: '100%', padding: isMobile ? '8px 0' : '7px 12px',
border: 'none', borderRadius: 8, cursor: 'pointer', fontFamily: 'inherit', fontSize: 'calc(13px * var(--fs-scale-body, 1))',
background: sortByDue ? '#f59e0b12' : 'transparent',
color: sortByDue ? '#f59e0b' : 'var(--text-secondary)',
fontWeight: sortByDue ? 600 : 400, transition: 'all 0.1s',
}}
onMouseEnter={e => { if (!sortByDue) e.currentTarget.style.background = 'var(--bg-hover)' }}
onMouseLeave={e => { if (!sortByDue) e.currentTarget.style.background = 'transparent' }}>
<Calendar size={isMobile ? 18 : 15} style={{ flexShrink: 0, opacity: 0.7 }} />
{!isMobile && <span style={{ flex: 1, textAlign: 'left' }}>{t('todo.detail.dueDate')}</span>}
</button>
{/* Categories */}
{!isMobile && <div style={{ fontSize: 'calc(10px * var(--fs-scale-caption, 1))', fontWeight: 600, color: 'var(--text-faint)', padding: '16px 12px 4px', textTransform: 'uppercase', letterSpacing: '0.05em' }}>
{t('todo.sidebar.categories')}
</div>}
{/* Lists */}
{!isMobile && <SidebarCaption>{t('todo.sidebar.categories')}</SidebarCaption>}
{isMobile && <div style={{ height: 1, background: 'var(--border-faint)', margin: '8px 4px' }} />}
{categories.map(cat => (
<SidebarItem key={cat} id={cat} icon={null} label={cat} count={catCount(cat)} color={katColor(cat, categories)} active={filter === cat} compact={isMobile} onSelect={selectFilter} />
))}
{canEdit && (
addingCategory && !isMobile ? (
<div style={{ display: 'flex', alignItems: 'center', gap: 4, padding: '4px 12px' }}>
<input autoFocus value={newCategoryName} onChange={e => setNewCategoryName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') addCategory(); if (e.key === 'Escape') { setAddingCategory(false); setNewCategoryName('') } }}
placeholder={t('todo.newCategory')}
style={{ flex: 1, fontSize: 'calc(12px * var(--fs-scale-body, 1))', padding: '4px 6px', border: '1px solid var(--border-primary)', borderRadius: 5, background: 'var(--bg-hover)', color: 'var(--text-primary)', fontFamily: 'inherit', minWidth: 0 }} />
<button type="button" onClick={addCategory} style={{ background: 'none', border: 'none', cursor: 'pointer', color: '#22c55e', padding: 2 }}><Check size={13} /></button>
</div>
) : (
<button type="button" onClick={() => setAddingCategory(true)}
title={isMobile ? t('todo.addCategory') : undefined}
style={{ display: 'flex', alignItems: 'center', justifyContent: isMobile ? 'center' : 'flex-start', gap: isMobile ? 0 : 6, padding: isMobile ? '8px 0' : '7px 12px', fontSize: 'calc(12px * var(--fs-scale-body, 1))', color: 'var(--text-faint)', background: 'none', border: 'none', cursor: 'pointer', fontFamily: 'inherit', width: '100%', textAlign: 'left' }}>
<Plus size={isMobile ? 18 : 13} /> {!isMobile && t('todo.addCategory')}
</button>
)
<button type="button" onClick={() => setAddingCategory(true)}
title={isMobile ? t('todo.addCategory') : undefined}
style={{
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: isMobile ? 0 : 6,
margin: '6px 0 0', padding: isMobile ? '8px 0' : '8px 12px', borderRadius: 99, border: '1.5px dashed var(--border-primary)',
fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, color: 'var(--text-faint)', background: 'none', cursor: 'pointer', fontFamily: 'inherit', width: '100%',
}}>
<Plus size={isMobile ? 16 : 13} /> {!isMobile && t('todo.addCategory')}
</button>
)}
</div>
{/* ── Middle: Task List ── */}
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', minWidth: 0 }}>
{/* Header */}
<div style={{ padding: '16px 20px 12px', borderBottom: '1px solid var(--border-faint)' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
<h2 style={{ margin: 0, fontSize: 'calc(22px * var(--fs-scale-title, 1))', fontWeight: 700, color: 'var(--text-primary)', letterSpacing: '-0.02em' }}>
{filterTitle}
</h2>
<span style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))', color: 'var(--text-faint)', background: 'var(--bg-hover)', borderRadius: 6, padding: '2px 8px', fontWeight: 600 }}>
{filtered.length}
</span>
{/* ── Middle: the task list, as a card ── */}
<div style={{ ...CARD, flex: 1, minWidth: 0 }}>
<div style={HEAD_BAND}>
<h2 style={{ margin: 0, fontSize: 'calc(15px * var(--fs-scale-subtitle, 1))', fontWeight: 700, color: 'var(--text-primary)', letterSpacing: '-0.01em', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{filterTitle}
</h2>
<span style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', color: 'var(--text-muted)', background: 'var(--bg-card)', borderRadius: 99, padding: '2px 8px', fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>
{filtered.length}
</span>
<span style={{ flex: 1 }} />
{/* Sort order: priority or due date, neither means the manual order */}
<div role="group" aria-label={t('todo.sidebar.sortBy')} style={{ display: 'inline-flex', alignItems: 'center', gap: 2, padding: 3, borderRadius: 99, background: 'var(--bg-card)', flexShrink: 0 }}>
<button type="button" aria-pressed={sortByPrio} title={t('todo.priority')} onClick={() => { setSortByDue(false); setSortByPrio(v => !v) }} style={sortSegment(sortByPrio)}>
<Flag size={12} />{!isMobile && t('todo.priority')}
</button>
<button type="button" aria-pressed={sortByDue} title={t('todo.detail.dueDate')} onClick={() => { setSortByPrio(false); setSortByDue(v => !v) }} style={sortSegment(sortByDue)}>
<Calendar size={12} />{!isMobile && t('todo.detail.dueDate')}
</button>
</div>
</div>
{/* Task list */}
<div style={{ flex: 1, overflowY: 'auto', padding: '4px 0' }}>
<div style={{ flex: 1, overflowY: 'auto' }}>
{filtered.length === 0 ? <EmptyState scene="tasks" title={t('todo.empty')} /> : (
filtered.map(item => {
filtered.map((item, index) => {
const contributions = contribFor(item.id)
return (
<Fragment key={item.id}>
@@ -250,6 +231,7 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
isSelected={selectedId === item.id}
canEdit={canEdit}
formatDate={formatDate}
divider={index > 0}
onSelect={(id) => { setSelectedId(id); setIsAddingNew(false) }}
onToggle={(id, checked) => toggleTodoItem(tripId, id, checked)}
drag={canReorder ? {
@@ -262,7 +244,7 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
} : undefined}
/>
{contributions.length > 0 && (
<div style={{ padding: '0 20px 8px' }}><PluginCardFooter items={contributions} tripId={tripId} /></div>
<div style={{ padding: '0 16px 8px' }}><PluginCardFooter items={contributions} tripId={tripId} /></div>
)}
</Fragment>
)
@@ -273,54 +255,27 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
{/* ── Right: Detail Pane ── */}
{selectedItem && !isAddingNew && !isMobile && (
<DetailPane
item={selectedItem}
tripId={tripId}
categories={categories}
members={members}
onClose={() => setSelectedId(null)}
/>
<DetailPane item={selectedItem} tripId={tripId} categories={categories} members={members} onClose={() => setSelectedId(null)} />
)}
{selectedItem && !isAddingNew && isMobile && (
<div role="presentation" onClick={e => { if (e.target === e.currentTarget) setSelectedId(null) }}
style={{ position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', justifyContent: 'center', alignItems: 'flex-end', paddingBottom: 'var(--bottom-nav-h)' }}>
<div style={{ width: '100%', maxHeight: '85vh', borderRadius: '16px 16px 0 0', overflow: 'auto' }}
ref={el => { if (el) { const child = el.firstElementChild as HTMLElement; if (child) { child.style.width = '100%'; child.style.borderLeft = 'none'; child.style.borderRadius = '16px 16px 0 0' } } }}>
<DetailPane
item={selectedItem}
tripId={tripId}
categories={categories}
members={members}
onClose={() => setSelectedId(null)}
/>
<div style={{ width: '100%', maxHeight: '85vh', display: 'flex' }}>
<DetailPane variant="sheet" item={selectedItem} tripId={tripId} categories={categories} members={members} onClose={() => setSelectedId(null)} />
</div>
</div>
)}
{isAddingNew && !selectedItem && !isMobile && createPortal(
{isAddingNew && !selectedItem && createPortal(
<div role="presentation" onClick={e => { if (e.target === e.currentTarget) setIsAddingNew(false) }}
className="trek-modal-backdrop"
style={{ position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(15,23,42,0.5)', display: 'flex', justifyContent: 'center', alignItems: 'flex-start', paddingTop: 'calc(var(--nav-h) + 60px)', paddingBottom: 40 }}>
<div style={{ width: 'min(520px, 92vw)', maxHeight: 'calc(100vh - var(--nav-h) - 120px)', overflow: 'auto', borderRadius: 16, boxShadow: '0 20px 60px rgba(0,0,0,0.25)' }}
ref={el => { if (el) { const child = el.firstElementChild as HTMLElement; if (child) { child.style.width = '100%'; child.style.borderLeft = 'none'; child.style.borderRadius = '16px' } } }}>
<NewTaskPane
tripId={tripId}
categories={categories}
members={members}
defaultCategory={typeof filter === 'string' && categories.includes(filter) ? filter : null}
onCreated={(id) => { setIsAddingNew(false); setSelectedId(id) }}
onClose={() => setIsAddingNew(false)}
/>
</div>
</div>,
document.body
)}
{isAddingNew && !selectedItem && isMobile && createPortal(
<div role="presentation" onClick={e => { if (e.target === e.currentTarget) setIsAddingNew(false) }}
className="trek-modal-backdrop"
style={{ position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', justifyContent: 'center', alignItems: 'flex-end', paddingBottom: 'var(--bottom-nav-h)' }}>
<div style={{ width: '100%', maxHeight: '85vh', borderRadius: '16px 16px 0 0', overflow: 'auto' }}
ref={el => { if (el) { const child = el.firstElementChild as HTMLElement; if (child) { child.style.width = '100%'; child.style.borderLeft = 'none'; child.style.borderRadius = '16px 16px 0 0' } } }}>
style={isMobile
? { position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', justifyContent: 'center', alignItems: 'flex-end', paddingBottom: 'var(--bottom-nav-h)' }
: { position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(15,23,42,0.5)', display: 'flex', justifyContent: 'center', alignItems: 'flex-start', paddingTop: 'calc(var(--nav-h) + 60px)', paddingBottom: 40 }}>
<div style={isMobile
? { width: '100%', maxHeight: '85vh', display: 'flex' }
: { width: 'min(520px, 92vw)', maxHeight: 'calc(100vh - var(--nav-h) - 120px)', display: 'flex', boxShadow: '0 20px 60px rgba(0,0,0,0.25)', borderRadius: 16 }}>
<NewTaskPane
variant={isMobile ? 'sheet' : 'dialog'}
tripId={tripId}
categories={categories}
members={members}
@@ -332,17 +287,69 @@ export default function TodoListPanel({ tripId, items, addItemSignal = 0 }: { tr
</div>,
document.body
)}
<NameDialog
open={canEdit && addingCategory}
title={t('todo.addCategory')}
placeholder={t('todo.newCategory')}
confirmLabel={t('common.add')}
value={newCategoryName}
onChange={setNewCategoryName}
onConfirm={addCategory}
onClose={() => { setAddingCategory(false); setNewCategoryName('') }}
/>
</div>
)
}
type PaneVariant = 'side' | 'dialog' | 'sheet'
/** The pane's frame: a card beside the list, a dialog, or a sheet from the bottom on a phone. */
function paneFrame(variant: PaneVariant): CSSProperties {
if (variant === 'side') return { ...CARD, width: 340, flexShrink: 0 }
return { ...CARD, width: '100%', border: 'none', borderRadius: variant === 'sheet' ? '16px 16px 0 0' : 16 }
}
function PaneHead({ title, onClose, lead }: { title: string; onClose: () => void; lead?: React.ReactNode }) {
const { t } = useTranslation()
return (
<div style={HEAD_BAND}>
{lead}
<span style={{ flex: 1, fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 700, color: 'var(--text-primary)' }}>{title}</span>
<button type="button" onClick={onClose} aria-label={t('common.close')} style={{ width: 28, height: 28, borderRadius: 8, background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-faint)', display: 'grid', placeItems: 'center' }}>
<X size={16} />
</button>
</div>
)
}
const nameFieldStyle: CSSProperties = {
width: '100%', fontSize: 'calc(16px * var(--fs-scale-subtitle, 1))', fontWeight: 600, border: 'none', padding: '2px 0',
background: 'transparent', color: 'var(--text-primary)', outline: 'none', fontFamily: 'inherit',
}
const FORM_BODY: CSSProperties = { flex: 1, minHeight: 0, overflowY: 'auto', padding: '16px', display: 'flex', flexDirection: 'column', gap: 16 }
const FOOTER: CSSProperties = { padding: '12px 16px', borderTop: '1px solid var(--border-faint)', display: 'flex', gap: 8, flexShrink: 0, background: 'var(--bg-card)' }
const primaryButton = (enabled: boolean): CSSProperties => ({
flex: 1, padding: '9px 16px', borderRadius: 10, fontSize: 'calc(12.5px * var(--fs-scale-body, 1))', fontWeight: 600,
cursor: enabled ? 'pointer' : 'default', fontFamily: 'inherit', border: 'none',
background: 'var(--accent)', color: 'var(--accent-text)', opacity: enabled ? 1 : 0.4, transition: 'opacity 0.15s',
})
// ── Detail Pane (right side) ──────────────────────────────────────────────
function DetailPane({ item, tripId, categories, members, onClose }: {
/** A task's editable fields as the form holds them: empty strings where the task has nothing. */
function fieldsOf(item: TodoItem): TaskFieldValues {
return {
desc: item.description || '', priority: item.priority || 0, category: item.category || '',
dueDate: item.due_date || '', assignedUserId: item.assigned_user_id,
}
}
function DetailPane({ item, tripId, categories, members, onClose, variant = 'side' }: {
item: TodoItem; tripId: number; categories: string[]; members: Member[];
onClose: () => void;
onClose: () => void; variant?: PaneVariant;
}) {
const { updateTodoItem, deleteTodoItem } = useTripStore()
const { updateTodoItem, deleteTodoItem, toggleTodoItem } = useTripStore()
const trip = useTripStore((s) => s.trip)
const can = useCanDo()
const canEdit = can('packing_edit', trip)
@@ -350,36 +357,30 @@ function DetailPane({ item, tripId, categories, members, onClose }: {
const { t } = useTranslation()
const [name, setName] = useState(item.name)
const [desc, setDesc] = useState(item.description || '')
const [dueDate, setDueDate] = useState(item.due_date || '')
const [category, setCategory] = useState(item.category || '')
const [addingCategory, setAddingCategoryInline] = useState(false)
const [assignedUserId, setAssignedUserId] = useState<number | null>(item.assigned_user_id)
const [priority, setPriority] = useState(item.priority || 0)
const [fields, setFields] = useState<TaskFieldValues>(() => fieldsOf(item))
const [saving, setSaving] = useState(false)
// Sync when selected item changes
useEffect(() => {
setName(item.name)
setDesc(item.description || '')
setDueDate(item.due_date || '')
setCategory(item.category || '')
setAssignedUserId(item.assigned_user_id)
setPriority(item.priority || 0)
setFields({
desc: item.description || '', priority: item.priority || 0, category: item.category || '',
dueDate: item.due_date || '', assignedUserId: item.assigned_user_id,
})
}, [item.id, item.name, item.description, item.due_date, item.category, item.assigned_user_id, item.priority])
const hasChanges = name !== item.name || desc !== (item.description || '') ||
dueDate !== (item.due_date || '') || category !== (item.category || '') ||
assignedUserId !== item.assigned_user_id || priority !== (item.priority || 0)
const hasChanges = name !== item.name || fields.desc !== (item.description || '') ||
fields.dueDate !== (item.due_date || '') || fields.category !== (item.category || '') ||
fields.assignedUserId !== item.assigned_user_id || fields.priority !== (item.priority || 0)
const save = async () => {
if (!name.trim() || !hasChanges) return
setSaving(true)
try {
await updateTodoItem(tripId, item.id, {
name: name.trim(), description: desc || null,
due_date: dueDate || null, category: category || null,
assigned_user_id: assignedUserId, priority,
name: name.trim(), description: fields.desc || null,
due_date: fields.dueDate || null, category: fields.category || null,
assigned_user_id: fields.assignedUserId, priority: fields.priority,
})
} catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.error')) }
setSaving(false)
@@ -392,172 +393,41 @@ function DetailPane({ item, tripId, categories, members, onClose }: {
} catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.error')) }
}
const labelClass = 'block text-xs font-medium text-content-secondary mb-1'
const inputStyle: React.CSSProperties = {
width: '100%', fontSize: 'calc(13px * var(--fs-scale-body, 1))', padding: '8px 10px', border: '1px solid var(--border-primary)',
borderRadius: 8, background: 'var(--bg-primary)', color: 'var(--text-primary)', fontFamily: 'inherit',
}
const done = !!item.checked
const doneBox = (
<button type="button" onClick={() => canEdit && toggleTodoItem(tripId, item.id, !done)} aria-pressed={done} aria-label={t('todo.filter.done')} title={t('todo.filter.done')}
style={{
flexShrink: 0, cursor: canEdit ? 'pointer' : 'default', padding: 0, width: 20, height: 20, borderRadius: 6, display: 'grid', placeItems: 'center',
border: `1.5px solid ${done ? 'var(--accent)' : 'var(--text-faint)'}`, background: done ? 'var(--accent)' : 'transparent', color: 'var(--accent-text)',
}}>
<Check size={12} strokeWidth={3} style={{ opacity: done ? 1 : 0 }} />
</button>
)
return (
<div style={{
width: 320, flexShrink: 0, borderLeft: '1px solid var(--border-faint)',
display: 'flex', flexDirection: 'column', background: 'var(--bg-primary)',
}}>
{/* Header */}
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '16px 20px 12px', borderBottom: '1px solid var(--border-faint)' }}>
<span style={{ fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 700, color: 'var(--text-primary)' }}>{t('todo.detail.title')}</span>
<button type="button" onClick={onClose} style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-faint)', padding: 4 }}>
<X size={16} />
</button>
<div role="region" aria-label={t('todo.detail.title')} style={paneFrame(variant)}>
<PaneHead title={t('todo.detail.title')} onClose={onClose} lead={doneBox} />
<div style={FORM_BODY}>
<input value={name} onChange={e => setName(e.target.value)} disabled={!canEdit}
style={{ ...nameFieldStyle, textDecoration: done ? 'line-through' : 'none', color: done ? 'var(--text-faint)' : 'var(--text-primary)' }}
placeholder={t('todo.namePlaceholder')} />
<TodoTaskFields values={fields} onChange={patch => setFields(f => ({ ...f, ...patch }))} categories={categories} members={members} canEdit={canEdit} />
</div>
{/* Form */}
<div style={{ flex: 1, overflowY: 'auto', padding: '16px 20px', display: 'flex', flexDirection: 'column', gap: 14 }}>
{/* Name */}
<div>
<input value={name} onChange={e => setName(e.target.value)} disabled={!canEdit}
style={{ ...inputStyle, fontSize: 'calc(15px * var(--fs-scale-subtitle, 1))', fontWeight: 600, border: 'none', padding: '4px 0', background: 'transparent' }}
placeholder={t('todo.namePlaceholder')} />
</div>
{/* Description */}
<div>
<label className={labelClass}>{t('todo.detail.description')}</label>
<textarea value={desc} onChange={e => setDesc(e.target.value)} disabled={!canEdit} rows={4}
placeholder={t('todo.descriptionPlaceholder')}
style={{ ...inputStyle, resize: 'vertical', minHeight: 80 }} />
</div>
{/* Priority */}
<div>
<label className={labelClass}>{t('todo.detail.priority')}</label>
<div style={{ display: 'flex', gap: 4 }}>
{[0, 1, 2, 3].map(p => {
const cfg = PRIO_CONFIG[p]
const isActive = priority === p
return (
<button type="button" key={p} onClick={() => canEdit && setPriority(p)}
style={{
flex: 1, padding: '6px 0', borderRadius: 6, fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 600, cursor: canEdit ? 'pointer' : 'default',
fontFamily: 'inherit', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 4,
border: `1px solid ${isActive && cfg ? cfg.color + '40' : 'var(--border-primary)'}`,
background: isActive && cfg ? cfg.color + '12' : 'transparent',
color: isActive && cfg ? cfg.color : isActive ? 'var(--text-primary)' : 'var(--text-faint)',
transition: 'all 0.1s',
}}>
{cfg ? <><Flag size={10} />{cfg.label}</> : t('todo.detail.noPriority')}
</button>
)
})}
</div>
</div>
{/* Category */}
<div>
<label className={labelClass}>{t('todo.detail.category')}</label>
{addingCategory ? (
<div style={{ display: 'flex', gap: 4 }}>
<input
autoFocus
value={category}
onChange={e => setCategory(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') setAddingCategoryInline(false); if (e.key === 'Escape') { setCategory(''); setAddingCategoryInline(false) } }}
placeholder={t('todo.newCategory')}
style={{ flex: 1, fontSize: 'calc(13px * var(--fs-scale-body, 1))', padding: '8px 10px', border: '1px solid var(--border-primary)', borderRadius: 8, background: 'var(--bg-primary)', color: 'var(--text-primary)', fontFamily: 'inherit', outline: 'none' }}
/>
<button type="button" onClick={() => setAddingCategoryInline(false)}
style={{ background: 'var(--bg-hover)', border: '1px solid var(--border-primary)', borderRadius: 8, padding: '0 10px', cursor: 'pointer', color: 'var(--text-primary)' }}>
<Check size={14} />
</button>
</div>
) : (
<div style={{ display: 'flex', gap: 4 }}>
<div style={{ flex: 1, minWidth: 0 }}>
<CustomSelect
value={category}
onChange={v => setCategory(String(v))}
options={[
{ value: '', label: t('todo.noCategory') },
...categories.map(c => ({
value: c, label: c,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(c, categories), display: 'inline-block' }} />,
})),
...(category && !categories.includes(category) ? [{
value: category, label: `${category} (${t('todo.newCategoryLabel') || 'new'})`,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: '#9ca3af', display: 'inline-block' }} />,
}] : []),
]}
placeholder={t('todo.noCategory')}
size="sm"
disabled={!canEdit}
/>
</div>
{canEdit && (
<button type="button" onClick={() => { setCategory(''); setAddingCategoryInline(true) }}
title={t('todo.newCategory')}
style={{ background: 'var(--bg-hover)', border: '1px solid var(--border-primary)', borderRadius: 8, padding: '0 10px', cursor: 'pointer', color: 'var(--text-muted)', fontFamily: 'inherit' }}>
<Plus size={14} />
</button>
)}
</div>
)}
</div>
{/* Due date */}
<div>
<label className={labelClass}>{t('todo.detail.dueDate')}</label>
<CustomDatePicker
value={dueDate}
onChange={v => setDueDate(v)}
/>
</div>
{/* Assigned to */}
<div>
<label className={labelClass}>{t('todo.detail.assignedTo')}</label>
<CustomSelect
value={String(assignedUserId ?? '')}
onChange={v => setAssignedUserId(v ? Number(v) : null)}
options={[
{ value: '', label: t('todo.unassigned'), icon: <User size={14} className="text-content-faint" /> },
...members.map(m => ({
value: String(m.id),
label: m.is_guest ? `${m.username} · ${t('members.guest')}` : m.username,
icon: m.avatar ? (
<img src={avatarSrc(m.avatar)!} style={{ width: 18, height: 18, borderRadius: '50%', objectFit: 'cover' as const }} alt="" />
) : (
<span style={{ width: 18, height: 18, borderRadius: '50%', background: 'var(--border-primary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(10px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', fontWeight: 600 }}>
{m.username.charAt(0).toUpperCase()}
</span>
),
})),
]}
placeholder={t('todo.unassigned')}
size="sm"
disabled={!canEdit}
/>
</div>
</div>
{/* Footer actions */}
{/* Always in sight: the pane scrolls between its head and this foot. */}
{canEdit && (
<div style={{ padding: '12px 20px', borderTop: '1px solid var(--border-faint)', display: 'flex', gap: 8 }}>
<div style={FOOTER}>
<button type="button" onClick={handleDelete}
style={{
flex: 1, padding: '9px 16px', borderRadius: 8, fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
border: '1px solid var(--border-primary)', background: 'transparent', color: 'var(--text-secondary)',
padding: '9px 14px', borderRadius: 10, fontSize: 'calc(12.5px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
border: 'none', background: 'rgba(239,68,68,0.1)', color: '#ef4444',
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 5,
}}>
<Trash2 size={13} />
{t('todo.detail.delete')}
</button>
<button type="button" onClick={save} disabled={!hasChanges || saving}
style={{
flex: 1, padding: '9px 16px', borderRadius: 8, fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: hasChanges ? 'pointer' : 'default', fontFamily: 'inherit',
border: 'none', background: hasChanges ? 'var(--text-primary)' : 'var(--border-faint)',
color: hasChanges ? 'var(--bg-primary)' : 'var(--text-faint)',
transition: 'all 0.15s',
}}>
<button type="button" onClick={save} disabled={!hasChanges || saving} style={primaryButton(hasChanges && !saving)}>
{saving ? '...' : t('todo.detail.save')}
</button>
</div>
@@ -566,36 +436,29 @@ function DetailPane({ item, tripId, categories, members, onClose }: {
)
}
// ── New Task Pane (right side, for creating) ──────────────────────────────
// ── New Task Pane (a dialog on a wide screen, a sheet on a phone) ─────────
function NewTaskPane({ tripId, categories, members, defaultCategory, onCreated, onClose }: {
function NewTaskPane({ tripId, categories, members, defaultCategory, onCreated, onClose, variant = 'dialog' }: {
tripId: number; categories: string[]; members: Member[]; defaultCategory: string | null;
onCreated: (id: number) => void; onClose: () => void;
onCreated: (id: number) => void; onClose: () => void; variant?: PaneVariant;
}) {
const { addTodoItem } = useTripStore()
const toast = useToast()
const { t } = useTranslation()
const [name, setName] = useState('')
const [desc, setDesc] = useState('')
const [dueDate, setDueDate] = useState('')
const [category, setCategory] = useState(defaultCategory || '')
const [addingCategory, setAddingCategoryInline] = useState(false)
const [assignedUserId, setAssignedUserId] = useState<number | null>(null)
const [priority, setPriority] = useState(0)
const [fields, setFields] = useState<TaskFieldValues>({ desc: '', priority: 0, category: defaultCategory || '', dueDate: '', assignedUserId: null })
const [saving, setSaving] = useState(false)
const labelClass = 'block text-xs font-medium text-content-secondary mb-1'
const create = async () => {
if (!name.trim()) return
setSaving(true)
try {
const trimmedCategory = category.trim()
const trimmedCategory = fields.category.trim()
const item = await addTodoItem(tripId, {
name: name.trim(), description: desc || null, priority,
due_date: dueDate || null, category: trimmedCategory || null,
assigned_user_id: assignedUserId,
name: name.trim(), description: fields.desc || null, priority: fields.priority,
due_date: fields.dueDate || null, category: trimmedCategory || null,
assigned_user_id: fields.assignedUserId,
})
if (item?.id) onCreated(item.id)
} catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.error')) }
@@ -603,138 +466,19 @@ function NewTaskPane({ tripId, categories, members, defaultCategory, onCreated,
}
return (
<div style={{
width: 320, flexShrink: 0, borderLeft: '1px solid var(--border-faint)',
display: 'flex', flexDirection: 'column', background: 'var(--bg-primary)',
}}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '16px 20px 12px', borderBottom: '1px solid var(--border-faint)' }}>
<span style={{ fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 700, color: 'var(--text-primary)' }}>{t('todo.newItem')}</span>
<button type="button" onClick={onClose} style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-faint)', padding: 4 }}>
<X size={16} />
</button>
<div role="region" aria-label={t('todo.newItem')} style={paneFrame(variant)}>
<PaneHead title={t('todo.newItem')} onClose={onClose} />
<div style={FORM_BODY}>
<input autoFocus value={name} onChange={e => setName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && name.trim()) create() }}
style={{ ...taskInputStyle, fontSize: 'calc(15px * var(--fs-scale-subtitle, 1))', fontWeight: 600 }}
placeholder={t('todo.namePlaceholder')} />
<TodoTaskFields values={fields} onChange={patch => setFields(f => ({ ...f, ...patch }))} categories={categories} members={members} />
</div>
<div style={{ flex: 1, overflowY: 'auto', padding: '16px 20px', display: 'flex', flexDirection: 'column', gap: 14 }}>
<div>
<input autoFocus value={name} onChange={e => setName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && name.trim()) create() }}
style={{ width: '100%', fontSize: 'calc(15px * var(--fs-scale-subtitle, 1))', fontWeight: 600, border: 'none', padding: '4px 0', background: 'transparent', color: 'var(--text-primary)', outline: 'none', fontFamily: 'inherit' }}
placeholder={t('todo.namePlaceholder')} />
</div>
<div>
<label className={labelClass}>{t('todo.detail.description')}</label>
<textarea value={desc} onChange={e => setDesc(e.target.value)} rows={4}
placeholder={t('todo.descriptionPlaceholder')}
style={{ width: '100%', fontSize: 'calc(13px * var(--fs-scale-body, 1))', padding: '8px 10px', border: '1px solid var(--border-primary)', borderRadius: 8, background: 'var(--bg-primary)', color: 'var(--text-primary)', fontFamily: 'inherit', resize: 'vertical', minHeight: 80 }} />
</div>
<div>
<label className={labelClass}>{t('todo.detail.category')}</label>
{addingCategory ? (
<div style={{ display: 'flex', gap: 4 }}>
<input
autoFocus
value={category}
onChange={e => setCategory(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') setAddingCategoryInline(false); if (e.key === 'Escape') { setCategory(''); setAddingCategoryInline(false) } }}
placeholder={t('todo.newCategory')}
style={{ flex: 1, fontSize: 'calc(13px * var(--fs-scale-body, 1))', padding: '8px 10px', border: '1px solid var(--border-primary)', borderRadius: 8, background: 'var(--bg-primary)', color: 'var(--text-primary)', fontFamily: 'inherit', outline: 'none' }}
/>
<button type="button" onClick={() => setAddingCategoryInline(false)}
style={{ background: 'var(--bg-hover)', border: '1px solid var(--border-primary)', borderRadius: 8, padding: '0 10px', cursor: 'pointer', color: 'var(--text-primary)' }}>
<Check size={14} />
</button>
</div>
) : (
<div style={{ display: 'flex', gap: 4 }}>
<div style={{ flex: 1, minWidth: 0 }}>
<CustomSelect
value={category}
onChange={v => setCategory(String(v))}
options={[
{ value: '', label: t('todo.noCategory') },
...categories.map(c => ({
value: c, label: c,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(c, categories), display: 'inline-block' }} />,
})),
...(category && !categories.includes(category) ? [{
value: category, label: `${category} (${t('todo.newCategoryLabel') || 'new'})`,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: '#9ca3af', display: 'inline-block' }} />,
}] : []),
]}
placeholder={t('todo.noCategory')}
size="sm"
/>
</div>
<button type="button" onClick={() => { setCategory(''); setAddingCategoryInline(true) }}
title={t('todo.newCategory')}
style={{ background: 'var(--bg-hover)', border: '1px solid var(--border-primary)', borderRadius: 8, padding: '0 10px', cursor: 'pointer', color: 'var(--text-muted)', fontFamily: 'inherit' }}>
<Plus size={14} />
</button>
</div>
)}
</div>
<div>
<label className={labelClass}>{t('todo.detail.priority')}</label>
<div style={{ display: 'flex', gap: 4 }}>
{[0, 1, 2, 3].map(p => {
const cfg = PRIO_CONFIG[p]
const isActive = priority === p
return (
<button type="button" key={p} onClick={() => setPriority(p)}
style={{
flex: 1, padding: '6px 0', borderRadius: 6, fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 600, cursor: 'pointer',
fontFamily: 'inherit', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 4,
border: `1px solid ${isActive && cfg ? cfg.color + '40' : 'var(--border-primary)'}`,
background: isActive && cfg ? cfg.color + '12' : 'transparent',
color: isActive && cfg ? cfg.color : isActive ? 'var(--text-primary)' : 'var(--text-faint)',
transition: 'all 0.1s',
}}>
{cfg ? <><Flag size={10} />{cfg.label}</> : t('todo.detail.noPriority')}
</button>
)
})}
</div>
</div>
<div>
<label className={labelClass}>{t('todo.detail.dueDate')}</label>
<CustomDatePicker value={dueDate} onChange={v => setDueDate(v)} />
</div>
<div>
<label className={labelClass}>{t('todo.detail.assignedTo')}</label>
<CustomSelect
value={String(assignedUserId ?? '')}
onChange={v => setAssignedUserId(v ? Number(v) : null)}
options={[
{ value: '', label: t('todo.unassigned'), icon: <User size={14} className="text-content-faint" /> },
...members.map(m => ({
value: String(m.id), label: m.username,
icon: m.avatar ? (
<img src={avatarSrc(m.avatar)!} style={{ width: 18, height: 18, borderRadius: '50%', objectFit: 'cover' as const }} alt="" />
) : (
<span style={{ width: 18, height: 18, borderRadius: '50%', background: 'var(--border-primary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(10px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', fontWeight: 600 }}>
{m.username.charAt(0).toUpperCase()}
</span>
),
})),
]}
placeholder={t('todo.unassigned')}
size="sm"
/>
</div>
</div>
<div style={{ padding: '12px 20px', borderTop: '1px solid var(--border-faint)' }}>
<button type="button" onClick={create} disabled={!name.trim() || saving}
style={{
width: '100%', padding: '9px 16px', borderRadius: 8, fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: name.trim() ? 'pointer' : 'default', fontFamily: 'inherit',
border: 'none', background: name.trim() ? 'var(--text-primary)' : 'var(--border-faint)',
color: name.trim() ? 'var(--bg-primary)' : 'var(--text-faint)', transition: 'all 0.15s',
}}>
<div style={FOOTER}>
<button type="button" onClick={create} disabled={!name.trim() || saving} style={primaryButton(!!name.trim() && !saving)}>
{saving ? '...' : t('todo.detail.create')}
</button>
</div>
+2 -1
View File
@@ -143,7 +143,8 @@ describe('TodoRow', () => {
it('FE-W4TDR-014: renders the assignee avatar for a member with a picture', () => {
const { container } = setup(todo({ assigned_user_id: 1 } as Partial<TodoItem>))
expect(screen.getByText('ada')).toBeInTheDocument()
// The assignee is an avatar; the name is its tooltip and label.
expect(screen.getByTitle('ada')).toHaveAttribute('aria-label', 'ada')
expect(container.querySelector('img')).toHaveAttribute('src', '/uploads/avatars/ada.png')
})
+57 -57
View File
@@ -1,11 +1,19 @@
import { CheckSquare, Square, ChevronRight, Flag, Calendar, GripVertical, UserRound } from 'lucide-react'
import type { CSSProperties } from 'react'
import { Check, ChevronRight, Flag, Calendar, GripVertical, UserRound } from 'lucide-react'
import { avatarSrc } from '../../utils/avatarSrc'
import type { TodoItem } from '../../types'
import { katColor, PRIO_CONFIG, type Member } from './todoListModel'
/** A quiet pill for the row's facts: filled, no frame, the packing list's badge. */
const badge: CSSProperties = {
fontSize: 'calc(10.5px * var(--fs-scale-caption, 1))', display: 'inline-flex', alignItems: 'center', gap: 4,
padding: '2px 8px', borderRadius: 99, fontWeight: 600,
color: 'var(--text-muted)', background: 'var(--bg-tertiary)',
}
/** A single task row in the todo list. Pure presentation; all behaviour is
* delegated to onSelect/onToggle so TodoListPanel stays a layout component. */
export default function TodoRow({ item, members, categories, today, isSelected, canEdit, formatDate, onSelect, onToggle, drag }: {
export default function TodoRow({ item, members, categories, today, isSelected, canEdit, formatDate, onSelect, onToggle, divider = false, drag }: {
item: TodoItem
members: Member[]
categories: string[]
@@ -15,6 +23,8 @@ export default function TodoRow({ item, members, categories, today, isSelected,
formatDate: (d: string) => string
onSelect: (id: number | null) => void
onToggle: (id: number, checked: boolean) => void
/** Draws the hairline above the row; the list leaves it off its first row. */
divider?: boolean
// Drag-to-reorder (#969); only provided when manual ordering is active.
drag?: {
isDragging: boolean
@@ -30,6 +40,7 @@ export default function TodoRow({ item, members, categories, today, isSelected,
const isOverdue = item.due_date && !done && item.due_date < today
const catColor = item.category ? katColor(item.category, categories) : null
const canDrag = canEdit && !!drag
const prio = item.priority > 0 ? PRIO_CONFIG[item.priority] : undefined
return (
<div key={item.id}
@@ -53,14 +64,14 @@ export default function TodoRow({ item, members, categories, today, isSelected,
onDragLeave={canDrag ? (e => { if (!e.currentTarget.contains(e.relatedTarget as Node)) drag!.onOver(-1) }) : undefined}
onDrop={canDrag ? (e => { e.preventDefault(); e.stopPropagation(); drag!.onDrop(item.id) }) : undefined}
style={{
display: 'flex', alignItems: 'center', gap: 10, padding: '10px 20px',
borderBottom: '1px solid var(--border-faint)', cursor: 'pointer',
background: isSelected ? 'var(--bg-hover)' : 'transparent',
display: 'flex', alignItems: 'center', gap: 10, padding: '11px 14px', position: 'relative',
borderTop: divider ? '1px solid var(--border-faint)' : 'none', cursor: 'pointer',
background: isSelected ? 'var(--bg-secondary)' : 'transparent',
boxShadow: drag?.isOver ? 'inset 3px 0 0 0 var(--accent)' : isSelected ? 'inset 3px 0 0 0 var(--text-primary)' : 'none',
opacity: drag?.isDragging ? 0.4 : 1,
boxShadow: drag?.isOver ? 'inset 3px 0 0 0 var(--accent)' : 'none',
transition: 'background 0.1s, opacity 0.15s',
}}
onMouseEnter={e => { if (!isSelected) e.currentTarget.style.background = 'rgba(0,0,0,0.02)' }}
onMouseEnter={e => { if (!isSelected) e.currentTarget.style.background = 'var(--bg-secondary)' }}
onMouseLeave={e => { if (!isSelected) e.currentTarget.style.background = 'transparent' }}>
{canDrag && (
@@ -72,23 +83,29 @@ export default function TodoRow({ item, members, categories, today, isSelected,
onClick={e => e.stopPropagation()}
onDragStart={e => { e.stopPropagation(); e.dataTransfer.effectAllowed = 'move'; drag!.onStart(item.id) }}
onDragEnd={() => drag!.onEnd()}
style={{ cursor: 'grab', display: 'flex', alignItems: 'center', color: 'var(--text-faint)', flexShrink: 0, marginLeft: -6 }}
style={{ cursor: 'grab', display: 'flex', alignItems: 'center', color: 'var(--text-faint)', flexShrink: 0, marginLeft: -4, opacity: 0.6 }}
>
<GripVertical size={14} />
<GripVertical size={13} />
</div>
)}
{/* Checkbox */}
{/* The packing list's box: filled with the accent once done, an outline until then. */}
<button type="button" onClick={e => { e.stopPropagation(); if (canEdit) onToggle(item.id, !done) }}
style={{ background: 'none', border: 'none', cursor: canEdit ? 'pointer' : 'default', padding: 0, flexShrink: 0,
color: done ? '#22c55e' : 'var(--border-primary)' }}>
{done ? <CheckSquare size={18} /> : <Square size={18} />}
aria-pressed={done}
style={{
flexShrink: 0, cursor: canEdit ? 'pointer' : 'default', padding: 0, width: 20, height: 20, borderRadius: 6,
display: 'grid', placeItems: 'center',
border: `1.5px solid ${done ? 'var(--accent)' : 'var(--text-faint)'}`,
background: done ? 'var(--accent)' : 'transparent', color: 'var(--accent-text)',
transition: 'background 180ms ease, border-color 180ms ease',
}}>
<Check size={12} strokeWidth={3} style={{ opacity: done ? 1 : 0, transform: done ? 'scale(1)' : 'scale(0.5)', transition: 'opacity 180ms ease, transform 200ms ease' }} />
</button>
{/* Content */}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{
fontSize: 'calc(14px * var(--fs-scale-body, 1))', color: done ? 'var(--text-faint)' : 'var(--text-primary)',
fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 500, color: done ? 'var(--text-faint)' : 'var(--text-primary)',
textDecoration: done ? 'line-through' : 'none', lineHeight: 1.4,
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
}}>
@@ -100,66 +117,49 @@ export default function TodoRow({ item, members, categories, today, isSelected,
{item.description}
</div>
)}
{/* Inline badges */}
{!!(item.priority || item.due_date || catColor || assignedUser) && (
<div style={{ display: 'flex', gap: 5, marginTop: 5, flexWrap: 'wrap' }}>
{item.priority > 0 && PRIO_CONFIG[item.priority] && (
<span style={{
fontSize: 'calc(10px * var(--fs-scale-caption, 1))', display: 'inline-flex', alignItems: 'center', gap: 3,
padding: '2px 7px', borderRadius: 5, fontWeight: 600,
color: PRIO_CONFIG[item.priority].color,
background: `${PRIO_CONFIG[item.priority].color}10`,
border: `1px solid ${PRIO_CONFIG[item.priority].color}25`,
}}>
<Flag size={9} />{PRIO_CONFIG[item.priority].label}
{/* Priority, date and list as quiet badges */}
{!!(prio || item.due_date || catColor) && (
<div style={{ display: 'flex', gap: 5, marginTop: 6, flexWrap: 'wrap' }}>
{prio && (
<span style={{ ...badge, color: prio.color, background: `color-mix(in srgb, ${prio.color} 12%, transparent)` }}>
<Flag size={9} />{prio.label}
</span>
)}
{item.due_date && (
<span style={{
fontSize: 'calc(10px * var(--fs-scale-caption, 1))', display: 'inline-flex', alignItems: 'center', gap: 3,
padding: '2px 7px', borderRadius: 5, fontWeight: 500,
color: isOverdue ? '#ef4444' : 'var(--text-secondary)',
background: isOverdue ? 'rgba(239,68,68,0.08)' : 'var(--bg-hover)',
border: `1px solid ${isOverdue ? 'rgba(239,68,68,0.15)' : 'var(--border-faint)'}`,
...badge,
color: isOverdue ? '#ef4444' : 'var(--text-muted)',
background: isOverdue ? 'rgba(239,68,68,0.1)' : 'var(--bg-tertiary)',
}}>
<Calendar size={9} />{formatDate(item.due_date)}
</span>
)}
{catColor && (
<span style={{
fontSize: 'calc(10px * var(--fs-scale-caption, 1))', display: 'inline-flex', alignItems: 'center', gap: 4,
padding: '2px 7px', borderRadius: 5, fontWeight: 500,
color: 'var(--text-secondary)', background: 'var(--bg-hover)',
border: '1px solid var(--border-faint)',
}}>
<span style={badge}>
<span style={{ width: 6, height: 6, borderRadius: '50%', background: catColor, flexShrink: 0 }} />
{item.category}
</span>
)}
{assignedUser && (
<span style={{
fontSize: 'calc(10px * var(--fs-scale-caption, 1))', display: 'inline-flex', alignItems: 'center', gap: 4,
padding: '2px 7px', borderRadius: 5, fontWeight: 500,
color: 'var(--text-secondary)', background: 'var(--bg-hover)',
border: '1px solid var(--border-faint)',
}}>
{assignedUser.avatar ? (
<img src={avatarSrc(assignedUser.avatar)!} style={{ width: 13, height: 13, borderRadius: '50%', objectFit: 'cover' }} alt="" />
) : (
<span style={{ width: 13, height: 13, borderRadius: '50%', background: 'var(--border-primary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(7px * var(--fs-scale-caption, 1))', color: 'var(--text-faint)', fontWeight: 700 }}>
{assignedUser.username.charAt(0).toUpperCase()}
</span>
)}
{assignedUser.is_guest && <UserRound size={11} style={{ opacity: 0.7 }} />}
{assignedUser.username}
</span>
)}
</div>
)}
</div>
{/* Chevron */}
<ChevronRight size={16} color="var(--text-faint)" style={{ flexShrink: 0, opacity: 0.4 }} />
{/* Who does it, as an avatar: the name is its tooltip and label. */}
{assignedUser && (
<span title={assignedUser.username} aria-label={assignedUser.username}
style={{ display: 'inline-flex', alignItems: 'center', gap: 3, flexShrink: 0 }}>
{assignedUser.avatar ? (
<img src={avatarSrc(assignedUser.avatar)!} style={{ width: 22, height: 22, borderRadius: '50%', objectFit: 'cover' }} alt="" />
) : (
<span style={{ width: 22, height: 22, borderRadius: '50%', background: 'var(--bg-tertiary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(10px * var(--fs-scale-caption, 1))', color: 'var(--text-muted)', fontWeight: 700 }}>
{assignedUser.username.charAt(0).toUpperCase()}
</span>
)}
{assignedUser.is_guest && <UserRound size={11} style={{ color: 'var(--text-faint)' }} />}
</span>
)}
<ChevronRight size={15} color="var(--text-faint)" style={{ flexShrink: 0, opacity: isSelected ? 0.8 : 0.35 }} />
</div>
)
}
@@ -0,0 +1,145 @@
import { useState } from 'react'
import { Flag, Plus, User } from 'lucide-react'
import { useTranslation } from '../../i18n'
import { avatarSrc } from '../../utils/avatarSrc'
import CustomSelect from '../shared/CustomSelect'
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
import NameDialog from '../shared/NameDialog'
import { PRIO_CONFIG, katColor, taskInputStyle, taskLabelClass, type Member, type TaskFieldValues } from './todoListModel'
interface TodoTaskFieldsProps {
values: TaskFieldValues
onChange: (patch: Partial<TaskFieldValues>) => void
categories: string[]
members: Member[]
canEdit?: boolean
}
/**
* The fields a task is made of, shared by the detail pane and the new-task
* dialog so both read and behave the same: description, priority as one
* segmented track, the list (a new one is named in a dialog), the due date and
* who does it.
*/
export default function TodoTaskFields({ values, onChange, categories, members, canEdit = true }: TodoTaskFieldsProps) {
const { t } = useTranslation()
const [namingList, setNamingList] = useState(false)
const [listName, setListName] = useState('')
const { desc, priority, category, dueDate, assignedUserId } = values
const confirmList = () => {
const name = listName.trim()
if (!name) return
onChange({ category: name })
setNamingList(false)
setListName('')
}
return (
<>
<div>
<label className={taskLabelClass}>{t('todo.detail.description')}</label>
<textarea value={desc} onChange={e => onChange({ desc: e.target.value })} disabled={!canEdit} rows={4}
placeholder={t('todo.descriptionPlaceholder')}
style={{ ...taskInputStyle, resize: 'vertical', minHeight: 84 }} />
</div>
<div>
<label className={taskLabelClass}>{t('todo.detail.priority')}</label>
<div style={{ display: 'flex', gap: 2, padding: 3, borderRadius: 11, background: 'var(--bg-tertiary)' }}>
{[0, 1, 2, 3].map(p => {
const cfg = PRIO_CONFIG[p]
const isActive = priority === p
return (
<button type="button" key={p} onClick={() => canEdit && onChange({ priority: p })} aria-pressed={isActive}
style={{
flex: 1, height: 28, borderRadius: 8, border: 'none', cursor: canEdit ? 'pointer' : 'default',
fontSize: 'calc(11.5px * var(--fs-scale-caption, 1))', fontWeight: 600, fontFamily: 'inherit',
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 4,
background: isActive ? 'var(--bg-card)' : 'transparent',
boxShadow: isActive ? '0 1px 2px rgba(0,0,0,0.1)' : 'none',
color: isActive ? (cfg ? cfg.color : 'var(--text-primary)') : 'var(--text-faint)',
transition: 'all 0.12s',
}}>
{cfg ? <><Flag size={10} />{cfg.label}</> : t('todo.detail.noPriority')}
</button>
)
})}
</div>
</div>
<div>
<label className={taskLabelClass}>{t('todo.detail.category')}</label>
<div style={{ display: 'flex', gap: 6 }}>
<div style={{ flex: 1, minWidth: 0 }}>
<CustomSelect
value={category}
onChange={v => onChange({ category: String(v) })}
options={[
{ value: '', label: t('todo.noCategory') },
...categories.map(c => ({
value: c, label: c,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(c, categories), display: 'inline-block' }} />,
})),
...(category && !categories.includes(category) ? [{
value: category, label: `${category} (${t('todo.newCategoryLabel')})`,
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(category, categories), display: 'inline-block' }} />,
}] : []),
]}
placeholder={t('todo.noCategory')}
size="sm"
disabled={!canEdit}
/>
</div>
{canEdit && (
<button type="button" onClick={() => setNamingList(true)} title={t('todo.addCategory')} aria-label={t('todo.addCategory')}
style={{ width: 36, flexShrink: 0, background: 'var(--bg-tertiary)', border: 'none', borderRadius: 10, cursor: 'pointer', color: 'var(--text-muted)', display: 'grid', placeItems: 'center' }}>
<Plus size={14} />
</button>
)}
</div>
</div>
<div>
<label className={taskLabelClass}>{t('todo.detail.dueDate')}</label>
<CustomDatePicker value={dueDate} onChange={v => onChange({ dueDate: v })} />
</div>
<div>
<label className={taskLabelClass}>{t('todo.detail.assignedTo')}</label>
<CustomSelect
value={String(assignedUserId ?? '')}
onChange={v => onChange({ assignedUserId: v ? Number(v) : null })}
options={[
{ value: '', label: t('todo.unassigned'), icon: <User size={14} className="text-content-faint" /> },
...members.map(m => ({
value: String(m.id),
label: m.is_guest ? `${m.username} · ${t('members.guest')}` : m.username,
icon: m.avatar ? (
<img src={avatarSrc(m.avatar)!} style={{ width: 18, height: 18, borderRadius: '50%', objectFit: 'cover' as const }} alt="" />
) : (
<span style={{ width: 18, height: 18, borderRadius: '50%', background: 'var(--bg-tertiary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(10px * var(--fs-scale-caption, 1))', color: 'var(--text-muted)', fontWeight: 700 }}>
{m.username.charAt(0).toUpperCase()}
</span>
),
})),
]}
placeholder={t('todo.unassigned')}
size="sm"
disabled={!canEdit}
/>
</div>
<NameDialog
open={namingList}
title={t('todo.addCategory')}
placeholder={t('todo.newCategory')}
confirmLabel={t('common.add')}
value={listName}
onChange={setListName}
onConfirm={confirmList}
onClose={() => { setNamingList(false); setListName('') }}
/>
</>
)
}
@@ -1,3 +1,5 @@
import type { CSSProperties } from 'react'
// Pure constants + helpers + types for the todo list. No React, no side effects.
export const KAT_COLORS = [
@@ -22,3 +24,19 @@ export function katColor(kat: string, allCategories: string[]) {
export type FilterType = 'all' | 'my' | 'overdue' | 'done' | string
export interface Member { id: number; username: string; avatar: string | null; is_guest?: boolean }
/** A task's editable fields as its form holds them: empty strings where the task has nothing. */
export interface TaskFieldValues {
desc: string
priority: number
category: string
dueDate: string
assignedUserId: number | null
}
/** The label and field look of the task form, shared by the detail pane and the new-task dialog. */
export const taskLabelClass = 'mb-1.5 block text-caption font-semibold text-content-muted'
export const taskInputStyle: CSSProperties = {
width: '100%', fontSize: 'calc(13px * var(--fs-scale-body, 1))', padding: '9px 11px', border: '1px solid var(--border-primary)',
borderRadius: 10, background: 'var(--bg-input)', color: 'var(--text-primary)', fontFamily: 'inherit', outline: 'none',
}
@@ -1,21 +1,21 @@
// FE-PACKNAME-001 to FE-PACKNAME-004
// FE-NAMEDLG-001 to FE-NAMEDLG-004
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '../../../tests/helpers/render'
import PackingNameDialog from './PackingNameDialog'
import NameDialog from './NameDialog'
function setup(value: string, open = true) {
const onChange = vi.fn()
const onConfirm = vi.fn()
const onClose = vi.fn()
render(
<PackingNameDialog open={open} title="Add list" placeholder="List name" confirmLabel="Add"
<NameDialog open={open} title="Add list" placeholder="List name" confirmLabel="Add"
value={value} onChange={onChange} onConfirm={onConfirm} onClose={onClose} />,
)
return { onChange, onConfirm, onClose }
}
describe('PackingNameDialog', () => {
it('FE-PACKNAME-001: asks for the name under its title, confirm waiting for one', () => {
describe('NameDialog', () => {
it('FE-NAMEDLG-001: asks for the name under its title, confirm waiting for one', () => {
const { onChange } = setup('')
expect(screen.getByText('Add list')).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Add' })).toBeDisabled()
@@ -24,14 +24,14 @@ describe('PackingNameDialog', () => {
expect(onChange).toHaveBeenCalledWith('Rain kit')
})
it('FE-PACKNAME-002: Enter and the button confirm a typed name', () => {
it('FE-NAMEDLG-002: Enter and the button confirm a typed name', () => {
const { onConfirm } = setup('Rain kit')
fireEvent.keyDown(screen.getByPlaceholderText('List name'), { key: 'Enter' })
fireEvent.click(screen.getByRole('button', { name: 'Add' }))
expect(onConfirm).toHaveBeenCalledTimes(2)
})
it('FE-PACKNAME-003: Enter on a blank name does nothing, Cancel closes', () => {
it('FE-NAMEDLG-003: Enter on a blank name does nothing, Cancel closes', () => {
const { onConfirm, onClose } = setup(' ')
fireEvent.keyDown(screen.getByPlaceholderText('List name'), { key: 'Enter' })
expect(onConfirm).not.toHaveBeenCalled()
@@ -40,7 +40,7 @@ describe('PackingNameDialog', () => {
expect(onClose).toHaveBeenCalledTimes(1)
})
it('FE-PACKNAME-004: stays out of the page while closed', () => {
it('FE-NAMEDLG-004: stays out of the page while closed', () => {
setup('', false)
expect(screen.queryByPlaceholderText('List name')).toBeNull()
})
@@ -1,7 +1,7 @@
import Modal from '../shared/Modal'
import Modal from './Modal'
import { useTranslation } from '../../i18n'
interface PackingNameDialogProps {
interface NameDialogProps {
open: boolean
title: string
placeholder: string
@@ -17,7 +17,7 @@ interface PackingNameDialogProps {
* It takes the name in the middle of the screen instead of pushing a field
* into the page; Enter confirms and Esc (from the modal) cancels.
*/
export default function PackingNameDialog({ open, title, placeholder, confirmLabel, value, onChange, onConfirm, onClose }: PackingNameDialogProps) {
export default function NameDialog({ open, title, placeholder, confirmLabel, value, onChange, onConfirm, onClose }: NameDialogProps) {
const { t } = useTranslation()
const ready = value.trim().length > 0
return (