From ca053ed9c4deb719ef58ca058718081df39a3f50 Mon Sep 17 00:00:00 2001 From: Pablo Velez Vidal Date: Sat, 12 Nov 2022 17:06:07 +0100 Subject: [PATCH] more advances on initial launch --- app/init/launch.ts | 15 +++++---------- app/screens/navigation.ts | 9 ++++++--- app/screens/onboarding/index.tsx | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/init/launch.ts b/app/init/launch.ts index 017574007..9adbbcd27 100644 --- a/app/init/launch.ts +++ b/app/init/launch.ts @@ -19,7 +19,6 @@ import {convertToNotificationData} from '@utils/notification'; import {parseDeepLink} from '@utils/url'; import type {DeepLinkChannel, DeepLinkDM, DeepLinkGM, DeepLinkPermalink, DeepLinkWithData, LaunchProps} from '@typings/launch'; -import { fetchConfigAndLicense } from '@actions/remote/systems'; const initialNotificationTypes = [PushNotification.NOTIFICATION_TYPE.MESSAGE, PushNotification.NOTIFICATION_TYPE.SESSION]; @@ -59,7 +58,6 @@ const launchAppFromNotification = async (notification: NotificationWithData) => launchApp(props); }; -// pablo - here I need to validate the logic for launching the onboarding screen const launchApp = async (props: LaunchProps, resetNavigation = true) => { let serverUrl: string | undefined; switch (props?.launchType) { @@ -102,10 +100,9 @@ const launchApp = async (props: LaunchProps, resetNavigation = true) => { // if (!onboardingAlreadyShown) { // here, check if there is not an active session and redirect to onboarding with a flag, so the sign in button will // redirect to the sign in - // return launchToOnboarding(props, goToLoginPage); + // return launchToOnboarding(props, goToLoginServerUrlPage); // } - console.log('\n\n first launch to onboarding \n\n', serverUrl); - return launchToOnboarding(props, resetNavigation, false, false, true, serverUrl); + return launchToOnboarding(props, resetNavigation, false, false, serverUrl); let launchType = props.launchType; if (!hasCurrentUser) { @@ -139,7 +136,6 @@ const launchApp = async (props: LaunchProps, resetNavigation = true) => { // if (onboardingAlreadyShown) { // // launchToServer(props, resetNavigation); // } - console.log('\n\n second launch to onboarding \n\n', serverUrl); return launchToOnboarding(props, resetNavigation); }; @@ -199,8 +195,7 @@ const launchToOnboarding = ( resetNavigation = true, notActiveSession = true, whiteLabeledApp = false, - goToLogIn = true, - serverUrl = '', + goToLoginServerUrl = '', ) => { // here, if there is an active session, redirect to home // if there is a whitelabeled app, redirect to either SERVER or LOGIN but don't show the onboarding @@ -208,8 +203,8 @@ const launchToOnboarding = ( launchToServer(props, resetNavigation); } - // if there is not an active session, pass the prop and redirect to the LOGIN page (keep in mind all the redirection login to check for SSO stuff) - return resetToOnboarding(props, true, serverUrl); + // goToLoginServerUrl will contain a value when there is a server already configured but not a active session + return resetToOnboarding(props, goToLoginServerUrl); }; export const relaunchApp = (props: LaunchProps, resetNavigation = false) => { diff --git a/app/screens/navigation.ts b/app/screens/navigation.ts index 680406507..32c03db7c 100644 --- a/app/screens/navigation.ts +++ b/app/screens/navigation.ts @@ -281,7 +281,7 @@ export function resetToSelectServer(passProps: LaunchProps) { }); } -export function resetToOnboarding(passProps: LaunchProps, goToLogIn: boolean, serverUrl: string) { +export function resetToOnboarding(passProps: LaunchProps, goToLoginServerUrl: string) { const theme = getDefaultThemeByAppearance(); const isDark = tinyColor(theme.sidebarBg).isDark(); StatusBar.setBarStyle(isDark ? 'light-content' : 'dark-content'); @@ -295,8 +295,7 @@ export function resetToOnboarding(passProps: LaunchProps, goToLogIn: boolean, se passProps: { ...passProps, theme, - goToLogIn, - serverUrl, + goToLoginServerUrl, }, options: { layout: { @@ -411,6 +410,10 @@ export function goToScreen(name: string, title: string, passProps = {}, options }, }; + if (name === Screens.SERVER) { + console.log('\n\n** screen pass props', passProps, componentId, name, '\n\n'); + } + return Navigation.push(componentId, { component: { id: name, diff --git a/app/screens/onboarding/index.tsx b/app/screens/onboarding/index.tsx index 12a4b9e9f..3f4213957 100644 --- a/app/screens/onboarding/index.tsx +++ b/app/screens/onboarding/index.tsx @@ -21,16 +21,14 @@ import type {LaunchProps} from '@typings/launch'; interface OnboardingProps extends LaunchProps { theme: Theme; - goToLogIn: boolean; - serverUrl: string; + goToLoginServerUrl: string; } const AnimatedSafeArea = Animated.createAnimatedComponent(SafeAreaView); const Onboarding = ({ theme, - goToLogIn, - serverUrl, + goToLoginServerUrl, }: OnboardingProps) => { const {width} = useWindowDimensions(); const styles = getStyleSheet(theme); @@ -72,7 +70,7 @@ const Onboarding = ({ }, [currentIndex.value, slidesRef.current, moveToSlide]); const initLogin = async () => { - const data = await fetchConfigAndLicense(serverUrl, true); + const data = await fetchConfigAndLicense(goToLoginServerUrl, true); if (data.error) { console.log('Error getting the config and license information'); return; @@ -89,7 +87,7 @@ const Onboarding = ({ hasLoginForm, license, serverDisplayName: displayName, - serverUrl, + serverUrl: goToLoginServerUrl, ssoOptions, theme, }; @@ -105,9 +103,6 @@ const Onboarding = ({ }; const signInHandler = useCallback(() => { - if (goToLogIn) { - initLogin(); - } const topBar = { visible: true, drawBehind: true, @@ -121,8 +116,13 @@ const Onboarding = ({ title: '', }, }; + + if (goToLoginServerUrl) { + initLogin(); + return; + } goToScreen(Screens.SERVER, '', {theme}, {topBar}); - }, [goToLogIn]); + }, [goToLoginServerUrl]); const renderSlide = useCallback(({item, index}: ListRenderItemInfo) => { return (