Skip to content

Commit

Permalink
Apply changes based on PR feedback: (#10)
Browse files Browse the repository at this point in the history
- Correctly register event listeners to be unregistered automatically.
- Use object.assign to fill in missing properties on saved data
- Use class list shorthand utility functions
- Add note to readme about why MetaEdit is required
  • Loading branch information
nathonius authored Sep 2, 2021
1 parent 2976a0a commit 2c32862
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The connection is through a YAML frontmatter key.

1. A Trello account
2. The [MetaEdit](https://github.com/chhoumann/MetaEdit) Obsidian plugin (install from inside Obsidian)
- Obsidian Trello makes use of MetaEdit's [YAML Frontmatter API](https://github.com/chhoumann/MetaEdit#api).
3. A Trello API token (see below).

Before you can connect a Trello card, you need to create an API token and set it in the plugin settings. You can create a token [here][tokenurl]; make sure to copy it before closing the tab.
Expand Down
7 changes: 4 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class TrelloPlugin extends Plugin {
async onload(): Promise<void> {
// Set up data and default data.
const savedData: PluginData | undefined = await this.loadData();
this.state = new PluginState(this, savedData || DEFAULT_DATA);
const data: PluginData = Object.assign({}, DEFAULT_DATA, savedData);
this.state = new PluginState(this, data);

// Create new API instance
this.api = new TrelloAPI(this);
Expand All @@ -65,8 +66,8 @@ export class TrelloPlugin extends Plugin {
// Register trello view type
this.registerView(TRELLO_VIEW_TYPE, (leaf: WorkspaceLeaf) => (this.view = new TrelloView(this, leaf)));

// Register file handler to check if the opened card is trello connected
this.app.workspace.on('file-open', async (file) => this.handleFile(file));
// Register file handler to check if the opened card is trello connected\
this.registerEvent(this.app.workspace.on('file-open', async (file) => this.handleFile(file)));
// Also check the current file on load
this.handleFile(this.app.workspace.getActiveFile());

Expand Down
6 changes: 3 additions & 3 deletions src/settings/board-select-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ export class BoardSelectModal extends Modal {
container.createDiv({ text: board.name, cls: 'trello-board-select--toggle-label' });
const toggle = container.createDiv({ cls: 'trello-board-select--toggle checkbox-container' });
if (this.newState[board.id]) {
toggle.classList.add('is-enabled');
toggle.addClass('is-enabled');
}
container.addEventListener('click', () => {
if (this.newState[board.id]) {
toggle.classList.remove('is-enabled');
toggle.removeClass('is-enabled');
delete this.newState[board.id];
} else {
toggle.classList.add('is-enabled');
toggle.addClass('is-enabled');
this.newState[board.id] = board;
}
});
Expand Down

0 comments on commit 2c32862

Please sign in to comment.