import React from 'react';
// Redux
import { Provider } from 'react-redux';
import { store } from './App/Store/ConfigureStore';
// Deps
import 'react-native-gesture-handler';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { TouchableOpacity, View, Image, Text, TextInput, StyleSheet, Alert } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome5';
import FlashMessage, { showMessage } from 'react-native-flash-message';
import * as SplashScreen from 'expo-splash-screen';
// i18n
import i18n from "./I18n";
// FileSytem
import * as FileSystem from 'expo-file-system';
// Controllers
import SyncController from './App/Controllers/SyncController';
// Views
import InstallScreen from './App/Views/InstallScreen';
import LoginScreen from './App/Views/LoginScreen';
import SyncScreen from './App/Views/SyncScreen';
import HomeScreen from './App/Views/HomeScreen';
import DirectoriesScreen from './App/Views/DirectoriesScreen';
import PDFScreen from './App/Views/PDFScreen';
import VideoScreen from './App/Views/VideoScreen';
import OnlyVideosScreen from './App/Views/OnlyVideosScreen';
import ContactScreen from './App/Views/ContactScreen';
import ContactDetailsScreen from './App/Views/ContactDetailsScreen';
import SearchScreen from "./App/Views/SearchScreen";
import MySpaceScreen from './App/Views/MySpaceScreen';
// Style
import styles from './Resources/Styles/NavigationStyle';
SplashScreen.preventAutoHideAsync(); //Keep
store.dispatch({ type: 'INIT' });
store.dispatch({ type: 'INIT_LOCALE' });
store.dispatch({ type: 'INIT_USERS' });
const Stack = createNativeStackNavigator();
class App extends React.Component {
state = {
isSetup: false,
isLogged: false,
searchTxt: '',
sendEmail: '',
mainColor: ''
};
componentDidMount() {
const unsubscribe = store.subscribe(this.handleChange.bind(this));
this.setState({
isSetup: store.getState().app.isSetup,
isLogged: store.getState().app.logged,
mainColor: store.getState().app.mainColor
});
}
handleChange() {
this.setState({
isSetup: store.getState().app.isSetup,
isLogged: store.getState().app.logged,
mainColor: store.getState().app.mainColor
}); // to force re-rendering
console.log("state changed")
}
render() {
return (
{this.state.isSetup === false &&
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('install.installation'), false),
headerRight: () => (
{
store.dispatch({ type: 'EDIT_LOCALE' });
}}
style={{ marginRight: 15 }}>
),
})}
/>
}
{this.state.isLogged === false ? (
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('global.login'), false),
headerRight: () => (
{
store.dispatch({ type: 'EDIT_LOCALE' });
}}
style={{ marginRight: 15 }}>
),
})}
/>
) : (
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('global.home')),
headerRight: () => (
this.setState({ searchTxt: text })}
/>
{
if (this.state.searchTxt.length > 0) {
navigation.navigation.navigate('SearchScreen', {
needle: this.state.searchTxt,
onlyVideos: false,
});
this.setState({ searchTxt: '' });
}
}}>
{
store.dispatch({ type: 'EDIT_LOCALE' });
}}
style={{ marginRight: 25 }}>
{store.getState().app.ShowIsActive === '1' && (
navigation.navigation.navigate('MySpaceScreen')}
style={{ marginRight: 25 }}>
)}
navigation.navigation.navigate('SyncScreen')
}
style={{ marginRight: 25 }}>
{
store.dispatch({ type: 'SET_CURRENT_USER', data: false });
}}
style={{ marginRight: 25 }}>
),
})}
/>
)}
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('global.synchronization'))
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('app.folders'))
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('global.videos')),
headerRight: () => (
this.setState({ searchTxt: text })} />
{
if (this.state.searchTxt.length > 0) {
navigation.navigation.navigate('SearchScreen', {
needle: this.state.searchTxt,
onlyVideos: true,
});
this.setState({ searchTxt: '' });
}
}}>
),
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('app.video')),
headerRight: () => this.SendEmail(),
orientation: 'landscape'
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, 'PDF'),
headerRight: () => this.SendEmail()
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('global.contacts'))
})}
initialParams={{ contactAdded: false }}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('app.contact_details'))
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('app.results_search'))
})}
/>
({
headerTitle: () => this.LogoTitle(navigation, i18n.t('app.my_space')),
headerRight: () => (
{
const folder = store.getState().directories.treeview.filter(tmp => tmp.id === 1);
navigation.navigation.navigate('DirectoriesScreen', { folder: folder })
}}
style={{ marginRight: 15 }}>
),
})}
/>
);
}
LogoTitle(navigation, title, wantBtn = true) {
console.log(this.state.isSetup)
return (
{
if (wantBtn) {
navigation.navigation.navigate('HomeScreen')
}
}}>
{this.state.isSetup ? (
) : (
)}
{title}
);
}
SendEmail() {
return (
this.setState({ sendEmail: text })} />
{
if (this.state.sendEmail.length > 0) {
if (Helpers.isEmailValid(this.state.sendEmail)) {
const email = {
email: this.state.sendEmail,
subject: i18n.t('app.file_sharing'),
message: '',
documents: JSON.stringify([store.getState().currentOpenedDoc]),
user_id: store.getState().currentUser.id
};
store.dispatch({ type: 'SEND_BROCHURE', data: email });
showMessage({
message: i18n.t('global.message_sent') + '.',
description: i18n.t('global.message_will_be_sent_after_sync') + '.',
type: 'success',
duration: 1500,
});
this.setState({ sendEmail: '' });
} else {
Alert.alert(i18n.t('global.warning') + ' !', i18n.t('error.invalid_email_address') + '.', [
{ text: 'OK' },
],
{ cancelable: false },
);
}
}
}}>
);
}
renderFlag() {
let flag;
switch (store.getState().locale.locale) {
case "fr":
flag = require('./assets/img/flags/fr.png');
break;
case "en":
flag = require('./assets/img/flags/en.png');
break;
case "de":
flag = require('./assets/img/flags/de.png');
break;
case "es":
flag = require('./assets/img/flags/es.png');
break;
}
return flag;
}
}
export default App;