From c6795e18fc0b68ebf54f4a23a3077b9de54a67ba Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Fri, 8 Jul 2022 14:14:35 +0400 Subject: [PATCH] MM-45456 - Gekidou LoadingUnreads component keeps spinning (#6453) * fix animation on LoadingUnreads component * code clean up * clean up * revert change to action/websocket/index * Update loading_unreads.tsx * fix loader stop spinning on second server removal * fix for stopping loader on addition of new server * Update loading_unreads.tsx --- app/actions/remote/entry/common.ts | 15 +++++++++------ app/actions/remote/post.ts | 8 +++----- .../categories_list/header/loading_unreads.tsx | 7 ++----- app/screens/navigation.ts | 1 + 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/actions/remote/entry/common.ts b/app/actions/remote/entry/common.ts index ee73b4c987..eef61b9c7f 100644 --- a/app/actions/remote/entry/common.ts +++ b/app/actions/remote/entry/common.ts @@ -61,6 +61,7 @@ export type EntryResponse = { } const FETCH_MISSING_DM_TIMEOUT = 2500; +const FETCH_UNREADS_TIMEOUT = 2500; export const teamsToRemove = async (serverUrl: string, removeTeamIds?: string[]) => { const operator = DatabaseManager.serverDatabases[serverUrl]?.operator; @@ -277,13 +278,15 @@ export async function deferredAppEntryActions( initialTeamId?: string, initialChannelId?: string) { // defer sidebar DM & GM profiles let channelsToFetchProfiles: Set|undefined; - if (chData?.channels?.length && chData.memberships?.length) { - const directChannels = chData.channels.filter(isDMorGM); - channelsToFetchProfiles = new Set(directChannels); + setTimeout(async () => { + if (chData?.channels?.length && chData.memberships?.length) { + const directChannels = chData.channels.filter(isDMorGM); + channelsToFetchProfiles = new Set(directChannels); - // defer fetching posts for unread channels on initial team - fetchPostsForUnreadChannels(serverUrl, chData.channels, chData.memberships, initialChannelId, true); - } + // defer fetching posts for unread channels on initial team + fetchPostsForUnreadChannels(serverUrl, chData.channels, chData.memberships, initialChannelId, true); + } + }, FETCH_UNREADS_TIMEOUT); // defer fetch channels and unread posts for other teams if (teamData.teams?.length && teamData.memberships?.length) { diff --git a/app/actions/remote/post.ts b/app/actions/remote/post.ts index 05344a2cf6..734c435190 100644 --- a/app/actions/remote/post.ts +++ b/app/actions/remote/post.ts @@ -326,11 +326,6 @@ export async function fetchPostsForChannel(serverUrl: string, channelId: string, } export const fetchPostsForUnreadChannels = async (serverUrl: string, channels: Channel[], memberships: ChannelMembership[], excludeChannelId?: string, emitEvent = false) => { - const database = DatabaseManager.serverDatabases[serverUrl]?.database; - if (!database) { - return {error: `${serverUrl} database not found`}; - } - try { const promises = []; if (emitEvent) { @@ -347,6 +342,9 @@ export const fetchPostsForUnreadChannels = async (serverUrl: string, channels: C DeviceEventEmitter.emit(Events.FETCHING_POSTS, false); } } catch (error) { + if (emitEvent) { + DeviceEventEmitter.emit(Events.FETCHING_POSTS, false); + } return {error}; } diff --git a/app/screens/home/channel_list/categories_list/header/loading_unreads.tsx b/app/screens/home/channel_list/categories_list/header/loading_unreads.tsx index eb7ecad7cb..162293a294 100644 --- a/app/screens/home/channel_list/categories_list/header/loading_unreads.tsx +++ b/app/screens/home/channel_list/categories_list/header/loading_unreads.tsx @@ -40,10 +40,7 @@ const LoadingUnreads = () => { useEffect(() => { if (loading) { opacity.value = 1; - rotation.value = withRepeat( - withTiming(360, {duration: 750, easing: Easing.ease}), - -1, - ); + rotation.value = withRepeat(withTiming(360, {duration: 750, easing: Easing.ease}), -1); } else { opacity.value = withTiming(0, {duration: 300, easing: Easing.ease}); cancelAnimation(rotation); @@ -62,7 +59,7 @@ const LoadingUnreads = () => { }); return () => listener.remove(); - }, [loading]); + }, []); if (!loading) { return null; diff --git a/app/screens/navigation.ts b/app/screens/navigation.ts index 047272dc7c..9786514f25 100644 --- a/app/screens/navigation.ts +++ b/app/screens/navigation.ts @@ -193,6 +193,7 @@ export function resetToHome(passProps: LaunchProps = {launchType: LaunchType.Nor dismissModal({componentId: Screens.LOGIN}); dismissModal({componentId: Screens.SSO}); dismissModal({componentId: Screens.BOTTOM_SHEET}); + DeviceEventEmitter.emit(Events.FETCHING_POSTS, false); return; }