-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (41 loc) · 1.29 KB
/
index.ts
File metadata and controls
48 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { Command as ObsidianCommand } from "obsidian";
import {
addTask,
addTaskWithPageInContent,
addTaskWithPageInDescription,
} from "@/commands/addTask";
import { t } from "@/i18n";
import type { Translations } from "@/i18n/translation";
import type TodoistPlugin from "@/index";
import { debug } from "@/log";
export type MakeCommand = (
plugin: TodoistPlugin,
i18n: Translations["commands"],
) => Omit<ObsidianCommand, "id">;
const syncCommand: MakeCommand = (plugin: TodoistPlugin, i18n: Translations["commands"]) => {
return {
name: i18n.sync,
callback: async () => {
debug("Syncing with Todoist API");
plugin.services.todoist.sync();
},
};
};
const commands = {
"todoist-sync": syncCommand,
"add-task": addTask,
"add-task-page-content": addTaskWithPageInContent,
"add-task-page-description": addTaskWithPageInDescription,
};
export type CommandId = keyof typeof commands;
export const registerCommands = (plugin: TodoistPlugin) => {
const i18n = t().commands;
for (const [id, make] of Object.entries(commands)) {
plugin.addCommand({ id, ...make(plugin, i18n) });
}
};
export const fireCommand = <K extends CommandId>(id: K, plugin: TodoistPlugin) => {
const i18n = t().commands;
const make = commands[id];
make(plugin, i18n).callback?.();
};