({
source,
feedId,
}: {
source?: SourceTooltip | null;
feedId?: string;
})
| 9 | import type { UseShareOrCopyLinkProps } from './useShareOrCopyLink'; |
| 10 | |
| 11 | const useSourceMenuProps = ({ |
| 12 | source, |
| 13 | feedId, |
| 14 | }: { |
| 15 | source?: SourceTooltip | null; |
| 16 | feedId?: string; |
| 17 | }) => { |
| 18 | const router = useRouter(); |
| 19 | const { follow, unfollow } = useContentPreference(); |
| 20 | const sourceId = source?.id ?? ''; |
| 21 | |
| 22 | const onCreateNewFeed = () => { |
| 23 | if (!source?.id) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | router.push( |
| 28 | `${webappUrl}feeds/new?entityId=${sourceId}&entityType=${ContentPreferenceType.Source}`, |
| 29 | ); |
| 30 | }; |
| 31 | |
| 32 | const onUndo = () => { |
| 33 | if (!source?.id || !source.handle) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | unfollow({ |
| 38 | id: sourceId, |
| 39 | entity: ContentPreferenceType.Source, |
| 40 | entityName: source.handle, |
| 41 | feedId, |
| 42 | }); |
| 43 | }; |
| 44 | |
| 45 | const onAdd = () => { |
| 46 | if (!source?.id || !source.handle) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | follow({ |
| 51 | id: sourceId, |
| 52 | entity: ContentPreferenceType.Source, |
| 53 | entityName: source.handle, |
| 54 | feedId, |
| 55 | }); |
| 56 | }; |
| 57 | |
| 58 | const shareProps: UseShareOrCopyLinkProps = { |
| 59 | text: source?.handle |
| 60 | ? `Check out ${source.handle} on daily.dev` |
| 61 | : 'Check out this source on daily.dev', |
| 62 | link: source?.permalink || getAbsoluteWebappUrl(), |
| 63 | cid: ReferralCampaignKey.ShareSource, |
| 64 | logObject: () => ({ |
| 65 | event_name: LogEvent.ShareSource, |
| 66 | ...(source?.id ? { target_id: source.id } : {}), |
| 67 | }), |
| 68 | }; |
no test coverage detected