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/components/OllamaCommandPallete.tsx | 54 +++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 src/components/OllamaCommandPallete.tsx

(limited to 'src/components/OllamaCommandPallete.tsx')

diff --git a/src/components/OllamaCommandPallete.tsx b/src/components/OllamaCommandPallete.tsx
new file mode 100644
index 0000000..d48d392
--- /dev/null
+++ b/src/components/OllamaCommandPallete.tsx
@@ -0,0 +1,54 @@
+import React, { KeyboardEventHandler, useEffect, useState } from "react"
+import {
+  Command,
+  CommandEmpty,
+  CommandInput,
+  CommandItem,
+  CommandList,
+} from "@/components/ui/command"
+import { convertToFlashCard, DivideTaskIntoSubTasks, summarize } from "@/ollama";
+import { PromptAI } from "./PromptAI";
+
+export function OllamaCommandPallete({ options, theme }: { options: string[], theme: string }) {
+  const [selection, setSelection] = useState('')
+  const [isEnterPressed, setIsEnterPressed] = useState(false);
+  const handleSelection = (selection: string) => {
+    setSelection(selection)
+    setIsEnterPressed(true);
+    switch (selection) {
+      case "divide into subtasks":
+        DivideTaskIntoSubTasks()
+        break;
+      case "summarize":
+        summarize()
+        break;
+      case "convert to flash card":
+        convertToFlashCard()
+        break;
+      default:
+        break;
+    }
+  }
+
+  if (isEnterPressed && (selection !== 'ask ai' && selection !== 'define' && selection !== 'ask with context')) {
+    return null
+  }
+
+  return (
+    selection === 'ask with context' || selection === 'ask ai' || selection === 'define' ? (<PromptAI theme={theme} type={selection} />) : (
+      <Command className={(theme === 'dark' ? "dark dark:bg-gray-900" : "bg-gray-200") + " rounded-lg border shadow-md w-1/2"}>
+        <CommandInput className="ai-input" placeholder="Type a command or search..." />
+        <CommandList>
+          <CommandEmpty>No results found.</CommandEmpty>
+          {
+            options.map((option) => (
+              <CommandItem key={option} onSelect={handleSelection} className="text-lg">
+                <span>{option}</span>
+              </CommandItem>
+            ))
+          }
+        </CommandList>
+      </Command>
+    )
+  )
+}
-- 
cgit v1.2.3

