-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
8,206 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,49 @@ | ||
import { | ||
React | ||
} from 'nylas-exports'; | ||
import { React } from 'nylas-exports'; | ||
import request from 'superagent'; | ||
import { | ||
remote | ||
} from 'electron'; | ||
var BrowserWindow = remote.BrowserWindow; | ||
var loginWindow; | ||
import { remote } from 'electron'; | ||
const { BrowserWindow } = remote; | ||
|
||
module.exports = React.createClass({ | ||
export default class Login extends React.Component{ | ||
|
||
render: function(){ | ||
static propTypes = { | ||
credentials: React.PropTypes.object | ||
} | ||
|
||
render(){ | ||
return <button className="n1todoist-loginbtn" onClick={this.handleLoginClick}> Login </button> | ||
}, | ||
} | ||
|
||
handleLoginClick: function(){ | ||
var loginUrl = this.props.credentials.oauth + '?client_id=' + this.props.credentials.clientId + '&scope=' + this.props.credentials.scopes; | ||
loginWindow = new BrowserWindow({ width: 400, height: 500, show: false, 'node-integration': false }); | ||
loginWindow.loadURL(loginUrl); | ||
loginWindow.show(); | ||
loginWindow.webContents.on('did-get-redirect-request',this.handleLoginCallback); | ||
}, | ||
handleLoginClick = () => { | ||
const loginUrl = this.props.credentials.oauth + '?client_id=' + this.props.credentials.clientId + '&scope=' + this.props.credentials.scopes; | ||
this.loginWindow = new BrowserWindow({ width: 400, height: 500, show: false, 'node-integration': false }); | ||
this.loginWindow.loadURL(loginUrl); | ||
this.loginWindow.show(); | ||
this.loginWindow.webContents.on('did-get-redirect-request',this.handleLoginCallback); | ||
} | ||
|
||
handleLogoutClick: function(){ | ||
handleLogoutClick = () => { | ||
localStorage.removeItem("N1todoist_authentication"); | ||
this.setState({authenticated: false}); | ||
}, | ||
|
||
|
||
handleLoginCallback: function(event, oauthUrl, tokenUrl){ | ||
//#Window.destroy(); | ||
} | ||
|
||
var rawCode = /code=([^&]*)/.exec(tokenUrl) | ||
var code = null | ||
handleLoginCallback = (event, oauthUrl, tokenUrl) => { | ||
const rawCode = /code=([^&]*)/.exec(tokenUrl) | ||
if (rawCode && rawCode.length > 1){ | ||
var code = rawCode[1] | ||
const code = rawCode[1] | ||
request.post("https://todoist.com/oauth/access_token") | ||
.send({ client_id: this.props.credentials.clientId, client_secret: this.props.credentials.clientSecret, code: code, redirect_uri: "https://alexfruehwirth.codes" }) | ||
.set('Content-Type','application/x-www-form-urlencoded') | ||
.end(this.handleAccessTokenResponse) | ||
} | ||
}, | ||
} | ||
|
||
handleAccessTokenResponse: function(error, response){ | ||
handleAccessTokenResponse = (error, response) => { | ||
if(response && response.ok){ | ||
localStorage.setItem('N1todoist_authentication', response.body.access_token) | ||
this.props.whenLoggedIn(); | ||
loginWindow.destroy(); | ||
this.loginWindow.destroy(); | ||
}else{ | ||
console.log(error); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import { | ||
React | ||
} from 'nylas-exports'; | ||
import { React } from 'nylas-exports'; | ||
|
||
export default class Logout extends React.Component{ | ||
|
||
static propTypes = { | ||
whenLoggedOut: React.PropTypes.func, | ||
} | ||
|
||
module.exports = React.createClass({ | ||
|
||
render: function(){ | ||
render(){ | ||
return <button className="n1todoist-logout" onClick={this.handleLogoutClick}> Logout </button> | ||
}, | ||
|
||
} | ||
|
||
handleLogoutClick: function(){ | ||
handleLogoutClick = () => { | ||
localStorage.removeItem("N1todoist_authentication"); | ||
this.props.whenLoggedOut(); | ||
}, | ||
|
||
|
||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { React } from 'nylas-exports'; | ||
|
||
export default React; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,54 @@ | ||
import { | ||
React, | ||
} from 'nylas-exports'; | ||
import { React } from 'nylas-exports'; | ||
|
||
import TodoistTaskStore from './todoist-task-store'; | ||
|
||
var TodoistLabel = React.createClass({ | ||
export default class TodoistLabel extends React.Component{ | ||
static displayName = 'TodoistLabel'; | ||
|
||
getInitialState: function(){ | ||
return { | ||
static propTypes = { | ||
thread: React.PropTypes.object, | ||
}; | ||
|
||
constructor(props){ | ||
super(props); | ||
this.state = { | ||
hasTask: this._hasTask(), | ||
done: this._isDone() | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
componentDidMount: function(){ | ||
componentDidMount(){ | ||
this._unsubscribe = TodoistTaskStore.listen(this.onTaskStoreChange); | ||
}, | ||
} | ||
|
||
componentWillUnmount: function() { | ||
componentWillUnmount() { | ||
this._unsubscribe(); | ||
}, | ||
|
||
} | ||
|
||
onTaskStoreChange: function(){ | ||
onTaskStoreChange = () => { | ||
this.setState({ | ||
hasTask: this._hasTask(), | ||
done: this._isDone() | ||
}) | ||
}, | ||
|
||
render: function(){ | ||
} | ||
|
||
render(){ | ||
if(this.state.hasTask){ | ||
return <div className={"mail-label n1todoist-maillabel" + (this.state.done ? " done" : "")}>Task</div> | ||
}else{ | ||
return null | ||
} | ||
}, | ||
|
||
_hasTask: function(){ | ||
let task = TodoistTaskStore.getTaskByClientId(this.props.thread.clientId) | ||
} | ||
|
||
_hasTask(){ | ||
const task = TodoistTaskStore.getTaskByClientId(this.props.thread.clientId) | ||
return task ? true : false; | ||
}, | ||
|
||
_isDone: function(){ | ||
let task = TodoistTaskStore.getTaskByClientId(this.props.thread.clientId) | ||
} | ||
|
||
_isDone(){ | ||
const task = TodoistTaskStore.getTaskByClientId(this.props.thread.clientId) | ||
return task ? task.done : false; | ||
} | ||
|
||
}); | ||
} | ||
|
||
module.exports = TodoistLabel; |
Oops, something went wrong.