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

Function SharePostBar

packages/shared/src/components/squads/SharePostBar.tsx:26–173  ·  view source on GitHub ↗
({
  className,
  disabled = false,
  disabledText = 'Only admins and moderators can post',
  squad,
}: SharePostBarProps)

Source from the content-addressed store, hash-verified

24}
25
26function SharePostBar({
27 className,
28 disabled = false,
29 disabledText = 'Only admins and moderators can post',
30 squad,
31}: SharePostBarProps): ReactElement {
32 const inputRef = useRef<HTMLInputElement | null>(null);
33 const { user } = useAuthContext();
34 const { openModal } = useLazyModal();
35 const [url, setUrl] = useState<string>('');
36 const isMobile = useViewSize(ViewSize.MobileL);
37 const isLaptop = useViewSize(ViewSize.Laptop);
38 const { evaluateSmartComposer } = useSmartComposer();
39 const [urlFocused, toggleUrlFocus] = useState(false);
40 const onSharedSuccessfully = () => {
41 if (inputRef.current) {
42 inputRef.current.value = '';
43 }
44 setUrl('');
45 };
46
47 const shouldRenderReadingHistory = !urlFocused && url.length === 0;
48
49 const onOpenCreatePost = (preview: ExternalLinkPreview, link?: string) => {
50 if (isLaptop && evaluateSmartComposer()) {
51 openModal({
52 type: LazyModal.SmartComposer,
53 props: {
54 initialUrl: link,
55 initialSquadHandle: squad.handle,
56 preview: { ...preview, url: link },
57 },
58 });
59 return;
60 }
61 openModal({
62 type: LazyModal.CreateSharedPost,
63 props: {
64 preview: { ...preview, url: link },
65 squad,
66 onSharedSuccessfully,
67 },
68 });
69 };
70
71 const onOpenHistory = () =>
72 openModal({
73 type: LazyModal.ReadingHistory,
74 props: {
75 onArticleSelected: ({ post }) => onOpenCreatePost(post, post.permalink),
76 keepOpenAfterSelecting: true,
77 },
78 });
79
80 const { getLinkPreview, isLoadingPreview } = usePostToSquad({
81 onExternalLinkSuccess: onOpenCreatePost,
82 });
83

Callers

nothing calls this directly

Calls 5

useAuthContextFunction · 0.90
useLazyModalFunction · 0.90
useViewSizeFunction · 0.90
useSmartComposerFunction · 0.90
usePostToSquadFunction · 0.90

Tested by

no test coverage detected