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