Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

at eli/problem-detection 55 lines 1.4 kB view raw
1import { useURL } from "expo-linking"; 2import { useEffect, useState } from "react"; 3import { useAppDispatch, useAppSelector } from "store/hooks"; 4import { 5 getProfile, 6 loadOAuthClient, 7 oauthCallback, 8 selectIsReady, 9 selectOAuthSession, 10 selectUserProfile, 11} from "./blueskySlice"; 12 13export default function BlueskyProvider({ 14 children, 15}: { 16 children: React.ReactNode; 17}) { 18 const dispatch = useAppDispatch(); 19 const isReady = useAppSelector(selectIsReady); 20 useEffect(() => { 21 dispatch(loadOAuthClient()); 22 }, []); 23 useEffect(() => { 24 if (!isReady) { 25 const handle = setInterval(() => { 26 dispatch(loadOAuthClient()); 27 }, 5000); 28 return () => clearInterval(handle); 29 } 30 }, [isReady]); 31 const oauthSession = useAppSelector(selectOAuthSession); 32 const userProfile = useAppSelector(selectUserProfile); 33 34 const [lastLink, setLastLink] = useState<string | null>(null); 35 const url = useURL(); 36 37 useEffect(() => { 38 if (url !== lastLink && url) { 39 setLastLink(url); 40 if (url.includes("?")) { 41 const params = new URLSearchParams(url.split("?")[1]); 42 if (params.has("error") || params.has("code")) { 43 dispatch(oauthCallback(url)); 44 } 45 } 46 } 47 }, [url, lastLink]); 48 49 useEffect(() => { 50 if (oauthSession && !userProfile) { 51 dispatch(getProfile(oauthSession.did)); 52 } 53 }, [oauthSession, userProfile]); 54 return <>{children}</>; 55}