import React from 'react'; import { Activity, EnrichedActivity, UR } from 'getstream'; import { ReactionToggleIcon } from './ReactionToggleIcon'; import { useFeedContext, DefaultAT, DefaultUT, useStreamContext } from '../context'; import { RepostIcon, Color } from './Icons'; import { PropsWithElementAttributes } from '../utils'; export type RepostButtonProps< UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR > = PropsWithElementAttributes<{ /** The activity received for stream for which to show the repost button. This is * used to initialize the toggle state and the counter. */ activity: EnrichedActivity; /** The feed group part of the feed that the activity should be reposted to, * e.g. `user` when posting to your own profile */ feedGroup?: string; /** Repost reaction custom data */ repostData?: RT; /** onAddReaction supports targetFeeds that you can use to send a notification to the post owner like ["notification:USER_ID"] */ targetFeeds?: string[]; /** The user_id part of the feed that the activity should be reposted to, default to current user id */ userId?: string; }>; /** * A repost button ready to be embedded as Activity footer */ export const RepostButton = < 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, feedGroup = 'user', userId, repostData, targetFeeds = [], className, style, }: RepostButtonProps) => { const feed = useFeedContext(); const app = useStreamContext(); // this to prevent reposting another repost, you can only repost an original activity to avoid nesting const originalActivity = activity.verb === 'repost' && typeof activity.object === 'object' ? (activity.object as EnrichedActivity) : activity; return ( counts={originalActivity.reaction_counts} own_reactions={originalActivity.own_reactions} kind="repost" onPress={() => feed.onToggleReaction('repost', originalActivity as Activity, repostData, { targetFeeds: [`${feedGroup}:${userId || app.user?.id}`, ...targetFeeds], }) } activeIcon={} inactiveIcon={} className={className} style={style} /> ); };