Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Frühwirth authored and Alexander Frühwirth committed Feb 15, 2017
2 parents 0ee4fba + 072bb98 commit 90ea3a9
Show file tree
Hide file tree
Showing 54 changed files with 8,206 additions and 354 deletions.
57 changes: 26 additions & 31 deletions lib/#.jsx
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);
}
}
});
}
24 changes: 11 additions & 13 deletions lib/logout.jsx
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();
},


});
}
}
10 changes: 1 addition & 9 deletions lib/main.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ComponentRegistry
} from 'nylas-exports';

import { ComponentRegistry } from 'nylas-exports';
import TodoistSidebar from './todoist-sidebar';
import TodoistLabel from './todoist-label';

Expand All @@ -14,11 +11,6 @@ export function activate() {
role: 'Thread:MailLabel',
});
}

export function serialize() {

}

export function deactivate() {
ComponentRegistry.unregister(TodoistComposer);
ComponentRegistry.unregister(TodoistSidebar);
Expand Down
80 changes: 33 additions & 47 deletions lib/projects.jsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
import {
React,
} from 'nylas-exports';

import TodoistProjectStore from './todoist-project-store';
import TodoistTaskStore from './todoist-task-store';
import ReactSelectize from 'react-selectize';

var SimpleSelect = ReactSelectize.SimpleSelect;

import { React } from 'nylas-exports';
// http://furqanzafar.github.io/react-selectize/#/?category=simple
// Check for custom styling (color + levels) etc.
import { SimpleSelect } from '../modules/react-selectize';

import TodoistProjectStore from './todoist-project-store';
import TodoistTaskStore from './todoist-task-store';

module.exports = React.createClass({

getInitialState: function(){
return {
export default class Projects extends React.Component{
constructor(props){
super(props);
this.state = {
projects: TodoistProjectStore.getProjects(),
current_project_id: null,
selectedOption: null
}
},
};
}

componentDidMount: function(){
componentDidMount(){
this._unsubscribeProjectStore = TodoistProjectStore.listen(this.onProjectStoreChange);
this._unsubscribeTaskStore = TodoistTaskStore.listen(this.onTaskStoreChange);
},
}

componentWillUnmount: function() {
componentWillUnmount() {
this._unsubscribeProjectStore();
this._unsubscribeTaskStore();
},

}


render: function(){
var self = this;
render(){
let options = [];
let currentProject = null;
let inboxProject = null;
if(this.state.projects){
options = this.state.projects.map(function(project){
if(self.state.current_project_id === project.id){
options = this.state.projects.map(project => {
if(this.state.current_project_id === project.id){
currentProject = {value: project.id, label: project.name, color: project.color, indent: project.indent};
}
if(project.inbox_project){
if(this.inbox_project){
inboxProject = {value: project.id, label: project.name, color: project.color, indent: project.indent};
}
return {value: project.id, label: project.name, color: project.color, indent: project.indent};
Expand All @@ -57,19 +48,19 @@ module.exports = React.createClass({
<SimpleSelect
options={options}
value={selectedOption}
onValueChange={function(item){
self.setState({selectedOption: item})
self.props.onChange(item ? item.value : null);
onValueChange={(item) => {
this.setState({selectedOption: item})
this.props.onChange(item ? item.value : null);
}}
renderOption={function(item){
renderOption={(item) =>{
return (
<div className={"simple-option n1todoist-project-listitem n1todoist-project-listitem-indent--"+item.indent}>
<span className={"n1todoist-project-listitem__color n1todoist-color--" + item.color}></span>
<span className="n1todoist-project-listitem__label">{item.label}</span>
</div>
);
}}
renderValue={function(item){
renderValue={(item) =>{
return (
<div className="simple-value n1todoist-project-listitem n1todoist-project-value">
<span className={"n1todoist-project-listitem__color n1todoist-color--" + item.color}></span>
Expand All @@ -80,31 +71,26 @@ module.exports = React.createClass({
/>
</div>
);
},
}

onProjectStoreChange: function(){
onProjectStoreChange = () => {
this._setStateFromProjectStore();
},
}

onTaskStoreChange: function(){
let currTask = TodoistTaskStore.taskForFocusedContent();
onTaskStoreChange = () => {
const currTask = TodoistTaskStore.taskForFocusedContent();
if(currTask !== null){
let currProjectId = currTask.project_id ? currTask.project_id : null;
const currProjectId = currTask.project_id ? currTask.project_id : null;
this.setState({
current_project_id: currProjectId
})
}

},
}

_setStateFromProjectStore: function(){
_setStateFromProjectStore = () => {
this.setState({
projects: TodoistProjectStore.getProjects()
});
},





});
}
}
3 changes: 3 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { React } from 'nylas-exports';

export default React;
53 changes: 26 additions & 27 deletions lib/todoist-label.jsx
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;
Loading

0 comments on commit 90ea3a9

Please # to comment.