Skip to content

Commit

Permalink
fix: cannot parse
Browse files Browse the repository at this point in the history
  • Loading branch information
benjypng committed Oct 18, 2023
1 parent b6b32d5 commit 6dcf35d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,18 @@ import "@logseq/libs";
import { settings } from "~/settings";
import { goToDate } from "~/features/go-to-date";
import { completeTask } from "~/features/complete-task";
import { handlePopup } from "~/utils";
import { handlePopup, setSettings } from "~/utils";
import { parseMutationObserver } from "~/features/parse/semi-auto";
import { manualParsing } from "~/features/parse/manual";
import { PluginSettings } from "./settings/types";

const main = async () => {
console.info("logseq-datenlp-plugin loaded");
setSettings();

handlePopup();

logseq.App.onCurrentGraphChanged(async () => {
const { dateChar, scheduledChar, deadlineChar } =
logseq.settings! as Partial<PluginSettings>;

// Check if the above has equivalence
if (
dateChar === scheduledChar ||
dateChar === deadlineChar ||
scheduledChar === deadlineChar
) {
// Reset settings if the special chars have equivalence
logseq.updateSettings({
dateChar: "@",
scheduledChar: "%",
deadlineChar: "^",
});
await logseq.UI.showMsg(
"There are overlapping characters for the inline parsing character. Please re-check your settings",
"error",
);
return;
}

window.setTimeout(async () => {
//Save user configs in settings;
const preferredDateFormat: string = (await logseq.App.getUserConfigs())
.preferredDateFormat;
logseq.updateSettings({ preferredDateFormat: preferredDateFormat });
console.info(
`logseq-datenlp-plugin: Settings updated to ${preferredDateFormat}`,
);
}, 1500);
setSettings();
});

goToDate();
Expand Down
34 changes: 34 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,37 @@ export const handlePopup = () => {
false,
);
};

export const setSettings = async () => {
if (!logseq.settings) return;
const { dateChar, scheduledChar, deadlineChar } = logseq.settings;

// Check if the above has equivalence
if (
dateChar === scheduledChar ||
dateChar === deadlineChar ||
scheduledChar === deadlineChar
) {
// Reset settings if the special chars have equivalence
logseq.updateSettings({
dateChar: "@",
scheduledChar: "%",
deadlineChar: "^",
});
await logseq.UI.showMsg(
"There are overlapping characters for the inline parsing character. Please re-check your settings",
"error",
);
return;
}

window.setTimeout(async () => {
//Save user configs in settings;
const preferredDateFormat: string = (await logseq.App.getUserConfigs())
.preferredDateFormat;
logseq.updateSettings({ preferredDateFormat: preferredDateFormat });
console.info(
`logseq-datenlp-plugin: Settings updated to ${preferredDateFormat}`,
);
}, 1500);
};

0 comments on commit 6dcf35d

Please sign in to comment.