diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-11-05 22:22:37 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-11-05 22:22:37 +0200 |
| commit | 121becd9cf52c735e2d33032873fca8fc6e3db54 (patch) | |
| tree | afcbd0697808faf66d7cb84f2852d979b5da8550 /src/App.tsx | |
| parent | 7c9ade2c19b5b65721918dd291de54bcd4dc805b (diff) | |
| download | ollama-logseq-121becd9cf52c735e2d33032873fca8fc6e3db54.tar.xz ollama-logseq-121becd9cf52c735e2d33032873fca8fc6e3db54.zip | |
Added all the main features of the plugin and also added setting and made the plugin respect themeing
Diffstat (limited to 'src/App.tsx')
| -rw-r--r-- | src/App.tsx | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/src/App.tsx b/src/App.tsx index 5b5fca0..c88108d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,30 +1,51 @@ +import { AppUserInfo } from "@logseq/libs/dist/LSPlugin"; import React, { useEffect, useRef, useState } from "react"; -import CommandPalette from "./components/CommandPallete"; +import { OllamaCommandPallete } from "./components/OllamaCommandPallete"; +import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI } from "./ollama"; import { useAppVisible } from "./utils"; const options = [ - { label: 'Ask Ai' }, - { label: 'Define' }, - { label: 'Divide into subtasks' }, - { label: 'Summarize' }, + 'Ask ai', + 'Ask with context', + 'Define', + 'Divide into subtasks', + 'Summarize', + 'Convert to flash card', ]; - -async function ollamaUI() { - console.log("Hello") - logseq.showMainUI({ autoFocus: true }) - setTimeout(() => { - document.getElementById("ai-input")?.focus() - console.log(document.getElementById("ai-input")) - }, 300) +async function getTheme() { + const theme = await logseq.App.getUserInfo() + if (!theme) { + return "dark" + } + return theme.preferredThemeMode } function App() { const innerRef = useRef<HTMLDivElement>(null); const visible = useAppVisible(); + const [theme, setTheme] = useState<string>('') useEffect(() => { + const getTheme = async () => { + const theme = await logseq.App.getUserConfigs() + if (!theme) { + setTheme('dark') + } else { + setTheme(theme.preferredThemeMode) + } + } + getTheme(); + if (!logseq.settings) { + return + } logseq.Editor.registerSlashCommand("ollama", ollamaUI) + logseq.Editor.registerBlockContextMenuItem("Create a flash card", convertToFlashCardFromEvent) + logseq.Editor.registerBlockContextMenuItem("Make task into subtasks", DivideTaskIntoSubTasksFromEvent) + logseq.App.registerCommandShortcut( + { "binding": logseq.settings.shortcut }, + ollamaUI + ); }, []) if (visible) { @@ -37,8 +58,8 @@ function App() { } }} > - <div ref={innerRef} className="text-white text-2xl"> - <CommandPalette options={options} /> + <div ref={innerRef} className="flex items-center justify-center w-screen"> + <OllamaCommandPallete options={options} theme={theme} /> </div> </main> ); |
