Skip to content

Commit

Permalink
Merge pull request #7 from spoon611/add-create-project
Browse files Browse the repository at this point in the history
adding create new project
  • Loading branch information
Spoorthi Satheesha authored Sep 23, 2020
2 parents ce2cf7b + 6b9ed42 commit 7aac0a0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## Unreleased

### Added

### Changed

### Removed

### Fixed

## [0.3.0] - 2020-09-23

### Added
* Adding support for [Sections](https://get.todoist.help/hc/en-us/articles/360003788739-Sections)
* Create new Project (only parent Projects currently supported)

### Changed

### Removed

### Fixed
* Fixed ordering of tasks and subtasks being incorrect

## [0.2.1] - 2020-07-27

Expand Down
1 change: 1 addition & 0 deletions media/dark_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions media/light_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "code-with-todoist",
"displayName": "code with Todoist",
"description": "Todoist plugin for vs code",
"version": "0.2.1",
"version": "0.3.0",
"publisher": "Spoorthi",
"icon": "media/extension_icon.png",
"license": "SEE LICENSE IN LICENSE",
Expand Down Expand Up @@ -39,6 +39,14 @@
"light": "media/light_check.svg",
"dark": "media/dark_check.svg"
}
},
{
"command": "todoist.addProject",
"title": "Add Todoist Project",
"icon": {
"light": "media/light_add.svg",
"dark": "media/dark_add.svg"
}
}
],
"configuration": [
Expand Down Expand Up @@ -70,6 +78,11 @@
"command": "todoist.sync",
"when": "view == projects",
"group": "navigation"
},
{
"command": "todoist.addProject",
"when": "view == projects",
"group": "navigation"
}
],
"view/item/context": [
Expand Down
23 changes: 19 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export function activate(context: vscode.ExtensionContext) {
initTreeView();
}

if(vscode.workspace.name) {
vscode.commands.executeCommand('setContext', 'workspaceOpen', true);

}
// if(vscode.workspace.name) {
// vscode.commands.executeCommand('setContext', 'workspaceOpen', true);
// }

// Commands -------------------------------------------------------------------------

Expand All @@ -54,6 +53,22 @@ export function activate(context: vscode.ExtensionContext) {
openCustomTask(filePath, line, column);
}));

context.subscriptions.push(vscode.commands.registerCommand('todoist.addProject', () => {
vscode.window.showInputBox({
prompt: 'New Project Name',
}).then(projectName => {
if(projectName) {
vscode.window.showInformationMessage('Project : ' + projectName + ' is being created.');
const state = context.globalState;
const apiHelper = new todoistAPIHelper(state);
apiHelper.createProject(projectName).then(project => {
syncTodoist();
vscode.window.showInformationMessage('Project : ' + project.name + ' has been created.');
});
}
});
}));

// Event Handlers -------------------------------------------------------------------

context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(function() {
Expand Down
36 changes: 36 additions & 0 deletions src/helpers/todoistAPIHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,42 @@ export default class todoistAPIHelper {
});
}

public createProject(projectName: string): Promise<project> {
const url = this.todoistAPIUrl;
const jwt = this.apiToken;

return new Promise(function (resolve, reject) {
axios.post(encodeURI(url + 'projects'), {
name: projectName
}, {
headers: {
Authorization: `Bearer ${jwt}`
}
}).then(response => {
if (response.status === 200) {
let newProject = project.deserialize(response.data);
resolve(newProject);
}
else {
reject(response.statusText)
}
}).catch(error => {
if(error.code == "ENOTFOUND") {
reject("Check your internet connection.");
}
else if(error.response.status === 400) {
reject("Ensure Todoist API token is set.");
}
else if(error.response.status === 403) {
reject("Incorrect Todoist API token. Update the token in the settings.")
}
else {
reject("Unknown error. " + error.message);
}
});
});
}

// TODO : Remove
public getProjects(): Promise<project[]> {
const url = this.todoistAPIUrl;
Expand Down

0 comments on commit 7aac0a0

Please sign in to comment.