From c487b7b37a9f9e2de82d386c30ea7d62097a847e Mon Sep 17 00:00:00 2001 From: David Li Date: Mon, 4 Dec 2023 16:17:48 +0800 Subject: Abstract out the prompt and block event functions into a closure so it can be use to create new menu events with different prompt prefix. --- src/App.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/App.tsx') diff --git a/src/App.tsx b/src/App.tsx index 6ab84a8..3e50f38 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,9 +4,7 @@ import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI, - summarizeBlockFromEvent, - promptFromBlockEvent, - expandBlockEvent + promptFromBlockEventClosure } from "./ollama"; import { useAppVisible } from "./utils"; @@ -48,10 +46,13 @@ function App() { } logseq.Editor.registerSlashCommand("ollama", ollamaUI) logseq.Editor.registerBlockContextMenuItem("Ollama: Create a flash card", convertToFlashCardFromEvent) - logseq.Editor.registerBlockContextMenuItem("Ollama: Summarize block", summarizeBlockFromEvent) logseq.Editor.registerBlockContextMenuItem("Ollama: Divide into subtasks", DivideTaskIntoSubTasksFromEvent) - logseq.Editor.registerBlockContextMenuItem("Ollama: Prompt from Block", promptFromBlockEvent) - logseq.Editor.registerBlockContextMenuItem("Ollama: Expand Block", expandBlockEvent) + logseq.Editor.registerBlockContextMenuItem("Ollama: Prompt from Block", promptFromBlockEventClosure()) + logseq.Editor.registerBlockContextMenuItem("Ollama: Summarize block", promptFromBlockEventClosure("Summarize: ")) + logseq.Editor.registerBlockContextMenuItem("Ollama: 总结 Block", promptFromBlockEventClosure("总结: ")) + logseq.Editor.registerBlockContextMenuItem("Ollama: Expand Block", promptFromBlockEventClosure("Expand: ")) + logseq.Editor.registerBlockContextMenuItem("Ollama: 扩展 Block", promptFromBlockEventClosure("扩展: ")) + logseq.App.registerCommandShortcut( { "binding": logseq.settings.shortcut }, ollamaUI -- cgit v1.2.3 From f4a66c83658c354a9c5e3d7f2476de4e429cae94 Mon Sep 17 00:00:00 2001 From: David Li Date: Sun, 10 Dec 2023 21:54:44 +0800 Subject: Use a configuration page instead of hard coding the context menu commands. --- src/App.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/App.tsx') diff --git a/src/App.tsx b/src/App.tsx index 3e50f38..b6b6918 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -44,19 +44,33 @@ function App() { if (!logseq.settings) { return } + +logseq.Editor.getPageBlocksTree("ollama-logseq-config").then((blocks) => { + blocks!.forEach((block) => { + logseq.Editor.getBlockProperty(block.uuid, "ollama-context-menu-title").then((title) => { + logseq.Editor.getBlockProperty(block.uuid, "ollama-prompt-prefix").then((prompt_prefix) => { + logseq.Editor.registerBlockContextMenuItem(title, promptFromBlockEventClosure(prompt_prefix)) + }) + }).catch((reason) => { + }) + }) +}).catch((reason) => { + console.log("Can not find the configuration page named 'ollama-logseq-config'") + console.log(reason) +}) + + logseq.Editor.registerSlashCommand("ollama", ollamaUI) logseq.Editor.registerBlockContextMenuItem("Ollama: Create a flash card", convertToFlashCardFromEvent) logseq.Editor.registerBlockContextMenuItem("Ollama: Divide into subtasks", DivideTaskIntoSubTasksFromEvent) logseq.Editor.registerBlockContextMenuItem("Ollama: Prompt from Block", promptFromBlockEventClosure()) logseq.Editor.registerBlockContextMenuItem("Ollama: Summarize block", promptFromBlockEventClosure("Summarize: ")) - logseq.Editor.registerBlockContextMenuItem("Ollama: 总结 Block", promptFromBlockEventClosure("总结: ")) logseq.Editor.registerBlockContextMenuItem("Ollama: Expand Block", promptFromBlockEventClosure("Expand: ")) - logseq.Editor.registerBlockContextMenuItem("Ollama: 扩展 Block", promptFromBlockEventClosure("扩展: ")) logseq.App.registerCommandShortcut( { "binding": logseq.settings.shortcut }, ollamaUI - ); + ); }, []) if (visible) { -- cgit v1.2.3