From e0e21cfbce1f9afa03eb5eab2f39eef83612dc56 Mon Sep 17 00:00:00 2001 From: Ramzan Date: Tue, 27 Oct 2020 22:30:46 -0400 Subject: [PATCH] Contacts: Add edit button to group list items --- src/Contacts/ContactEdit.tsx | 10 +++++----- src/Contacts/Main.tsx | 4 ++-- src/Contacts/SearchableAddressBook.tsx | 1 + src/Contacts/Sidebar.tsx | 18 +++++++++++++++--- src/widgets/List.tsx | 8 ++++++++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Contacts/ContactEdit.tsx b/src/Contacts/ContactEdit.tsx index c82c017..18636f1 100644 --- a/src/Contacts/ContactEdit.tsx +++ b/src/Contacts/ContactEdit.tsx @@ -120,7 +120,7 @@ interface PropsType { collections: CachedCollection[]; initialCollection?: string; item?: ContactType; - group?: boolean; + newGroup?: boolean; onSave: (contact: ContactType, collectionUid: string, originalContact?: ContactType) => Promise; onDelete: (contact: ContactType, collectionUid: string) => void; onCancel: () => void; @@ -305,7 +305,7 @@ class ContactEdit extends React.PureComponent { comp.updatePropertyWithValue("version", "4.0"); comp.updatePropertyWithValue("uid", this.state.uid); comp.updatePropertyWithValue("rev", ICAL.Time.now()); - if (this.props.group) { + if (this.props.newGroup) { comp.updatePropertyWithValue("kind", "group"); } @@ -356,7 +356,7 @@ class ContactEdit extends React.PureComponent { } - if (!this.props.group && !this.state.group) { + if (!this.props.newGroup && !this.state.group) { setProperties("tel", this.state.phone); setProperties("email", this.state.email); setProperties("adr", this.state.address); @@ -399,7 +399,7 @@ class ContactEdit extends React.PureComponent { return (

- {this.props.item ? this.state.group ? "Edit Group" : "Edit Contact" : this.props.group ? "New Group" : "New Contact"} + {this.props.item ? this.state.group ? "Edit Group" : "Edit Contact" : this.props.newGroup ? "New Group" : "New Contact"}

@@ -417,7 +417,7 @@ class ContactEdit extends React.PureComponent { - {this.props.group || this.state.group ? + {this.props.newGroup || this.state.group ? diff --git a/src/Contacts/Sidebar.tsx b/src/Contacts/Sidebar.tsx index a08ca0d..a7a8eeb 100644 --- a/src/Contacts/Sidebar.tsx +++ b/src/Contacts/Sidebar.tsx @@ -3,6 +3,7 @@ import * as React from "react"; import InboxIcon from "@material-ui/icons/Inbox"; import LabelIcon from "@material-ui/icons/LabelOutlined"; import AddIcon from "@material-ui/icons/Add"; +import EditIcon from "@material-ui/icons/EditOutlined"; import IconButton from "@material-ui/core/IconButton"; @@ -15,19 +16,27 @@ interface ListItemPropsType { primaryText: string; filterByGroup: string | undefined; setFilterByGroup: (group: string | undefined) => void; + editGroup: () => void; } function SidebarListItem(props: ListItemPropsType) { - const { name, icon, primaryText, filterByGroup } = props; + const { name, icon, primaryText, filterByGroup, editGroup } = props; const handleClick = () => props.setFilterByGroup(name); + const selected = name === filterByGroup; + return ( + + + } /> ); } @@ -37,10 +46,11 @@ interface PropsType { filterByGroup: string | undefined; setFilterByGroup: (group: string | undefined) => void; newGroup: () => void; + editGroup: (group: ContactType) => void; } export default React.memo(function Sidebar(props: PropsType) { - const { groups, filterByGroup, setFilterByGroup, newGroup } = props; + const { groups, filterByGroup, setFilterByGroup, newGroup, editGroup } = props; const groupList = [...groups].sort((a, b) => a.fn.localeCompare(b.fn)).map((group) => ( } filterByGroup={filterByGroup} setFilterByGroup={setFilterByGroup} + editGroup={() => editGroup(group)} /> )); @@ -61,6 +72,7 @@ export default React.memo(function Sidebar(props: PropsType) { icon={} filterByGroup={filterByGroup} setFilterByGroup={setFilterByGroup} + editGroup={newGroup} />
diff --git a/src/widgets/List.tsx b/src/widgets/List.tsx index f496ed6..fa4b590 100644 --- a/src/widgets/List.tsx +++ b/src/widgets/List.tsx @@ -6,6 +6,7 @@ import * as React from "react"; import { createStyles, makeStyles } from "@material-ui/core/styles"; import MuiList from "@material-ui/core/List"; import MuiListItem from "@material-ui/core/ListItem"; +import MuiListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction"; import MuiListSubheader from "@material-ui/core/ListSubheader"; import ListItemIcon from "@material-ui/core/ListItemIcon"; import ListItemText from "@material-ui/core/ListItemText"; @@ -47,6 +48,7 @@ interface ListItemPropsType { nestedItems?: React.ReactNode[]; selected?: boolean; secondaryTextColor?: "initial" | "inherit" | "primary" | "secondary" | "textPrimary" | "textSecondary" | "error"; + secondaryAction?: React.ReactNode; } export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) { @@ -64,6 +66,7 @@ export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) nestedItems, selected, secondaryTextColor, + secondaryAction, } = _props; const extraProps = (onClick || href) ? { @@ -94,6 +97,11 @@ export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) {rightIcon} )} + {secondaryAction && ( + + {secondaryAction} + + )} {nestedItems && (