|
1 | 1 | import {AvatarStack, Flex} from '@sanity/ui'
|
2 | 2 | import {AnimatePresence, motion} from 'framer-motion'
|
3 |
| -import {useCallback} from 'react' |
| 3 | +import {useCallback, useMemo} from 'react' |
4 | 4 | import {type FormPatch, type PatchEvent, type Path, set} from 'sanity'
|
5 | 5 |
|
6 | 6 | import {Button} from '../../../../../ui-components'
|
@@ -47,28 +47,38 @@ export function TasksSubscribers(props: TasksSubscriberProps) {
|
47 | 47 | )
|
48 | 48 | }
|
49 | 49 |
|
50 |
| -export function TasksSubscriberAvatars(props: {subscriberIds?: string[]}) { |
51 |
| - const {subscriberIds} = props |
| 50 | +const EMPTY_ARRAY: [] = [] |
| 51 | + |
| 52 | +interface TasksSubscriberAvatarsProps { |
| 53 | + subscriberIds?: string[] |
| 54 | +} |
| 55 | + |
| 56 | +export function TasksSubscriberAvatars(props: TasksSubscriberAvatarsProps) { |
| 57 | + const {subscriberIds: subscriberIdsProp} = props |
| 58 | + |
| 59 | + const subscriberIds = useMemo(() => { |
| 60 | + // Make sure we have valid subscriber IDs |
| 61 | + return subscriberIdsProp?.filter(Boolean) || EMPTY_ARRAY |
| 62 | + }, [subscriberIdsProp]) |
52 | 63 |
|
53 | 64 | return (
|
54 | 65 | <AnimatePresence initial={false}>
|
55 | 66 | <AvatarStack maxLength={3} size={0}>
|
56 |
| - {subscriberIds && |
57 |
| - subscriberIds.map((subscriberId) => ( |
58 |
| - <motion.div |
59 |
| - key={subscriberId} |
60 |
| - exit={{opacity: 0, translateX: '2px', scale: 0.9}} |
61 |
| - animate={{ |
62 |
| - opacity: 1, |
63 |
| - translateX: 0, |
64 |
| - scale: 1, |
65 |
| - transition: {type: 'just', duration: 0.2}, |
66 |
| - }} |
67 |
| - initial={{opacity: 0, translateX: '2px', scale: 0.9}} |
68 |
| - > |
69 |
| - <TasksUserAvatar user={{id: subscriberId}} size={0} /> |
70 |
| - </motion.div> |
71 |
| - ))} |
| 67 | + {subscriberIds.map((subscriberId) => ( |
| 68 | + <motion.div |
| 69 | + key={subscriberId} |
| 70 | + exit={{opacity: 0, translateX: '2px', scale: 0.9}} |
| 71 | + animate={{ |
| 72 | + opacity: 1, |
| 73 | + translateX: 0, |
| 74 | + scale: 1, |
| 75 | + transition: {type: 'just', duration: 0.2}, |
| 76 | + }} |
| 77 | + initial={{opacity: 0, translateX: '2px', scale: 0.9}} |
| 78 | + > |
| 79 | + <TasksUserAvatar user={{id: subscriberId}} size={0} /> |
| 80 | + </motion.div> |
| 81 | + ))} |
72 | 82 | </AvatarStack>
|
73 | 83 | </AnimatePresence>
|
74 | 84 | )
|
|
0 commit comments