import React, { useEffect } from 'react'; import { Activity, EnrichedReaction, UR, Reaction, EnrichedActivity } from 'getstream'; import { DefaultAT, DefaultUT } from '../context/StreamApp'; import { ReactionToggleIcon } from './ReactionToggleIcon'; import { ThumbsUpIcon, Color } from './Icons'; import { useFeedContext } from '../context'; import { PropsWithElementAttributes } from '../utils'; export type LikeButtonProps< UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR > = PropsWithElementAttributes<{ /** The activity received from stream that should be liked when pressing the LikeButton. */ activity?: EnrichedActivity; /** The reaction received from stream that should be liked when pressing the LikeButton. */ reaction?: EnrichedReaction; /** onAddReaction supports targetFeeds that you can use to send a notification to the post owner like ["notification:USER_ID"] */ targetFeeds?: string[]; }>; export const LikeButton = < UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR, PT extends UR = UR >({ activity, reaction, targetFeeds, className, style, }: LikeButtonProps) => { const feed = useFeedContext(); useEffect(() => { if (!reaction && !activity) console.warn('LikeButton requires an activity or reaction to work properly'); if (reaction && activity) console.warn('LikeButton requires only one of the activity or reaction to work properly'); }, []); return ( { if (reaction) return feed.onToggleChildReaction('like', reaction as Reaction, {} as CRT, { targetFeeds }); if (activity) return feed.onToggleReaction('like', activity as Activity, {} as RT, { targetFeeds }); return Promise.resolve(); }} activeIcon={} inactiveIcon={} labelSingle="like" labelPlural="likes" /> ); };