Skip to content

Commit

Permalink
version 0.0.11 which modifies so todo elements are marked as todos in…
Browse files Browse the repository at this point in the history
… obsidian and optional todoTag setting available
  • Loading branch information
kinabalu committed Jun 8, 2024
1 parent 1e0c1c1 commit 9f4838b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
32 changes: 28 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'obsidian';
import {moment} from "obsidian"
import VoiceNotesApi from "./voicenotes-api";
import {capitalizeFirstLetter} from "./utils";
import {capitalizeFirstLetter, isAlphaNumeric} from "./utils";
import {VoiceNoteEmail} from "./types";
import { sanitize } from 'sanitize-filename-ts';
import * as path from 'path';
Expand All @@ -30,6 +30,7 @@ interface VoiceNotesPluginSettings {
syncDirectory: string;
deleteSynced: boolean;
reallyDeleteSynced: boolean;
todoTag: string;
}

const DEFAULT_SETTINGS: VoiceNotesPluginSettings = {
Expand All @@ -38,6 +39,7 @@ const DEFAULT_SETTINGS: VoiceNotesPluginSettings = {
syncDirectory: "voicenotes",
deleteSynced: false,
reallyDeleteSynced: false,
todoTag: "",
}

export default class VoiceNotesPlugin extends Plugin {
Expand Down Expand Up @@ -125,6 +127,7 @@ export default class VoiceNotesPlugin extends Plugin {
} while(nextPage)
}

// console.dir(recordings)
if (recordings) {
for (const recording of recordings.data) {
if (!recording.title) {
Expand Down Expand Up @@ -176,6 +179,12 @@ export default class VoiceNotesPlugin extends Plugin {
const creationData = creation.content.data as VoiceNoteEmail
note += `**Subject:** ${creationData.subject}\n\n`
note += `${creationData.body}\n`
} else if (creation.type === 'todo') {
const creationData = creation.content.data as string[]

if (Array.isArray(creationData)) {
note += creationData.map(data => `- [ ] ${data}${this.settings.todoTag ? ' #' + this.settings.todoTag : ''}`).join('\n')
}
} else if (creation.type !== 'tweet') {
const creationData = creation.content.data as string[]

Expand Down Expand Up @@ -264,10 +273,13 @@ class VoiceNotesSettingTab extends PluginSettingTab {
username: this.plugin.settings.username,
password: this.password
})
new Notice("Login to voicenotes.com was successful")

this.plugin.settings.password = null
await this.plugin.saveSettings()
await this.display()
if (this.plugin.settings.token) {
new Notice("Login to voicenotes.com was successful")
await this.plugin.saveSettings()
await this.display()
}
})
)
}
Expand Down Expand Up @@ -337,6 +349,18 @@ class VoiceNotesSettingTab extends PluginSettingTab {
})
)

new Setting(containerEl)
.setName("Add a tag to todos")
.setDesc("When syncing a note add an optional tag to the todo")
.addText(text => text
.setPlaceholder("TODO")
.setValue(this.plugin.settings.todoTag)
.onChange(async (value) => {
this.plugin.settings.todoTag = value;
await this.plugin.saveSettings();
})
)

new Setting(containerEl)
.setName("Download audio")
.setDesc("Store and download the audio associated with the transcript")
Expand Down
4 changes: 4 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export function capitalizeFirstLetter(word: string): string {
return word[0].toUpperCase() + word.slice(1);
}

export function isAlphaNumeric(value: string): boolean {
const regex = /^[a-z0-9_]+$/i;
return regex.test(value);
}

0 comments on commit 9f4838b

Please sign in to comment.