-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from bikingbadger/68-todoist-tasks
Integrate Todoist
- Loading branch information
Showing
8 changed files
with
169 additions
and
40 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
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,13 @@ | ||
'use strict'; | ||
|
||
import ProfileModel from './model.mjs'; | ||
|
||
const ProfileController = { | ||
model: ProfileModel, | ||
/** Save settings */ | ||
saveProfileSettings: function (setting) { | ||
this.model.saveSetting(setting); | ||
}, | ||
}; | ||
|
||
export default ProfileController; |
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,30 @@ | ||
'use strict'; | ||
|
||
const ProfileModel = { | ||
settings: {}, | ||
storageID: 'settings', | ||
pubSub: null, | ||
subject: 'profile', | ||
load: function (PubSub) { | ||
this.settings = localStorage.getItem(this.storageID); | ||
console.log(this.settings); | ||
this.settings = this.settings | ||
? JSON.parse(this.settings) | ||
: { todoistKey: '' }; | ||
|
||
// Add PubSub reference | ||
this.pubSub = PubSub; | ||
this.publish(); | ||
}, | ||
saveSetting: function (setting) { | ||
console.log(setting); | ||
localStorage.setItem(this.storageID, JSON.stringify(setting)); | ||
}, | ||
publish: function () { | ||
this.pubSub.publish(this); | ||
// Save the object back to localStorage | ||
localStorage.setItem(this.storageID, JSON.stringify(this.settings)); | ||
}, | ||
}; | ||
|
||
export default ProfileModel; |
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,35 @@ | ||
'use strict'; | ||
import ProfileController from './controller.mjs'; | ||
|
||
const saveButton = document.querySelector('#settings-save'); | ||
const todoistInput = document.querySelector('#settings-todoist-token'); | ||
|
||
const ProfileView = { | ||
load: function () { | ||
// Check that the todoist input exists | ||
if (!todoistInput) { | ||
throw Error('Todoist input is missing'); | ||
} | ||
//Check that button for saving exists | ||
if (!saveButton) { | ||
throw Error('Save button is missing'); | ||
} | ||
|
||
saveButton.addEventListener( | ||
'click', | ||
function () { | ||
ProfileController.saveProfileSettings({todoistKey: todoistInput.value}); | ||
}, | ||
false, | ||
); | ||
}, | ||
render: function (profile) { | ||
console.log(profile); | ||
todoistInput.value = profile.settings.todoistKey; | ||
}, | ||
notify: function (model) { | ||
this.render(model); | ||
}, | ||
}; | ||
|
||
export default ProfileView; |
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
('use strict'); | ||
|
||
const saveButton = document.querySelector('#settings-save'); | ||
const storageID = 'settings'; | ||
let settings = localStorage.getItem(storageID); | ||
settings = settings ? JSON.parse(settings) : { todoistKey: '' }; | ||
const todoistInput = document.querySelector('#settings-todoist-token'); | ||
todoistInput.value = settings.todoistKey; | ||
console.log(saveButton); | ||
saveButton.addEventListener( | ||
'click', | ||
function () { | ||
settings = { todoistKey: todoistInput.value }; | ||
console.log(settings); | ||
localStorage.setItem(storageID, JSON.stringify(settings)); | ||
}, | ||
false, | ||
); | ||
import PubSub from './modules/pubSub/pubSub.mjs'; | ||
import ProfileView from './modules/profile/view.mjs'; | ||
import ProfileModel from './modules/profile/model.mjs'; | ||
|
||
/** | ||
* Add the profile settings view to the subscription of the pubSub | ||
* This will then receive the publications of the model each time a change is made | ||
*/ | ||
ProfileView.load(); | ||
PubSub.subscribe(ProfileModel.subject, ProfileView); | ||
/** | ||
* Setup the model to use the PubSub for publishing all changes | ||
* That way any subscribers will get the updates and make changes to the view | ||
*/ | ||
ProfileModel.load(PubSub); |