Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #148 : Google drive #151

Closed
wants to merge 4 commits into from
Closed
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
53 changes: 41 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@buttercup/dropbox-client": "^0.1.1",
"@buttercup/googledrive-client": "^0.2.1",
"@perrymitchell/react-native-prompt": "^1.1.0",
"@tradle/react-native-http": "^2.0.0",
"@yfuks/react-native-action-sheet": "0.0.4",
Expand Down
Binary file added resources/images/googledrive-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions source/actions/googleDrive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createAction } from "redux-actions";
import {
GOOGLE_DRIVE_RESET_AUTH,
GOOGLE_DRIVE_SET_AUTHENTICATED,
GOOGLE_DRIVE_SET_AUTHENTICATING,
GOOGLE_DRIVE_SET_AUTH_TOKEN
} from "./types.js";

export const resetGoogleDriveAuth = createAction(GOOGLE_DRIVE_RESET_AUTH);
export const setGoogleDriveAuthenticated = createAction(GOOGLE_DRIVE_SET_AUTHENTICATED);
export const setGoogleDriveAuthenticating = createAction(GOOGLE_DRIVE_SET_AUTHENTICATING);
export const setGoogleDriveAuthToken = createAction(GOOGLE_DRIVE_SET_AUTH_TOKEN);
5 changes: 5 additions & 0 deletions source/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const DROPBOX_SET_AUTHENTICATED = "dropbox/setAuthenticated";
export const DROPBOX_SET_AUTHENTICATING = "dropbox/setAuthenticating";
export const DROPBOX_SET_AUTH_TOKEN = "dropbox/setAuthToken";

export const GOOGLE_DRIVE_RESET_AUTH = "googleDrive/resetAuthentication";
export const GOOGLE_DRIVE_SET_AUTHENTICATED = "googleDrive/setAuthenticated";
export const GOOGLE_DRIVE_SET_AUTHENTICATING = "googleDrive/setAuthenticating";
export const GOOGLE_DRIVE_SET_AUTH_TOKEN = "googleDrive/setAuthToken";

export const ENTRY_LOAD = "entry/load";
export const ENTRY_NEW_CLEAR = "entry/clearNew";
export const ENTRY_NEW_META_CLEAR = "entry/clearNewMeta";
Expand Down
32 changes: 32 additions & 0 deletions source/components/GoogleDriveAuthButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Cell, CellGroup } from "react-native-cell-components";

class GoogleDriveAuthButton extends Component {
beginAuthentication() {
this.props.onClick();
}

render() {
const title = this.props.authenticated ? "Authenticated" : "Authenticate";
return (
<CellGroup>
<Cell
title={title}
icon={{ name: "google-drive", source: "font-awesome" }}
onPress={() => this.beginAuthentication()}
tintColor="#1144FF"
disabled={this.props.authenticating || this.props.authenticated}
/>
</CellGroup>
);
}
}

GoogleDriveAuthButton.propTypes = {
authenticated: PropTypes.bool.isRequired,
authenticating: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired
};

export default GoogleDriveAuthButton;
29 changes: 28 additions & 1 deletion source/components/RemoteConnectPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Keyboard, StyleSheet, TouchableWithoutFeedback, View } from "react-nati
import { Cell, CellGroup, CellInput } from "react-native-cell-components";
import PropTypes from "prop-types";
import DropboxAuthButton from "../containers/DropboxAuthButton.js";
import GoogleDriveAuthButton from "../containers/GoogleDriveAuthButton.js";
import Spinner from "./Spinner.js";

