MCPcopy Create free account
hub / github.com/dailydotdev/apps / useSourceMenuProps

Function useSourceMenuProps

packages/shared/src/hooks/useSourceMenuProps.tsx:11–76  ·  view source on GitHub ↗
({
  source,
  feedId,
}: {
  source?: SourceTooltip | null;
  feedId?: string;
})

Source from the content-addressed store, hash-verified

9import type { UseShareOrCopyLinkProps } from './useShareOrCopyLink';
10
11const 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 };

Callers 1

SourceEntityCardFunction · 0.85

Calls 3

useContentPreferenceFunction · 0.90
getAbsoluteWebappUrlFunction · 0.90
useRouterFunction · 0.50

Tested by

no test coverage detected