aboutsummaryrefslogtreecommitdiff
path: root/src/components/OllamaCommandPallete.tsx
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-11-05 22:22:37 +0200
committeromagdy7 <omar.professional8777@gmail.com>2023-11-05 22:22:37 +0200
commit121becd9cf52c735e2d33032873fca8fc6e3db54 (patch)
treeafcbd0697808faf66d7cb84f2852d979b5da8550 /src/components/OllamaCommandPallete.tsx
parent7c9ade2c19b5b65721918dd291de54bcd4dc805b (diff)
downloadollama-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/components/OllamaCommandPallete.tsx')
-rw-r--r--src/components/OllamaCommandPallete.tsx54
1 files changed, 54 insertions, 0 deletions
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>
+ )
+ )
+}