feat(mobile): refine TREK navigation and interfaces

This commit is contained in:
Maurice
2026-12-03 23:06:17 +01:00
parent 995e9c435f
commit 00955f0ac5
553 changed files with 17703 additions and 13101 deletions
@@ -24,7 +24,7 @@ interface KategorieGruppeProps {
onRename: (oldName: string, newName: string) => Promise<void>
onDeleteAll: (items: PackingItem[]) => Promise<void>
onDeleteItem: (item: PackingItem) => Promise<void>
onAddItem: (category: string, name: string) => Promise<void>
onAddItem: (category: string, name: string) => Promise<unknown>
assignees: CategoryAssignee[]
tripMembers: TripMember[]
onSetAssignees: (category: string, userIds: number[]) => Promise<void>
@@ -80,6 +80,19 @@ describe('usePackingItemActions', () => {
expect(phone.acts.addPackingItem).toHaveBeenCalledWith(7, { name: 'Tent', category: 'Camp', visibility: 'common' });
});
it('uses the personal placeholder when both scopes have the same category name', async () => {
const shared = buildPackingItem({ id: 4, name: PACKING_PLACEHOLDER_NAME, category: 'Camp' });
const personal = buildPackingItem({ ...shared, id: 5, is_private: 1, owner_id: 9 });
const { result, acts } = setup({ items: [shared, personal], view: 'personal' });
await act(async () => {
await result.current.addItemToCategory('Camp', 'Tent');
});
expect(acts.updatePackingItem).toHaveBeenCalledWith(7, 5, { name: 'Tent' });
expect(acts.updatePackingItem).toHaveBeenCalledOnce();
});
it('FE-PACK-ITEMACT-003: in my list a new item is shared the way the category already is (#2241)', async () => {
const own = buildPackingItem({
id: 5,
@@ -57,13 +57,18 @@ export function usePackingItemActions({
const [addingCategory, setAddingCategory] = useState(false);
const [newCategoryName, setNewCategoryName] = useState('');
const addItemToCategory = async (category: string, name: string) => {
const addItemToCategory = async (category: string | null, name: string) => {
try {
// Reuse the '...' placeholder slot when the category already has one, so a
// freshly-emptied category keeps its position (and therefore its colour)
// instead of the new item being appended to the end of the list.
const pool = placeholderFrom === 'store' ? useTripStore.getState().packingItems : items;
const placeholder = pool.find((i) => i.category === category && isPackingPlaceholder(i));
const placeholder = packingViewItems(pool, view).find(
(i) =>
(i.category || null) === category &&
isPackingPlaceholder(i) &&
(view === 'common' || i.owner_id == null || i.owner_id === currentUserId)
);
if (placeholder) {
await updatePackingItem(tripId, placeholder.id, { name });
} else {
@@ -71,12 +76,13 @@ export function usePackingItemActions({
// category's own items agree on (#2241).
await addPackingItem(tripId, {
name,
category,
...newItemSharing(items, category, view, currentUserId),
...(category ? { category, ...newItemSharing(items, category, view, currentUserId) } : { visibility: view }),
} as Parameters<typeof addPackingItem>[1]);
}
return true;
} catch {
toast.error(t('packing.toast.addError'));
return false;
}
};
@@ -88,7 +94,7 @@ export function usePackingItemActions({
// removing the placeholder is how an empty category is dismissed.
const deleteItem = async (item: PackingItem) => {
try {
if (isLastCustomItemInCategory(item, items)) {
if (isLastCustomItemInCategory(item, packingViewItems(items, item.is_private ? 'personal' : 'common'))) {
if (item.checked) await togglePackingItem(tripId, item.id, false);
await updatePackingItem(tripId, item.id, {
name: PACKING_PLACEHOLDER_NAME,
@@ -106,7 +112,7 @@ export function usePackingItemActions({
/** Moves every item of a category to the new name, one write each; a failure stops it and is thrown. */
const renameCategory = async (oldName: string, newName: string) => {
const toUpdate = items.filter((i) => (i.category || defaultCategory) === oldName);
const toUpdate = packingViewItems(items, view).filter((i) => (i.category || defaultCategory) === oldName);
for (const item of toUpdate) {
await updatePackingItem(tripId, item.id, { category: newName });
}
@@ -136,7 +142,7 @@ export function usePackingItemActions({
/** Removes the checked items of the open view only, the ones the button's count names. */
const clearChecked = async () => {
let failed = false;
for (const item of packingViewItems(items, view).filter((i) => i.checked)) {
for (const item of packingViewItems(items, view).filter((i) => i.checked && !isPackingPlaceholder(i))) {
try {
await deletePackingItem(tripId, item.id);
} catch {