Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Hot fixes 0.0.10 #323

Merged
merged 7 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"versionFlag": "private-beta-rc",
"requiredServerVersion": "0.0.10",

"productionMode": true
"productionMode": false
}
14 changes: 9 additions & 5 deletions src/components/input/GlassButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<TouchableOpacity onPress={onPress} disabled={disabled} style={{
...styles.container,
...style,
backgroundColor: disabled ? Colors.purple2 : Colors.purple1,
}}>
<TouchableOpacity
onPress={onPress}
disabled={disabled}
style={{
...styles.container,
...style,
backgroundColor: disabled ? `${Colors.lightGrey}60` : Colors.purple1,
shadowOpacity: disabled ? 0 : 0.5,
}}>
{children == null ? (
<Text style={{
...Fonts.bold(fontSize, Colors.white),
Expand Down
1 change: 0 additions & 1 deletion src/components/other/DebugUrlsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const DebugUrlsMenu = () => {
</>
)}
</View>

);
};

Expand Down
11 changes: 11 additions & 0 deletions src/components/viewSlider/ViewSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ const ViewSlider = ({ children, onViewIndexChanged = () => {} }, ref) => {
</Text>
</TouchableOpacity>
)}
{currentViewIndex === 0 && (
<TouchableOpacity
style={{ ...Styles.center, position: 'absolute', bottom: 0, width: '100%' }}
onPress={() => setCurrentViewIndex(1)}
hitSlop={{ top: 30, bottom: 30, left: 30, right: 30 }}
>
<Text style={{ marginBottom: 10, ...Fonts.bold(13, Colors.lightGrey) }}>
I dont have an account
</Text>
</TouchableOpacity>
)}
{currentViewIndex > 1 && currentViewIndex < children.length - 1 && (
<DotIndicator
currentIndex={currentViewIndex - 1}
Expand Down
14 changes: 11 additions & 3 deletions src/screens/Onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { AntDesign, FontAwesome5, MaterialCommunityIcons, MaterialIcons } from '
import { openCamera, openPicker } from 'react-native-image-crop-picker';
import { useActionSheet } from '@expo/react-native-action-sheet';
import { PERMISSIONS, request, requestNotifications, RESULTS } from 'react-native-permissions';
import BackgroundGeolocation from 'react-native-background-geolocation';
import DropyLogo from '../assets/svgs/dropy_logo_grey.svg';
import Styles, { Colors, Fonts } from '../styles/Styles';
import OnboardingLines from '../assets/svgs/onboarding_lines.svg';
Expand Down Expand Up @@ -210,7 +209,6 @@ export default function Onboarding({ navigation }) {
};

const handleLogin = async () => {
setLoading(true);
const emailValid = loginEmailInputRef.current?.isValid();

if (!emailValid) {
Expand All @@ -222,8 +220,12 @@ export default function Onboarding({ navigation }) {
await requestNotificationsPermissions();

try {
setLoading(true);
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) {
Expand Down Expand Up @@ -383,19 +385,22 @@ export default function Onboarding({ navigation }) {
onEdited={setEmail}
isEmail
defaultValue={email}
autoComplete='email'
/>
<FormInput
placeholder='Password'
inputStyle={{ backgroundColor: Colors.lighterGrey }}
isPassword
onEdited={setPassword}
defaultValue={password}
autoComplete='password'
/>
</View>
<LoadingGlassButton
onPress={handleLogin}
disabled={email.length === 0 || password.length === 0}
text='Login'
loading={loading}
/>
</View>

Expand Down Expand Up @@ -463,6 +468,7 @@ export default function Onboarding({ navigation }) {
inputStyle={{ backgroundColor: Colors.lighterGrey }}
isEmail
defaultValue={email}
autoComplete='email'
/>
<FormInput
ref={passwordInputRef}
Expand All @@ -471,6 +477,7 @@ export default function Onboarding({ navigation }) {
inputStyle={{ backgroundColor: Colors.lighterGrey }}
isPassword
defaultValue={password}
autoComplete='password-new'
/>
<FormInput
ref={passwordConfirmationInputRef}
Expand All @@ -479,6 +486,7 @@ export default function Onboarding({ navigation }) {
inputStyle={{ backgroundColor: Colors.lighterGrey }}
isPassword
defaultValue={passwordConfirmation}
autoComplete='password-new'
/>
</View>
<LoadingGlassButton
Expand Down
28 changes: 21 additions & 7 deletions src/screens/SettingScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-undef */
import React, { useContext, useEffect, useState } from 'react';
import React, { useContext, useEffect, useRef, useState } from 'react';
import {
Linking,
SafeAreaView,
Expand All @@ -12,6 +11,7 @@ import {
} from 'react-native';
import { responsiveWidth } from 'react-native-responsive-dimensions';
import { AntDesign, Feather, Ionicons } from '@expo/vector-icons';
import KeyboardSpacer from 'react-native-keyboard-spacer';
import AppInfo from '../../app.json';
import Styles, { Colors, Fonts } from '../styles/Styles';
import { BackgroundGeolocationContext } from '../states/BackgroundGolocationContextProvider';
Expand All @@ -32,14 +32,19 @@ const SettingsScreen = ({ navigation }) => {
const { sendAlert } = useOverlay();

const [notificationsSettings, setNotificationsSettings] = useState(null);
const notificatinsSettingsRef = useRef(null);

useEffect(() => {
fetchNotificationsSettings();
return () => {
if (notificatinsSettingsRef.current != null)
postNotificationsSettings(notificatinsSettingsRef.current);
};
celian-rib marked this conversation as resolved.
Show resolved Hide resolved
}, []);

useEffect(() => {
if (notificationsSettings)
postNotificationsSettings();
if (notificationsSettings != null)
notificatinsSettingsRef.current = notificationsSettings;
}, [notificationsSettings]);

const fetchNotificationsSettings = async () => {
Expand All @@ -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',
Expand All @@ -71,6 +77,8 @@ const SettingsScreen = ({ navigation }) => {
};

const logout = async () => {
await postNotificationsSettings(notificatinsSettingsRef.current);
notificatinsSettingsRef.current = null;
await API.logout();
navigation.reset({
index: 0,
Expand Down Expand Up @@ -173,6 +181,7 @@ const SettingsScreen = ({ navigation }) => {

<View style={styles.spacer} />

{/* eslint-disable-next-line no-undef */}
<TouchableOpacity onLongPress={() => (user.isDeveloper || __DEV__) && setDeveloperMode((old) => !old)} activeOpacity={1}>
<View style={styles.infoTextContainer}>
<Ionicons name='git-branch' size={19} color={Colors.darkGrey} />
Expand All @@ -195,7 +204,12 @@ const SettingsScreen = ({ navigation }) => {
</TouchableOpacity>

<DebugText marginBottom={20}>DEV MODE</DebugText>
{(developerMode || customUrls) && <DebugUrlsMenu /> }
{(developerMode || customUrls) && (
<>
<DebugUrlsMenu />
<KeyboardSpacer />
</>
)}
</ScrollView>
</SafeAreaView>
);
Expand Down
10 changes: 7 additions & 3 deletions src/screens/Splash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -26,14 +26,17 @@ const Splash = ({ navigation, route }) => {
handleLoginSuccess();
}, [user]);

const navigateToOnboarding = () => navigation.reset({ index: 0, routes: [{ name: 'Onboarding' }] });
const navigateToOnboarding = () => {
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;
}

Expand Down Expand Up @@ -61,6 +64,7 @@ const Splash = ({ navigation, route }) => {

const appIsReady = async () => {
try {
await API.init();
const isCompatibleWithServer = await API.serverVersionIsCompatible();

if (!isCompatibleWithServer) {
Expand Down
39 changes: 21 additions & 18 deletions src/services/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +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)
axios.defaults.baseURL = customUrls.api ?? API_BASE_URL;
if (customUrls?.api != null) {
console.log('Using custom urls', customUrls);
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,
Expand All @@ -30,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 });
Expand All @@ -46,16 +50,15 @@ 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 });

return user;
};

const refreshTokenUrl = () => `${API_BASE_URL}/refresh`;
const refreshTokenUrl = () => `${axios.defaults.baseURL}/refresh`;

const postUserDeviceToken = (deviceToken) => {
const result = axios.post('/user/updateDeviceToken', {
Expand All @@ -64,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`);
Expand Down Expand Up @@ -174,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 });
Expand All @@ -188,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;
};
Expand Down Expand Up @@ -231,6 +233,7 @@ const API = {
logout,
getNotificationsSettings,
postNotificationsSettings,
init,
};

export default API;
4 changes: 2 additions & 2 deletions src/states/UserContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down