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

Function NewSourceModal

packages/shared/src/components/modals/NewSourceModal.tsx:80–421  ·  view source on GitHub ↗
(props: ModalProps)

Source from the content-addressed store, hash-verified

78);
79
80export default function NewSourceModal(props: ModalProps): ReactElement {
81 const scrapeFormRef = useRef<HTMLFormElement>();
82 const [enableSubmission, setEnableSubmission] = useState(false);
83 const [scrapeError, setScrapeError] = useState<string>();
84 const [showContact, setShowContact] = useState(false);
85 const [showNotification, setShowNotification] = useState(false);
86 const { isPushSupported } = usePushNotificationContext();
87 const { hasPermissionCache } = usePushNotificationMutation();
88 const [feeds, setFeeds] = useState<{ label: ReactNode; value: string }[]>();
89 const [selectedFeed, setSelectedFeed] = useState<string>();
90 const [existingSource, setExistingSource] = useState<Source>();
91 const { user, isLoggedIn, loginState, showLogin } = useContext(AuthContext);
92 const loginTrigger = AuthTriggers.SubmitNewSource;
93 const { onRequestClose } = props;
94 const [isDismissed, setIsDismissed] = usePersistentContext(
95 DISMISS_PERMISSION_BANNER,
96 false,
97 );
98 const { data: sourceRequestAvailability, isPending: isLoadingAccess } =
99 useQuery({
100 queryKey: [RequestKey.SourceRequestAvailability, user?.id],
101
102 queryFn: async () => {
103 const result = await gqlClient.request<{
104 sourceRequestAvailability: SourceRequestAvailability;
105 }>(SOURCE_REQUEST_AVAILABILITY_QUERY);
106
107 return result.sourceRequestAvailability;
108 },
109 });
110
111 const failedToScrape = () => {
112 setShowContact(true);
113 setScrapeError(
114 'Failed to fetch information, try to find the link to the RSS itself and try again.',
115 );
116 };
117
118 const { mutateAsync: checkIfSourceExists, isPending: checkingIfExists } =
119 useMutation<{ source: Source }, unknown, string>({
120 mutationFn: (feed: string) =>
121 gqlClient.request(SOURCE_BY_FEED_QUERY, {
122 feed,
123 }),
124 });
125
126 const { mutateAsync: scrapeSource, isPending: isScraping } = useMutation<
127 ScrapeSourceResponse,
128 unknown,
129 string
130 >({
131 mutationFn: async (url) => {
132 const res = await fetchTimeout(
133 `${apiUrl}/scrape/source?url=${url}`,
134 20000,
135 {
136 credentials: 'same-origin',
137 },

Callers

nothing calls this directly

Calls 7

usePersistentContextFunction · 0.85
fetchTimeoutFunction · 0.85
failedToScrapeFunction · 0.85
getFeedLabelFunction · 0.85
onRequestCloseFunction · 0.50

Tested by

no test coverage detected