Skip to content

Commit

Permalink
app: use menu for more actions on item and collection screen
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed Jan 21, 2024
1 parent 2ab5909 commit a72a768
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 58 deletions.
27 changes: 14 additions & 13 deletions App/app/features/inventory/screens/CollectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<UIGroup.ListItem.RenderItemContainer
Expand Down Expand Up @@ -333,7 +321,20 @@ function CollectionScreen({
action2Label={(data && 'Actions') || undefined}
action2SFSymbolName={(data && 'ellipsis.circle') || undefined}
action2MaterialIconName={(data && 'dots-horizontal') || undefined}
onAction2Press={handleMoreActionsPress}
action2MenuActions={[
{
type: 'section',
children: [
{
title: 'Copy Collection ID',
sfSymbolName: 'doc.on.doc',
onPress: () => {
Clipboard.setString(id);
},
},
],
},
]}
>
<FlatList
onRefresh={refresh}
Expand Down
97 changes: 52 additions & 45 deletions App/app/features/inventory/screens/ItemScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function ItemScreen({

const rootNavigation = useRootNavigation();
const { openRfidSheet } = useRootBottomSheets();
const { showActionSheet } = useActionSheet();

const { config, loading: configLoading } = useConfig();
const { save, saving } = useSave();
Expand Down Expand Up @@ -298,49 +297,6 @@ function ItemScreen({
navigation,
});

const handleMoreActionsPress = useCallback(() => {
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<typeof s> => !!s),
);
}, [data, id, navigation, rootNavigation, showActionSheet]);

const dispatch = useAppDispatch();
useEffect(() => {
dispatch(actions.inventory.addRecentViewedItemId({ id }));
Expand Down Expand Up @@ -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<typeof s> => !!s),
},
{
type: 'section',
children: [
{
title: 'Copy Item ID',
sfSymbolName: 'doc.on.doc',
onPress: () => {
Clipboard.setString(id);
},
},
],
},
]}
>
<ScreenContent.ScrollView
refreshControl={
Expand Down

0 comments on commit a72a768

Please sign in to comment.