diff --git a/src/view/com/modals/ComposePost.tsx b/src/view/com/modals/ComposePost.tsx index 0032fbe7..806b5d7a 100644 --- a/src/view/com/modals/ComposePost.tsx +++ b/src/view/com/modals/ComposePost.tsx @@ -33,13 +33,18 @@ export function Component({ const [autocompleteOptions, setAutocompleteOptions] = useState([]) useEffect(() => { + let aborted = false store.api.app.bsky .getUserFollows({ user: store.me.did || '', }) .then(res => { + if (aborted) return setFollowedUsers(res.data.follows) }) + return () => { + aborted = true + } }) const onChangeText = (newText: string) => { diff --git a/src/view/com/util/UserInfoText.tsx b/src/view/com/util/UserInfoText.tsx index 54cb93f7..536eef9e 100644 --- a/src/view/com/util/UserInfoText.tsx +++ b/src/view/com/util/UserInfoText.tsx @@ -29,15 +29,21 @@ export function UserInfoText({ const [didFail, setFailed] = useState(false) useEffect(() => { + let aborted = false // TODO use caching to reduce loads store.api.app.bsky.getProfile({user: did}).then( v => { + if (aborted) return setProfile(v.data) }, _err => { + if (aborted) return setFailed(true) }, ) + return () => { + aborted = true + } }, [did, store.api.app.bsky]) return ( diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index f48c8cde..58010685 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -24,6 +24,7 @@ export const Home = observer(function Home({ ) useEffect(() => { + let aborted = false if (!visible) { return } @@ -33,7 +34,13 @@ export const Home = observer(function Home({ } else { store.nav.setTitle('Home') console.log('Fetching home feed') - defaultFeedView.setup().then(() => setHasSetup(true)) + defaultFeedView.setup().then(() => { + if (aborted) return + setHasSetup(true) + }) + } + return () => { + aborted = true } }, [visible, store]) diff --git a/src/view/screens/Login.tsx b/src/view/screens/Login.tsx index 91df7015..bc40327b 100644 --- a/src/view/screens/Login.tsx +++ b/src/view/screens/Login.tsx @@ -214,21 +214,27 @@ const CreateAccount = ({onPressBack}: {onPressBack: () => void}) => { const [username, setUsername] = useState('') useEffect(() => { + let aborted = false if (serviceDescription || error) { return } store.session.describeService('http://localhost:2583/').then( desc => { + if (aborted) return setServiceDescription(desc) setUserDomain(desc.availableUserDomains[0]) }, err => { + if (aborted) return console.error(err) setError( 'Unable to contact your service. Please check your Internet connection.', ) }, ) + return () => { + aborted = true + } }, []) const onPressNext = async () => { diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx index 60627385..fac39acd 100644 --- a/src/view/screens/Notifications.tsx +++ b/src/view/screens/Notifications.tsx @@ -13,6 +13,7 @@ export const Notifications = ({visible}: ScreenParams) => { const store = useStores() useEffect(() => { + let aborted = false if (!visible) { return } @@ -24,7 +25,13 @@ export const Notifications = ({visible}: ScreenParams) => { console.log('Fetching notifications feed') const newNotesView = new NotificationsViewModel(store, {}) setNotesView(newNotesView) - newNotesView.setup().then(() => setHasSetup(true)) + newNotesView.setup().then(() => { + if (aborted) return + setHasSetup(true) + }) + } + return () => { + aborted = true } }, [visible, store]) diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 9fe094af..f5f4f553 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -23,6 +23,7 @@ export const Profile = observer(({visible, params}: ScreenParams) => { >() useEffect(() => { + let aborted = false if (!visible) { return } @@ -36,9 +37,13 @@ export const Profile = observer(({visible, params}: ScreenParams) => { const newProfileUiState = new ProfileUiModel(store, {user}) setProfileUiState(newProfileUiState) newProfileUiState.setup().then(() => { + if (aborted) return setHasSetup(true) }) } + return () => { + aborted = true + } }, [visible, params.name, store]) // events