const styles = StyleSheet.create({
Expand Down Expand Up @@ -30,6 +31,8 @@ class RemoteConnectPage extends Component {

render() {
switch (this.props.archiveType) {
case "googleDrive":
return this.renderGoogleDrive();
case "dropbox":
return this.renderDropbox();
case "webdav":
Expand All @@ -44,6 +47,28 @@ class RemoteConnectPage extends Component {
}
}

renderGoogleDrive() {
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<View>
<GoogleDriveAuthButton />
<CellGroup>
<Cell
title="Connect"
icon="cloud"
onPress={() => this.submit()}
tintColor="#1144FF"
disabled={!this.props.googledriveAuthenticated}
/>
</CellGroup>
</View>
<Spinner visible={this.props.connecting} text="Connecting" />
</View>
</TouchableWithoutFeedback>
);
}

renderDropbox() {
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
Expand Down Expand Up @@ -127,6 +152,7 @@ RemoteConnectPage.propTypes = {
archiveType: PropTypes.string,
connecting: PropTypes.bool,
dropboxAuthenticated: PropTypes.bool,
googledriveAuthenticated: PropTypes.bool,
initiateConnection: PropTypes.func,
onChangePassword: PropTypes.func,
onChangeURL: PropTypes.func,
Expand All @@ -138,7 +164,8 @@ RemoteConnectPage.propTypes = {
};

RemoteConnectPage.defaultProps = {
dropboxAuthenticated: false
dropboxAuthenticated: false,
googledriveAuthenticated: false
};

export default RemoteConnectPage;
22 changes: 22 additions & 0 deletions source/containers/GoogleDriveAuthButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { connect } from "react-redux";
import GoogleDriveAuthButton from "../components/GoogleDriveAuthButton.js";
import { isAuthenticated, isAuthenticating } from "../selectors/googleDrive.js";
import { setBrowserURL } from "../actions/browser.js";
import { generateAuthorisationURL } from "../library/googleDrive.js";
import { navigateToPopupBrowser } from "../actions/navigation.js";
import { setGoogleDriveAuthenticating } from "../actions/googleDrive.js";

export default connect(
(state, ownProps) => ({
authenticated: isAuthenticated(state),
authenticating: isAuthenticating(state)
}),
{
onClick: () => dispatch => {
const url = generateAuthorisationURL();
dispatch(setBrowserURL(url));
dispatch(setGoogleDriveAuthenticating(true));
dispatch(navigateToPopupBrowser("googleDrive"));
}
}
)(GoogleDriveAuthButton);
7 changes: 6 additions & 1 deletion source/containers/RemoteConnectPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isConnecting
} from "../selectors/RemoteConnectPage.js";
import { getToken, isAuthenticated } from "../selectors/dropbox.js";
import { getGoogleDriveToken, isGoogleDriveAuthenticated } from "../selectors/googleDrive.js";
import {
clearArchiveDetails,
disconnect,
Expand All @@ -26,7 +27,8 @@ function handleConnectionCreation(dispatch, getState) {
const state = getState();
const remoteConnInfo = getRemoteConnectionInfo(state);
const dropboxToken = getToken(state);
return createRemoteConnection({ ...remoteConnInfo, dropboxToken })
const googleToken = getGoogleDriveToken(state);
return createRemoteConnection({ ...remoteConnInfo, dropboxToken, googleToken })
.then(function __onConnected() {
const state = getState();
let title = "Remote";
Expand All @@ -36,6 +38,8 @@ function handleConnectionCreation(dispatch, getState) {
title = domain;
} else if (dropboxToken) {
title = "dropbox.com";
} else if (dropboxToken) {
title = "drive.google.com";
}
dispatch(onConnected());
dispatch(navigateToRemoteExplorer({ title }));
Expand All @@ -51,6 +55,7 @@ export default connect(
archiveType: getArchiveType(state),
connecting: isConnecting(state),
dropboxAuthenticated: isAuthenticated(state),
googleDriveAuthenticated: isGoogleDriveAuthenticated(state),
url: getRemoteURL(state),
...getRemoteCredentials(state)
}),
Expand Down
5 changes: 5 additions & 0 deletions source/library/archives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { formatArchiveTypeTitle } from "./format.js";

export function getArchiveTypeDetails() {
return [
{
type: "googleDrive",
title: formatArchiveTypeTitle("googleDrive"),
image: require("../../resources/images/googledrive-256.png")
},
{
type: "dropbox",
title: formatArchiveTypeTitle("dropbox"),
Expand Down
2 changes: 2 additions & 0 deletions source/library/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function formatArchiveTypeTitle(type) {
return "Nextcloud";
case "dropbox":
return "Dropbox";
case "googleDrive":
return "Google Drive";
default:
return type;
}
Expand Down
Loading