Skip to content

Commit

Permalink
finish some command coding
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpeng98 committed Dec 27, 2023
1 parent 59c15f1 commit fb5f7b5
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 185 deletions.
73 changes: 35 additions & 38 deletions src/commands/NotionCommands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { i18nConfig } from "src/lang/I18n";
import { Editor, MarkdownView } from "obsidian";
import {Editor, MarkdownView, setTooltip} from "obsidian";
import { FuzzySuggester, DatabaseList } from "./FuzzySuggester";
import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand";
import ObsidianSyncNotionPlugin from "src/main";
import {DatabaseDetails} from "../ui/settingTabs";


interface Command {
Expand All @@ -21,26 +22,11 @@ export default class RibbonCommands {
constructor(plugin: ObsidianSyncNotionPlugin) {
this.plugin = plugin;

// Check if NextButton is true, then include the corresponding command
if (this.plugin.settings.NextButton) {
this.Ncommand.push({
id: "share-to-notionnext",
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app);
}
});
}
// iterate through the database detail

// Check if GeneralButton is true, then include the corresponding command
if (this.plugin.settings.GeneralButton) {
this.Ncommand.push({
id: "share-to-notion",
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
}
});
for (let key in this.plugin.settings.databaseDetails) {
let dbDetails = this.plugin.settings.databaseDetails[key];
this.addCommandForDatabase(dbDetails);
}

// Register all the commands
Expand Down Expand Up @@ -77,24 +63,9 @@ export default class RibbonCommands {

this.Ncommand = [];

if (this.plugin.settings.NextButton) {
this.Ncommand.push({
id: "share-to-notionnext",
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app);
}
});
}

if (this.plugin.settings.GeneralButton) {
this.Ncommand.push({
id: "share-to-notion",
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
}
});
for (let key in this.plugin.settings.databaseDetails) {
let dbDetails = this.plugin.settings.databaseDetails[key];
this.addCommandForDatabase(dbDetails);
}

this.Ncommand.forEach(command => {
Expand All @@ -107,4 +78,30 @@ export default class RibbonCommands {
);
});
}

private addCommandForDatabase(dbDetails: DatabaseDetails) {
// Example logic - adjust based on your specific requirements
let commandId = `share-to-${dbDetails.abName}`;
let commandName = `Share to ${dbDetails.abName}`; // or use a translated name

let editorCallback: (editor: Editor, view: MarkdownView) => Promise<void>;
if (dbDetails.format === 'next') {
editorCallback = async (editor, view) => {
await uploadCommandNext(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
};
} else if (dbDetails.format === 'general') {
editorCallback = async (editor, view) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
};
}
// else if (dbDetails.format === 'custom') {
// editorCallback = async (editor, view) => {
// await uploadCommandGeneral(this.plugin, dbDetails, this.plugin.app);
// };
// }

this.Ncommand.push({ id: commandId, name: commandName, editorCallback });
}


}
11 changes: 10 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Upload2NotionGeneral } from "src/upload/upload_general/Upload2NotionGen
import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext";
import { i18nConfig } from "src/lang/I18n";
import ribbonCommands from "src/commands/NotionCommands";
import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs";
import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS, DatabaseDetails } from "src/ui/settingTabs";

// Remember to rename these classes and interfaces!

Expand Down Expand Up @@ -55,6 +55,15 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
await this.saveData(this.settings);
}

async addDatabaseDetails(dbDetails: DatabaseDetails) {
this.settings.databaseDetails = {
...this.settings.databaseDetails,
[dbDetails.abName]: dbDetails,
};

await this.saveSettings();
}

}


Expand Down
Loading

0 comments on commit fb5f7b5

Please sign in to comment.