1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-14 11:18:47 +02:00

91 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-07-29 15:43:53 +02:00
const React = require('react');
2019-07-29 15:58:33 +02:00
const { View, Button, Text, TextInput, TouchableOpacity, StyleSheet, ScrollView } = require('react-native');
2018-03-27 00:55:44 +01:00
const { connect } = require('react-redux');
const { ScreenHeader } = require('../ScreenHeader');
const { _ } = require('@joplin/lib/locale');
2020-11-05 16:58:23 +00:00
const { BaseScreenComponent } = require('../base-screen.js');
const DialogBox = require('react-native-dialogbox').default;
2020-11-05 16:58:23 +00:00
const { dialogs } = require('../../utils/dialogs.js');
const Shared = require('@joplin/lib/components/shared/dropbox-login-shared');
2020-11-05 16:58:23 +00:00
const { themeStyle } = require('../global-style.js');
2018-03-27 00:55:44 +01:00
class DropboxLoginScreenComponent extends BaseScreenComponent {
constructor() {
super();
2018-03-27 17:41:19 +00:00
this.styles_ = {};
this.shared_ = new Shared(this, msg => dialogs.info(this, msg), msg => dialogs.error(this, msg));
2018-03-27 00:55:44 +01:00
}
UNSAFE_componentWillMount() {
2018-03-27 00:55:44 +01:00
this.shared_.refreshUrl();
}
2018-03-27 17:41:19 +00:00
styles() {
2020-09-15 14:01:07 +01:00
const themeId = this.props.themeId;
2018-03-27 17:41:19 +00:00
const theme = themeStyle(themeId);
if (this.styles_[themeId]) return this.styles_[themeId];
this.styles_ = {};
const styles = {
2020-06-20 11:14:01 +01:00
screen: {
flex: 1,
backgroundColor: theme.backgroundColor,
},
2018-03-27 17:41:19 +00:00
container: {
padding: theme.margin,
backgroundColor: theme.backgroundColor,
2018-03-27 17:41:19 +00:00
},
stepText: { ...theme.normalText, marginBottom: theme.margin },
urlText: { ...theme.urlText, marginBottom: theme.margin },
2019-07-29 15:43:53 +02:00
};
2018-03-27 17:41:19 +00:00
this.styles_[themeId] = StyleSheet.create(styles);
return this.styles_[themeId];
}
2018-03-27 00:55:44 +01:00
render() {
2020-09-15 14:01:07 +01:00
const theme = themeStyle(this.props.themeId);
2018-03-27 17:41:19 +00:00
2018-03-27 00:55:44 +01:00
return (
<View style={this.styles().screen}>
2019-07-29 15:43:53 +02:00
<ScreenHeader title={_('Login with Dropbox')} />
<ScrollView style={this.styles().container}>
2018-03-27 17:41:19 +00:00
<Text style={this.styles().stepText}>{_('To allow Joplin to synchronise with Dropbox, please follow the steps below:')}</Text>
<Text style={this.styles().stepText}>{_('Step 1: Open this URL in your browser to authorise the application:')}</Text>
<View>
<TouchableOpacity onPress={this.shared_.loginUrl_click}>
<Text style={this.styles().urlText}>{this.state.loginUrl}</Text>
</TouchableOpacity>
</View>
<Text style={this.styles().stepText}>{_('Step 2: Enter the code provided by Dropbox:')}</Text>
<TextInput placeholder={_('Enter code here')} placeholderTextColor={theme.colorFaded} selectionColor={theme.textSelectionColor} keyboardAppearance={theme.keyboardAppearance} value={this.state.authCode} onChangeText={this.shared_.authCodeInput_change} style={theme.lineInput} />
2019-07-29 15:43:53 +02:00
<View style={{ height: 10 }}></View>
<Button disabled={this.state.checkingAuthToken} title={_('Submit')} onPress={this.shared_.submit_click}></Button>
{/* Add this extra padding to make sure the view is scrollable when the keyboard is visible on small screens (iPhone SE) */}
<View style={{ height: 200 }}></View>
</ScrollView>
<DialogBox
ref={dialogbox => {
this.dialogbox = dialogbox;
}}
/>
2018-03-27 00:55:44 +01:00
</View>
);
}
}
const DropboxLoginScreen = connect(state => {
2018-03-27 17:41:19 +00:00
return {
2020-09-15 14:01:07 +01:00
themeId: state.settings.theme,
2018-03-27 17:41:19 +00:00
};
2019-07-29 15:43:53 +02:00
})(DropboxLoginScreenComponent);
2018-03-27 00:55:44 +01:00
2019-07-29 15:43:53 +02:00
module.exports = { DropboxLoginScreen };