Skip to content

Commit

Permalink
fix: disconnecting cards removes both meta keys and saved id state
Browse files Browse the repository at this point in the history
  • Loading branch information
nathonius committed Sep 19, 2021
1 parent ef5b747 commit b079f6e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,24 @@ export class TrelloPlugin extends Plugin {
/**
* Removes the trello frontmatter property from the current file.
*/
disconnectTrelloCard(): void {
async disconnectTrelloCard(): Promise<void> {
const view = this.app.workspace.activeLeaf?.view;

if (view instanceof FileView && this.metaEdit.available) {
from(this.metaEdit.plugin.getPropertyValue(MetaKey.TrelloId, view.file)).subscribe((existing) => {
if (existing) {
this.log('TrelloPlugin.disconnectTrelloCard', 'Disconnecting trello connected card.');
this.metaEdit.plugin.deleteProperty(MetaKey.TrelloId, view.file);
this.state.connectedCardId.next(null);
}
});
this.log('TrelloPlugin.disconnectTrelloCard', 'Disconnecting trello connected card.');

const existingPluginId = await this.metaEdit.plugin.getPropertyValue(MetaKey.TrelloId, view.file);
if (existingPluginId) {
await this.metaEdit.plugin.deleteProperty(MetaKey.TrelloId, view.file);
await new Promise((resolve) => window.setTimeout(resolve, METAEDIT_DEBOUNCE));
this.state.updateConnectedCard(existingPluginId, null);
this.state.connectedCardId.next(null);
this.log('TrelloPlugin.disconnectTrelloCard', '-> Removed plugin ID.');
}

await this.metaEdit.plugin.deleteProperty(MetaKey.BoardCard, view.file);
this.state.boardCardId.next(null);
this.log('TrelloPlugin.disconnectTrelloCard', '-> Removed board/card ID.');
}
}

Expand Down

0 comments on commit b079f6e

Please sign in to comment.