From 361d886314724441873b77af01565a0d3b41acf1 Mon Sep 17 00:00:00 2001 From: celian Date: Sat, 26 Nov 2022 11:28:14 +0100 Subject: [PATCH 1/6] Hot fixes --- app.json | 2 +- src/components/input/GlassButton.js | 14 ++++++++----- src/components/other/DebugUrlsMenu.js | 1 - src/components/viewSlider/ViewSlider.js | 11 +++++++++++ src/screens/Onboarding.js | 1 - src/screens/SettingScreen.js | 26 ++++++++++++++++++------- src/screens/Splash.js | 11 ++++++++--- src/services/API.js | 5 ++++- 8 files changed, 52 insertions(+), 19 deletions(-) diff --git a/app.json b/app.json index cf68085a..03adf1f9 100644 --- a/app.json +++ b/app.json @@ -6,5 +6,5 @@ "versionFlag": "private-beta-rc", "requiredServerVersion": "0.0.10", - "productionMode": true + "productionMode": false } diff --git a/src/components/input/GlassButton.js b/src/components/input/GlassButton.js index 0f220530..9d433dbc 100644 --- a/src/components/input/GlassButton.js +++ b/src/components/input/GlassButton.js @@ -3,11 +3,15 @@ import { StyleSheet, Text, TouchableOpacity } from 'react-native'; import Styles, { Colors, Fonts } from '../../styles/Styles'; const GlassButton = ({ children, onPress, buttonText, style, disabled, fontSize = 19 }) => ( - + {children == null ? ( { )} - ); }; diff --git a/src/components/viewSlider/ViewSlider.js b/src/components/viewSlider/ViewSlider.js index 38f7b69f..cf7acf99 100644 --- a/src/components/viewSlider/ViewSlider.js +++ b/src/components/viewSlider/ViewSlider.js @@ -111,6 +111,17 @@ const ViewSlider = ({ children, onViewIndexChanged = () => {} }, ref) => { )} + {currentViewIndex === 0 && ( + setCurrentViewIndex(1)} + hitSlop={{ top: 30, bottom: 30, left: 30, right: 30 }} + > + + I dont have an account + + + )} {currentViewIndex > 1 && currentViewIndex < children.length - 1 && ( { const { sendAlert } = useOverlay(); const [notificationsSettings, setNotificationsSettings] = useState(null); + const notificatinsSettingsRef = useRef(null); useEffect(() => { fetchNotificationsSettings(); + return () => { + if (notificatinsSettingsRef.current != null) + postNotificationsSettings(notificatinsSettingsRef.current); + }; }, []); useEffect(() => { - if (notificationsSettings) - postNotificationsSettings(); + if (notificationsSettings != null) + notificatinsSettingsRef.current = notificationsSettings; }, [notificationsSettings]); const fetchNotificationsSettings = async () => { @@ -57,9 +62,10 @@ const SettingsScreen = ({ navigation }) => { } }; - const postNotificationsSettings = async () => { + const postNotificationsSettings = async (settings) => { + console.log('postNotificationsSettings', settings); try { - await API.postNotificationsSettings(notificationsSettings); + await API.postNotificationsSettings(settings); } catch (error) { sendAlert({ title: 'Notifications settings not updated', @@ -173,6 +179,7 @@ const SettingsScreen = ({ navigation }) => { + {/* eslint-disable-next-line no-undef */} (user.isDeveloper || __DEV__) && setDeveloperMode((old) => !old)} activeOpacity={1}> @@ -195,7 +202,12 @@ const SettingsScreen = ({ navigation }) => { DEV MODE - {(developerMode || customUrls) && } + {(developerMode || customUrls) && ( + <> + + + + )} ); diff --git a/src/screens/Splash.js b/src/screens/Splash.js index 94ded749..801de9cb 100644 --- a/src/screens/Splash.js +++ b/src/screens/Splash.js @@ -13,7 +13,7 @@ import Storage from '../utils/storage'; const Splash = ({ navigation, route }) => { const { cancelAutoLogin = false } = route.params ?? {}; - const { setUser, user } = useCurrentUser(); + const { setUser, user, customUrls } = useCurrentUser(); const { sendAlert } = useOverlay(); @@ -26,14 +26,18 @@ const Splash = ({ navigation, route }) => { handleLoginSuccess(); }, [user]); - const navigateToOnboarding = () => navigation.reset({ index: 0, routes: [{ name: 'Onboarding' }] }); + const navigateToOnboarding = () => { + Storage.removeItem('@auth_tokens'); + navigation.reset({ index: 0, routes: [{ name: 'Onboarding' }] }); + }; const launch = async () => { const ready = await appIsReady(); console.log(`Splash launch : app is ready -> ${ready}`); if (!ready) { - navigateToOnboarding(); + if (customUrls != null) + navigateToOnboarding(); return; } @@ -61,6 +65,7 @@ const Splash = ({ navigation, route }) => { const appIsReady = async () => { try { + await API.loadCustomUrl(); const isCompatibleWithServer = await API.serverVersionIsCompatible(); if (!isCompatibleWithServer) { diff --git a/src/services/API.js b/src/services/API.js index e97f5ca8..b77ef9d5 100644 --- a/src/services/API.js +++ b/src/services/API.js @@ -16,8 +16,10 @@ const getHeaders = () => axios.defaults.headers.common; const loadCustomUrl = async () => { const customUrls = await Storage.getItem('@custom_urls'); - if (customUrls != null) + if (customUrls != null) { + console.log('Using custom urls', customUrls); axios.defaults.baseURL = customUrls.api ?? API_BASE_URL; + } }; const register = async (displayName, email, password, newsLetter) => { @@ -231,6 +233,7 @@ const API = { logout, getNotificationsSettings, postNotificationsSettings, + loadCustomUrl, }; export default API; From acac499533135bb79730d7df7d2547e4e02be8fc Mon Sep 17 00:00:00 2001 From: celian Date: Sat, 26 Nov 2022 11:52:58 +0100 Subject: [PATCH 2/6] Fix and autocomplete --- src/screens/Onboarding.js | 6 ++++++ src/screens/SettingScreen.js | 1 + 2 files changed, 7 insertions(+) diff --git a/src/screens/Onboarding.js b/src/screens/Onboarding.js index f9e6a408..7c30769b 100644 --- a/src/screens/Onboarding.js +++ b/src/screens/Onboarding.js @@ -382,6 +382,7 @@ export default function Onboarding({ navigation }) { onEdited={setEmail} isEmail defaultValue={email} + autoComplete='email' /> { }; const logout = async () => { + await postNotificationsSettings(notificatinsSettingsRef.current); await API.logout(); navigation.reset({ index: 0, From 838f38e3ed10125567da31185cc95dfabcc31cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Riboulet?= Date: Sat, 26 Nov 2022 12:08:19 +0100 Subject: [PATCH 3/6] Update src/screens/Onboarding.js --- src/screens/Onboarding.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/screens/Onboarding.js b/src/screens/Onboarding.js index 7c30769b..1583426f 100644 --- a/src/screens/Onboarding.js +++ b/src/screens/Onboarding.js @@ -422,7 +422,6 @@ export default function Onboarding({ navigation }) { ref={displayNameInputRef} minLength={3} defaultValue={displayName} - autoComplete='username' /> Date: Sat, 26 Nov 2022 16:27:33 +0100 Subject: [PATCH 4/6] Fix #322 --- src/screens/Onboarding.js | 5 ++++- src/states/UserContextProvider.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/screens/Onboarding.js b/src/screens/Onboarding.js index 7c30769b..974c67bb 100644 --- a/src/screens/Onboarding.js +++ b/src/screens/Onboarding.js @@ -222,7 +222,10 @@ export default function Onboarding({ navigation }) { try { const userInfos = await API.login(email, password); - setUser(userInfos); + // Fix #322 permissions granting messing with states -> sockets not initializing + setTimeout(() => { + setUser(userInfos); + }, 1000); } catch (error) { setLoading(false); if (error.response.status === 404) { diff --git a/src/states/UserContextProvider.js b/src/states/UserContextProvider.js index 7874cc3b..ad955640 100644 --- a/src/states/UserContextProvider.js +++ b/src/states/UserContextProvider.js @@ -15,10 +15,10 @@ const UserProvider = ({ children }) => { }, [user]); useEffect(() => { - loadStoredIPs(); + loadCustomUrls(); }, []); - const loadStoredIPs = async () => { + const loadCustomUrls = async () => { const customUrls = await Storage.getItem('@custom_urls'); if (!customUrls) return; From f13c43cca98e4928ec73a0c22f75d2527f05c47d Mon Sep 17 00:00:00 2001 From: celian Date: Sat, 26 Nov 2022 20:36:54 +0100 Subject: [PATCH 5/6] Fix url switch --- src/screens/Onboarding.js | 3 ++- src/screens/SettingScreen.js | 1 + src/screens/Splash.js | 2 +- src/services/API.js | 38 ++++++++++++++++++------------------ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/screens/Onboarding.js b/src/screens/Onboarding.js index f553d8ea..6c5fa8a5 100644 --- a/src/screens/Onboarding.js +++ b/src/screens/Onboarding.js @@ -209,7 +209,6 @@ export default function Onboarding({ navigation }) { }; const handleLogin = async () => { - setLoading(true); const emailValid = loginEmailInputRef.current?.isValid(); if (!emailValid) { @@ -221,6 +220,7 @@ export default function Onboarding({ navigation }) { await requestNotificationsPermissions(); try { + setLoading(true); const userInfos = await API.login(email, password); // Fix #322 permissions granting messing with states -> sockets not initializing setTimeout(() => { @@ -400,6 +400,7 @@ export default function Onboarding({ navigation }) { onPress={handleLogin} disabled={email.length === 0 || password.length === 0} text='Login' + loading={loading} /> diff --git a/src/screens/SettingScreen.js b/src/screens/SettingScreen.js index e83b4ce9..7a3afeb4 100644 --- a/src/screens/SettingScreen.js +++ b/src/screens/SettingScreen.js @@ -78,6 +78,7 @@ const SettingsScreen = ({ navigation }) => { const logout = async () => { await postNotificationsSettings(notificatinsSettingsRef.current); + notificatinsSettingsRef.current = null; await API.logout(); navigation.reset({ index: 0, diff --git a/src/screens/Splash.js b/src/screens/Splash.js index 801de9cb..38e53cca 100644 --- a/src/screens/Splash.js +++ b/src/screens/Splash.js @@ -65,7 +65,7 @@ const Splash = ({ navigation, route }) => { const appIsReady = async () => { try { - await API.loadCustomUrl(); + await API.init(); const isCompatibleWithServer = await API.serverVersionIsCompatible(); if (!isCompatibleWithServer) { diff --git a/src/services/API.js b/src/services/API.js index b77ef9d5..09ac9da7 100644 --- a/src/services/API.js +++ b/src/services/API.js @@ -5,23 +5,25 @@ import AppInfo from '../../app.json'; const DOMAIN_PREFIX = AppInfo.productionMode ? '' : 'preprod-'; const API_BASE_URL = `https://${DOMAIN_PREFIX}api.dropy-app.com`; -const AXIOS_PARAMS = { - baseURL: API_BASE_URL, - timeout: 5000, -}; - -let axios = Axios.create(AXIOS_PARAMS); +let axios = null; -const getHeaders = () => axios.defaults.headers.common; +const init = async () => { + let baseURL = API_BASE_URL; -const loadCustomUrl = async () => { const customUrls = await Storage.getItem('@custom_urls'); - if (customUrls != null) { + if (customUrls?.api != null) { console.log('Using custom urls', customUrls); - axios.defaults.baseURL = customUrls.api ?? API_BASE_URL; + baseURL = customUrls.api; } + + axios = Axios.create({ + baseURL, + timeout: 5000, + }); }; +const getHeaders = () => axios.defaults.headers.common; + const register = async (displayName, email, password, newsLetter) => { const response = await axios.post('/register', { displayName, @@ -32,7 +34,7 @@ const register = async (displayName, email, password, newsLetter) => { const { accessToken, refreshToken, expires, profile: user } = response.data; - axios = Axios.create(AXIOS_PARAMS); + await init(); axios.defaults.headers.common.Authorization = accessToken; await Storage.setItem('@auth_tokens', { accessToken, refreshToken, expires }); @@ -48,8 +50,7 @@ const login = async (email, password) => { const { accessToken, refreshToken, expires, profile: user } = response.data; - axios = Axios.create(AXIOS_PARAMS); - loadCustomUrl(); + await init(); axios.defaults.headers.common.Authorization = accessToken; await Storage.setItem('@auth_tokens', { accessToken, refreshToken, expires }); @@ -57,7 +58,7 @@ const login = async (email, password) => { return user; }; -const refreshTokenUrl = () => `${API_BASE_URL}/refresh`; +const refreshTokenUrl = () => `${axios.defaults.baseURL}/refresh`; const postUserDeviceToken = (deviceToken) => { const result = axios.post('/user/updateDeviceToken', { @@ -66,7 +67,7 @@ const postUserDeviceToken = (deviceToken) => { return result; }; -const userBackgroundGeolocationPingUrl = () => `${API_BASE_URL}/user/backgroundGeolocationPing`; +const userBackgroundGeolocationPingUrl = () => `${axios.defaults.baseURL}/user/backgroundGeolocationPing`; const getDropyMedia = async (dropyId) => { const result = await axios.get(`/dropy/${dropyId}/media`); @@ -176,7 +177,7 @@ const refreshToken = async (token) => { const { accessToken, refreshToken, expires } = response.data; - axios = Axios.create(AXIOS_PARAMS); + await init(); axios.defaults.headers.common.Authorization = accessToken; await Storage.setItem('@auth_tokens', { accessToken, refreshToken, expires }); @@ -190,8 +191,7 @@ const getUserProfile = async () => { }; const logout = async () => { - axios = Axios.create(AXIOS_PARAMS); - loadCustomUrl(); + await init(); const removedItem = await Storage.removeItem('@auth_tokens'); return removedItem; }; @@ -233,7 +233,7 @@ const API = { logout, getNotificationsSettings, postNotificationsSettings, - loadCustomUrl, + init, }; export default API; From ea5de4af49ffb1f83a2ba3e316914bf0bffe5f49 Mon Sep 17 00:00:00 2001 From: celian Date: Sat, 26 Nov 2022 20:40:56 +0100 Subject: [PATCH 6/6] Remove token delete --- src/screens/Splash.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/screens/Splash.js b/src/screens/Splash.js index 38e53cca..07faf645 100644 --- a/src/screens/Splash.js +++ b/src/screens/Splash.js @@ -27,7 +27,6 @@ const Splash = ({ navigation, route }) => { }, [user]); const navigateToOnboarding = () => { - Storage.removeItem('@auth_tokens'); navigation.reset({ index: 0, routes: [{ name: 'Onboarding' }] }); };