Skip to content

Commit

Permalink
feat: PersonInChip => PersonOrGroupInChip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Sep 18, 2019
1 parent 43542fd commit 09975d7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
21 changes: 0 additions & 21 deletions src/components/shared/SelectPeople/PersonInChip.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions src/components/shared/SelectPeople/PersonOrGroupInChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react'
import { Avatar } from '../../../utils/components/Avatar'
import MuiAvatar from '@material-ui/core/Avatar/Avatar'
import { Chip } from '@material-ui/core'
import { Person, Group } from '../../../database'

interface SharedProps {
onDelete?(): void
disabled?: boolean
}
interface PersonChipProps {
type: 'person'
item: Person
}
interface GroupChipProps {
type: 'group'
item: Group
}
export function PersonOrGroupInChip(props: SharedProps & (PersonChipProps | GroupChipProps)) {
const { disabled, onDelete } = props
let avatar: ReturnType<typeof Avatar> | undefined = undefined
let displayName = ''
if (props.type === 'group') {
const group = props.item
displayName = group.groupName
avatar = group.avatar ? <MuiAvatar aria-label={displayName} src={avatar} /> : undefined
} else {
const person = props.item
displayName = person.nickname || person.identifier.userId
avatar = person.avatar ? <Avatar person={person} /> : undefined
}

return (
<Chip
style={{ marginRight: 6, marginBottom: 6 }}
color="primary"
onDelete={disabled ? undefined : onDelete}
label={displayName}
avatar={avatar}
/>
)
}
9 changes: 5 additions & 4 deletions src/components/shared/SelectPeople/SelectPeopleUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeStyles, ListItem, ListItemText, InputBase, Button, List, Box } from
import { Person } from '../../../database'
import { useCurrentIdentity } from '../../DataSource/useActivatedUI'
import { PersonInList } from './PeopleInList'
import { PersonInChip } from './PersonInChip'
import { PersonOrGroupInChip } from './PersonOrGroupInChip'
interface SelectPeopleUIProps {
ignoreMyself?: boolean
people: Person[]
Expand Down Expand Up @@ -126,14 +126,15 @@ export function SelectPeopleUI(props: SelectPeopleUIProps) {
)
}
function FrozenChip(person: Person) {
return <PersonInChip disabled key={person.identifier.userId} person={person} />
return <PersonOrGroupInChip disabled key={person.identifier.userId} type="person" item={person} />
}
function RemovableChip(person: Person) {
return (
<PersonInChip
<PersonOrGroupInChip
disabled={disabled}
key={person.identifier.userId}
person={person}
type="person"
item={person}
onDelete={() => onSetSelected(selected.filter(x => x.identifier.userId !== person.identifier.userId))}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/SelectPeople/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './SelectPeopleUI'
export * from './PeopleInList'
export * from './PersonInChip'
export * from './PersonOrGroupInChip'

0 comments on commit 09975d7

Please sign in to comment.