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

Function usePostToSquad

packages/shared/src/hooks/squads/usePostToSquad.tsx:100–553  ·  view source on GitHub ↗
({
  onPostSuccess,
  onComplete,
  onMutate,
  onError,
  onExternalLinkSuccess,
  onSourcePostModerationSuccess,
  getSharedPostSuccessToast,
  initialPreview,
  displayMutationErrors = false,
}: UsePostToSquadProps = {})

Source from the content-addressed store, hash-verified

98};
99
100export const usePostToSquad = ({
101 onPostSuccess,
102 onComplete,
103 onMutate,
104 onError,
105 onExternalLinkSuccess,
106 onSourcePostModerationSuccess,
107 getSharedPostSuccessToast,
108 initialPreview,
109 displayMutationErrors = false,
110}: UsePostToSquadProps = {}): UsePostToSquad => {
111 const { toggleGroup, getGroupStatus } = useNotificationSettings();
112 const { displayToast } = useToastNotification();
113 const logPostCreated = useLogPostCreated();
114 const { user } = useAuthContext();
115 const client = useQueryClient();
116 const { completeAction } = useActions();
117 const moderationCreationRef = useRef<PostType | null>(null);
118 const [preview, setPreview] = useState<ExternalLinkPreview>(
119 initialPreview ?? {},
120 );
121 const { requestMethod: requestMethodContext } = useRequestProtocol();
122 const requestMethod = requestMethodContext ?? gqlClient.request;
123
124 const handleMutationError = useCallback(
125 (err: unknown, options: { displayError?: boolean } = {}): void => {
126 if (!isApiErrorResult(err)) {
127 return;
128 }
129
130 const { displayError = true } = options;
131 if (displayMutationErrors && displayError) {
132 displayToast(err.response?.errors?.[0]?.message ?? DEFAULT_ERROR);
133 }
134
135 onError?.(err);
136 },
137 [displayMutationErrors, displayToast, onError],
138 );
139
140 const handlePostSuccess = useCallback(
141 (post: Post): void => {
142 onPostSuccess?.(post, post?.permalink ?? '');
143 onComplete?.();
144 },
145 [onComplete, onPostSuccess],
146 );
147
148 const handleComplete = useCallback((): void => onComplete?.(), [onComplete]);
149
150 const {
151 mutateAsync: onCreatePost,
152 isPending: isLoadingFreeform,
153 isSuccess: isFreeformPostSuccess,
154 } = useMutation({
155 mutationFn: createPost,
156 onMutate,
157 onError: (err) => handleMutationError(err),

Callers 7

CreateSharedPostModalFunction · 0.90
SharePostBarFunction · 0.90
useComposerSubmitFunction · 0.90
ShareLinkFunction · 0.90
CreatePostFunction · 0.90
EditPostFunction · 0.90

Calls 15

useToastNotificationFunction · 0.90
useLogPostCreatedFunction · 0.90
useAuthContextFunction · 0.90
useActionsFunction · 0.90
useRequestProtocolFunction · 0.90
getExternalLinkPreviewFunction · 0.90
getApiErrorFunction · 0.90
moderationRequiredFunction · 0.90
addPostToSquadFunction · 0.90
updateSquadPostFunction · 0.90
submitExternalLinkFunction · 0.90
useNotificationSettingsFunction · 0.85

Tested by

no test coverage detected