From a72a768eb65e0a2dfc6530b042364b651009966e Mon Sep 17 00:00:00 2001 From: zetavg Date: Thu, 18 Jan 2024 00:26:56 +0800 Subject: [PATCH] app: use menu for more actions on item and collection screen --- .../inventory/screens/CollectionScreen.tsx | 27 +++--- .../features/inventory/screens/ItemScreen.tsx | 97 ++++++++++--------- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/App/app/features/inventory/screens/CollectionScreen.tsx b/App/app/features/inventory/screens/CollectionScreen.tsx index a610e7d3..29cadfe6 100644 --- a/App/app/features/inventory/screens/CollectionScreen.tsx +++ b/App/app/features/inventory/screens/CollectionScreen.tsx @@ -253,18 +253,6 @@ function CollectionScreen({ const collectionName = typeof data?.name === 'string' ? data.name : preloadedTitle || 'Collection'; - const { showActionSheet } = useActionSheet(); - const handleMoreActionsPress = useCallback(() => { - showActionSheet([ - { - name: 'Copy Collection ID', - onSelect: () => { - Clipboard.setString(id); - }, - }, - ]); - }, [id, showActionSheet]); - const renderListItem = useCallback( ({ item, index }: { item: DataTypeWithID<'item'>; index: number }) => ( { + Clipboard.setString(id); + }, + }, + ], + }, + ]} > { - showActionSheet( - [ - data?.__valid - ? { - name: 'Duplicate', - onSelect: () => { - if (!data?.__valid) return; - rootNavigation?.navigate('SaveItem', { - initialData: { - ...Object.fromEntries( - Object.entries(data).filter( - ([k]) => - !k.startsWith('_') && - k !== 'actual_rfid_tag_epc_memory_bank_contents' && - k !== 'rfid_tag_access_password' && - k !== 'integrations', - ), - ), - }, - afterSave: it => { - it.__id && navigation.push('Item', { id: it.__id }); - }, - }); - }, - } - : null, - { - name: 'Print Label', - onSelect: () => { - rootNavigation?.push('PrintLabelModal', { itemIds: [id] }); - }, - }, - { - name: 'Copy Item ID', - onSelect: () => { - Clipboard.setString(id); - }, - }, - ].filter((s): s is NonNullable => !!s), - ); - }, [data, id, navigation, rootNavigation, showActionSheet]); - const dispatch = useAppDispatch(); useEffect(() => { dispatch(actions.inventory.addRecentViewedItemId({ id })); @@ -386,7 +342,58 @@ function ItemScreen({ action2Label={(data && 'Actions') || undefined} action2SFSymbolName={(data && 'ellipsis.circle') || undefined} action2MaterialIconName={(data && 'dots-horizontal') || undefined} - onAction2Press={handleMoreActionsPress} + action2MenuActions={[ + { + type: 'section', + children: [ + data?.__valid + ? { + title: 'Duplicate', + sfSymbolName: 'plus.square.on.square', + onPress: () => { + if (!data?.__valid) return; + rootNavigation?.navigate('SaveItem', { + initialData: { + ...Object.fromEntries( + Object.entries(data).filter( + ([k]) => + !k.startsWith('_') && + k !== + 'actual_rfid_tag_epc_memory_bank_contents' && + k !== 'rfid_tag_access_password' && + k !== 'integrations', + ), + ), + }, + afterSave: it => { + it.__id && navigation.push('Item', { id: it.__id }); + }, + }); + }, + } + : null, + { + title: 'Print Label', + sfSymbolName: 'printer', + onPress: () => { + rootNavigation?.push('PrintLabelModal', { itemIds: [id] }); + }, + }, + ].filter((s): s is NonNullable => !!s), + }, + { + type: 'section', + children: [ + { + title: 'Copy Item ID', + sfSymbolName: 'doc.on.doc', + onPress: () => { + Clipboard.setString(id); + }, + }, + ], + }, + ]} >