From 121becd9cf52c735e2d33032873fca8fc6e3db54 Mon Sep 17 00:00:00 2001
From: omagdy7 <omar.professional8777@gmail.com>
Date: Sun, 5 Nov 2023 22:22:37 +0200
Subject: Added all the main features of the plugin and also added setting and
 made the plugin respect themeing

---
 src/App.tsx | 51 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 15 deletions(-)

(limited to 'src/App.tsx')

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>
     );
-- 
cgit v1.2.3

