fix(mobile): group checklist progress and filtering

Move packed-item visibility into the packing actions menu. Share an accessible progress display with To-Do and keep count badges only on filters with matching tasks.
This commit is contained in:
Maurice
2026-12-04 12:14:12 +01:00
parent 35b3ff0c9e
commit 908e4e1f8b
33 changed files with 98 additions and 50 deletions
@@ -1,4 +1,6 @@
import { Check, Minus } from 'lucide-react';
import { Check, CircleCheck, Minus } from 'lucide-react';
import { useId } from 'react';
import MProgress from '../../../components/MProgress';
/** Checkbox-sized icon in a full touch target, separate from the row that opens details. */
export default function MChecklistCheck({
@@ -34,3 +36,18 @@ export default function MChecklistCheck({
</button>
);
}
export function MChecklistProgress({ label, done, total }: { label: string; done: number; total: number }) {
const id = useId();
return (
<div className="min-w-0 flex-1 space-y-1.5">
<div id={id} className="flex items-center gap-1.5 text-caption font-medium tabular-nums text-m-muted">
<CircleCheck size={14} className="flex-none" aria-hidden />
<span>{label}</span>
</div>
<div role="progressbar" aria-labelledby={id} aria-valuemax={total} aria-valuenow={done}>
<MProgress value={(done / total) * 100} />
</div>
</div>
);
}
@@ -3,7 +3,7 @@ import { useMemo, useState, type ReactNode } from 'react'
import { selectionHaptic } from '../../../../native/haptics'
import type { LucideIcon } from 'lucide-react'
import {
Briefcase, Check, CheckCheck, ChevronDown, ChevronLeft, ChevronUp, EyeOff, HandHelping,
Briefcase, Check, CheckCheck, ChevronDown, ChevronLeft, ChevronUp, Eye, EyeOff, HandHelping,
Download, FileSpreadsheet, FileText, LayoutTemplate, ListPlus, MoreHorizontal, Package, Pencil, Plus, Printer, RotateCcw,
Save as SaveIcon, Share2, Trash2, UserRound,
} from 'lucide-react'
@@ -31,7 +31,7 @@ import { usePackingItemActions } from '../../../../components/Packing/usePacking
import { usePackingCategorySharing } from '../../../../components/Packing/usePackingCategorySharing'
import MBagsSheet from './MBagsSheet'
import MPackItemSheet from './MPackItemSheet'
import MChecklistCheck from './MChecklistCheck'
import MChecklistCheck, { MChecklistProgress } from './MChecklistCheck'
import MPackingImportSheet from './MPackingImportSheet'
import MPackingCategorySharingSheet from './MPackingCategorySharingSheet'
import PackingPrintPreview from '../../../../components/Packing/PackingPrintPreview'
@@ -160,24 +160,13 @@ export default function MPackingListTab({ planner }: { planner: TripPlanner }) {
</button>
</div>
{progress.total > 0 && (
<div className="mx-1.5 mt-3 pb-1">
<div className="flex flex-wrap items-center justify-between gap-2">
<span className="text-caption font-semibold tabular-nums text-m-ink">
{progress.pct === 100
? t('packing.allPacked')
: t('packing.packedCount', { packed: progress.checked, total: progress.total })}
</span>
{(checkedCount > 0 || hideDone) && (
<button type="button" onClick={() => setHideDone(value => !value)} aria-pressed={hideDone}
className={`flex min-h-9 items-center gap-1.5 rounded-full px-2.5 text-caption font-medium ${hideDone ? 'bg-m-act text-m-actfg' : 'bg-m-ic text-m-muted'}`}>
<EyeOff size={13} aria-hidden />{t('packing.hideDone')}
</button>
)}
<div className="mx-1.5 mt-3 border-t border-m-rowbr pb-1 pt-3">
<MChecklistProgress
label={progress.pct === 100 ? t('packing.allPacked') : t('packing.packedCount', { packed: progress.checked, total: progress.total })}
done={progress.checked}
total={progress.total}
/>
</div>
<div className="mt-[7px] h-[5px] overflow-hidden rounded-full bg-m-ic">
<div className="h-full rounded-full bg-m-act" style={{ width: `${progress.pct}%` }} />
</div>
</div>
)}
</div>
)}
@@ -289,6 +278,13 @@ export default function MPackingListTab({ planner }: { planner: TripPlanner }) {
{canEdit && isAdmin && items.length > 0 && <ActionRow icon={SaveIcon} label={t('packing.saveAsTemplate')} onClick={() => setActionView('save')} />}
{canEdit && <ActionRow icon={Download} label={t('packing.import')} onClick={run(() => setShowImportSheet(true))} />}
</ActionGroup>
<ActionGroup>
{(checkedCount > 0 || hideDone) && (
<ActionRow icon={hideDone ? Eye : EyeOff}
label={t(hideDone ? 'packing.showDone' : 'packing.hideDone')}
onClick={run(() => setHideDone(value => !value))} />
)}
</ActionGroup>
<ActionGroup>
{bagTrackingEnabled && <ActionRow icon={Briefcase} label={t('packing.bags')} onClick={run(() => setShowBagsSheet(true))} />}
{packingExport.hasItems && (
@@ -19,7 +19,7 @@ import { PRIORITY_COLOR, PRIORITY_LABEL } from './listsModel'
import { TODO_SMART_FILTERS, isTodoOverdue, type TodoSmartFilter } from '../../../../components/Todo/todoListModel'
import { useTodoView } from '../../../../components/Todo/useTodoList'
import MTaskSheet from './MTaskSheet'
import MChecklistCheck from './MChecklistCheck'
import MChecklistCheck, { MChecklistProgress } from './MChecklistCheck'
import MarkdownText from '../../../../components/shared/MarkdownText'
/**
@@ -44,7 +44,6 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
// With room for two panes the filters become a pane of their own (MTodoSidebar).
const split = useIsSplit()
const pct = items.length > 0 ? Math.round((counts.done / items.length) * 100) : 0
const defaultCategoryForNew = active.kind === 'category' ? active.name : null
const openCreate = () => { setEditingItemId(null); setCreatingTask(true) }
@@ -65,7 +64,7 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
}`
// The switch above the list: segments in one track, like Shared | My list.
const segment = (on: boolean) =>
`flex flex-none items-center gap-[5px] whitespace-nowrap rounded-full px-[12px] py-[6px] text-caption font-semibold ${
`flex min-h-9 min-w-max flex-1 items-center justify-center gap-1.5 whitespace-nowrap rounded-full px-2 py-1 text-caption font-semibold ${
on ? 'bg-m-act text-m-actfg' : 'text-m-ink'
}`
@@ -114,14 +113,7 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
const progressCard = items.length > 0 && (
// The packing list's card: how far along, a slim bar, the rest and the add.
<div className="flex items-center gap-[10px] rounded-2xl border border-m-rowbr bg-m-sheetop px-[14px] py-[12px]">
<div className="min-w-0 flex-1">
<div className="text-caption font-semibold tabular-nums text-m-ink">
{progressLabel(t, counts.done, items.length)}
</div>
<div className="mt-[7px] h-[5px] overflow-hidden rounded-full bg-m-ic">
<div className="h-full rounded-full bg-m-act" style={{ width: `${pct}%` }} />
</div>
</div>
<MChecklistProgress label={progressLabel(t, counts.done, items.length)} done={counts.done} total={items.length} />
{items.length > 0 && !split && (
<button
type="button"
@@ -181,18 +173,28 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
{/* ── Which tasks: one track, like the packing list's switch ── */}
{!split && items.length > 0 && (
<MChipStrip className="mt-[10px] gap-[2px] whitespace-nowrap rounded-full bg-m-ic p-[3px]">
{TODO_SMART_FILTERS.map(f => (
<button
key={f}
type="button"
aria-pressed={active.kind === 'smart' && active.id === f}
onClick={() => setActive({ kind: 'smart', id: f })}
className={segment(active.kind === 'smart' && active.id === f)}
>
{f === 'my' ? t('todo.filter.myShort') : filterLabel(f)}
<span className="text-caption tabular-nums opacity-60">{filterCount(f)}</span>
</button>
))}
{TODO_SMART_FILTERS.map(f => {
const isActive = active.kind === 'smart' && active.id === f
const count = filterCount(f)
const label = f === 'my' ? t('todo.filter.myShort') : filterLabel(f)
return (
<button
key={f}
type="button"
aria-label={count ? `${label} ${count}` : label}
aria-pressed={isActive}
onClick={() => setActive({ kind: 'smart', id: f })}
className={segment(isActive)}
>
{label}
{count > 0 && (
<span className="grid h-4 min-w-4 flex-none place-items-center rounded-full bg-m-sheetop px-1 text-caption leading-none tabular-nums text-m-ink">
{count}
</span>
)}
</button>
)
})}
{active.kind === 'category' && (
<button type="button" aria-pressed onClick={() => setOptionsOpen(true)} className={segment(true)}>{active.name}</button>
)}
@@ -298,18 +298,23 @@ describe('MPackingListTab', () => {
expect(screen.getByText('packing.personalEmptyHint')).toBeInTheDocument()
})
it('FE-MOB-PACKTAB-019: the visible filter hides packed items and restores them on a second tap', async () => {
it('FE-MOB-PACKTAB-019: the actions menu hides packed items and offers to show them again', async () => {
await setup()
expect(screen.queryByRole('button', { name: 'packing.hideDone' })).not.toBeInTheDocument()
openActions()
fireEvent.click(screen.getByRole('button', { name: 'packing.hideDone' }))
await waitFor(() => expect(screen.queryByRole('dialog', { name: 'packing.actions' })).not.toBeInTheDocument())
expect(screen.queryByText('Passport')).toBeNull()
expect(screen.getByText('Visa')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'packing.hideDone' }))
openActions()
fireEvent.click(screen.getByRole('button', { name: 'packing.showDone' }))
expect(screen.getByText('Passport')).toBeInTheDocument()
})
it('FE-MOB-PACKTAB-020: hiding everything shows the filtered-empty hint', async () => {
await setup({ items: [packItem({ id: 1, name: 'Visa', checked: 1 })] })
openActions()
fireEvent.click(screen.getByRole('button', { name: 'packing.hideDone' }))
expect(screen.getByText('packing.emptyFiltered')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'packing.filterAll' }))
@@ -123,10 +123,10 @@ describe('MTodoListTab', () => {
todo({ id: 4, name: 'Done', checked: 1 }),
])
expect(screen.getByRole('button', { name: 'todo.filter.all3' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.myShort1' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.overdue1' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.done1' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.all 3' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.myShort 1' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.overdue 1' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.done 1' })).toBeInTheDocument()
})
it('FE-MOB-TODO-005: defaults to the open items and hides done ones', () => {
@@ -161,7 +161,7 @@ describe('MTodoListTab', () => {
seedStore(useAuthStore, { user: null })
setup([todo({ id: 1, name: 'Mine', assigned_user_id: ME })])
expect(screen.getByRole('button', { name: 'todo.filter.myShort0' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'todo.filter.myShort' })).not.toHaveTextContent('0')
fireEvent.click(screen.getByRole('button', { name: /todo.filter.my/ }))