Show delete button when sets are selected

This commit is contained in:
Brandon Presley 2024-02-21 17:56:37 +13:00
parent 164d946b90
commit c2accf7202
4 changed files with 47 additions and 34 deletions

View File

@ -88,7 +88,7 @@ const styles = StyleSheet.create({
debugBanner: { debugBanner: {
position: 'absolute', position: 'absolute',
top: 20, top: 20,
right: 50, right: 100,
backgroundColor: 'red', backgroundColor: 'red',
zIndex: 1000, zIndex: 1000,
borderRadius: 5, borderRadius: 5,

View File

@ -6,15 +6,21 @@ import { DrawerParams } from "./drawer-params";
export default function DrawerHeader({ export default function DrawerHeader({
name, name,
children, children,
ids,
unSelect,
}: { }: {
name: string; name: string;
children?: JSX.Element | JSX.Element[]; children?: JSX.Element | JSX.Element[];
ids?: number[],
unSelect?: () => void,
}) { }) {
const navigation = useNavigation<DrawerNavigationProp<DrawerParams>>(); const navigation = useNavigation<DrawerNavigationProp<DrawerParams>>();
return ( return (
<Appbar.Header> <Appbar.Header>
<IconButton icon="menu" onPress={navigation.openDrawer} /> {ids && ids.length > 0 ? (<IconButton icon="arrow-left" onPress={unSelect} />) : (
<IconButton icon="menu" onPress={navigation.openDrawer} />
)}
<Appbar.Content title={name} /> <Appbar.Content title={name} />
{children} {children}
</Appbar.Header> </Appbar.Header>

View File

@ -47,40 +47,45 @@ export default function ListMenu({
}; };
return ( return (
<Menu <>
visible={showMenu} {ids.length > 0 && (
onDismiss={() => setShowMenu(false)} <IconButton icon="delete" onPress={() => setShowRemove(true)} />
anchor={ )}
<IconButton onPress={() => setShowMenu(true)} icon="dots-vertical" /> <Menu
} visible={showMenu}
> onDismiss={() => setShowMenu(false)}
<Menu.Item leadingIcon="check-all" title="Select all" onPress={select} /> anchor={
<Menu.Item <IconButton onPress={() => setShowMenu(true)} icon="dots-vertical" />
leadingIcon="close" }
title="Clear" >
onPress={clear} <Menu.Item leadingIcon="check-all" title="Select all" onPress={select} />
disabled={ids?.length === 0}
/>
<Menu.Item
leadingIcon="pencil"
title="Edit"
onPress={edit}
disabled={ids?.length === 0}
/>
{onCopy && (
<Menu.Item <Menu.Item
leadingIcon="content-copy" leadingIcon="close"
title="Copy" title="Clear"
onPress={copy} onPress={clear}
disabled={ids?.length === 0} disabled={ids?.length === 0}
/> />
)} <Menu.Item
<Divider /> leadingIcon="pencil"
<Menu.Item title="Edit"
leadingIcon="delete" onPress={edit}
onPress={() => setShowRemove(true)} disabled={ids?.length === 0}
title="Delete" />
/> {onCopy && (
<Menu.Item
leadingIcon="content-copy"
title="Copy"
onPress={copy}
disabled={ids?.length === 0}
/>
)}
<Divider />
<Menu.Item
leadingIcon="delete"
onPress={() => setShowRemove(true)}
title="Delete"
/>
</Menu>
<ConfirmDialog <ConfirmDialog
title={ids?.length === 0 ? "Delete all" : "Delete selected"} title={ids?.length === 0 ? "Delete all" : "Delete selected"}
show={showRemove} show={showRemove}
@ -94,6 +99,6 @@ export default function ListMenu({
<>This will delete {ids?.length} record(s). Are you sure?</> <>This will delete {ids?.length} record(s). Are you sure?</>
)} )}
</ConfirmDialog> </ConfirmDialog>
</Menu> </>
); );
} }

View File

@ -164,6 +164,8 @@ export default function SetList() {
<> <>
<DrawerHeader <DrawerHeader
name={ids.length > 0 ? `${ids.length} selected` : "History"} name={ids.length > 0 ? `${ids.length} selected` : "History"}
ids={ids}
unSelect={() => setIds([])}
> >
<ListMenu <ListMenu
onClear={clear} onClear={clear}