Skip to content

Commit

Permalink
[fix] settings not loading when api token is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
hkgnp committed Jan 12, 2023
1 parent f304fd9 commit 3434cef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-todoist-plugin",
"version": "5.2.0",
"version": "5.2.1",
"author": "hkgnp",
"description": "Simple Todoist plugin to pull only active tasks from specified project, i.e. Inbox",
"logseq": {
Expand Down
3 changes: 2 additions & 1 deletion src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function callSettings() {
default: "KtE71bDUeY2OpDBr3LQEgWEHUZPFN1yi",
title: "API Token",
description:
"You can retrieve your API token from your Todoist developer dashboard.",
"Please enter your API token and restart Logseq. You can retrieve your API token from your Todoist developer dashboard.",
},
{
key: "",
Expand Down Expand Up @@ -117,5 +117,6 @@ export default async function callSettings() {
"If set to true, Todoist Sync will be enabled. The default retrieve project identified above will be used as the synchronising project",
},
];

logseq.useSettingsSchema(settings);
}
38 changes: 22 additions & 16 deletions src/services/todoistHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@ import {
} from "../utils/parseStrings";

export async function getAllProjects() {
const api = new TodoistApi(logseq.settings!.apiToken);

const allProjects: Project[] = await api.getProjects();

let projArr = allProjects.map((project) => `${project.name} (${project.id})`);
projArr.unshift("--- ---");

return projArr;
try {
const api = new TodoistApi(logseq.settings!.apiToken);
const allProjects: Project[] = await api.getProjects();
let projArr = allProjects.map(
(project) => `${project.name} (${project.id})`
);
projArr.unshift("--- ---");
return projArr;
} catch (e) {
console.log(e);
return ["--- ---"];
}
}

export async function getAllLabels() {
const api = new TodoistApi(logseq.settings!.apiToken);

const allLabels: Label[] = await api.getLabels();

let labelArr = allLabels.map((label) => `${label.name} (${label.id})`);
labelArr.unshift("--- ---");

return labelArr;
try {
const api = new TodoistApi(logseq.settings!.apiToken);
const allLabels: Label[] = await api.getLabels();
let labelArr = allLabels.map((label) => `${label.name} (${label.id})`);
labelArr.unshift("--- ---");
return labelArr;
} catch (e) {
console.log(e);
return ["--- ---"];
}
}

function removeTaskFlags(content: string) {
Expand Down

0 comments on commit 3434cef

Please sign in to comment.