From 121becd9cf52c735e2d33032873fca8fc6e3db54 Mon Sep 17 00:00:00 2001 From: omagdy7 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/CommandPallete.tsx | 96 --------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 src/components/CommandPallete.tsx (limited to 'src/components/CommandPallete.tsx') diff --git a/src/components/CommandPallete.tsx b/src/components/CommandPallete.tsx deleted file mode 100644 index e4f5924..0000000 --- a/src/components/CommandPallete.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import React, { useState, useEffect, useRef } from 'react'; -import { DivideTaskIntoSubTasks, summarize } from '../ollama'; -import { PromptAI } from './PromptAI'; - - -function CommandPalette({ options }) { - console.log("rendered commana pallate") - const [inputValue, setInputValue] = useState(''); - const [selectedOption, setSelectedOption] = useState<{ label: string }>({ label: "Ask Ai" }); - const [filteredOptions, setFilteredOptions] = useState(options); - const [isExecute, setIsExecute] = useState(false) - const inputRef = useRef(null); - - useEffect(() => { - // Initially, select the first option. - if (filteredOptions.length > 0) { - setSelectedOption(filteredOptions[0]); - } - }, [filteredOptions]); - - - const handleInputChange = (e) => { - const query = e.target.value; - setInputValue(query); - - // Filter options based on the input. - const results = options.filter((option: { label: string }) => - option.label.toLowerCase().includes(query.toLowerCase()) - ); - setFilteredOptions(results); - }; - - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'Tab') { - e.preventDefault(); - - const currentIndex = filteredOptions.indexOf(selectedOption); - let newIndex = currentIndex; - - if (e.key === 'ArrowUp' || (e.shiftKey && e.key == 'Tab')) { - newIndex = (currentIndex - 1 + filteredOptions.length) % filteredOptions.length; - } else if (e.key === 'ArrowDown' || e.key === 'Tab') { - newIndex = (currentIndex + 1) % filteredOptions.length; - } - - setSelectedOption(filteredOptions[newIndex]); - } else if (e.key === 'Enter') { - if (selectedOption) { - setIsExecute(true) - setInputValue(selectedOption.label); - if (selectedOption.label === "Divide into subtasks") { - DivideTaskIntoSubTasks() - } else if (selectedOption.label === "Summarize") { - summarize() - } - } - } - }; - - return ( - isExecute && inputValue == "Ask Ai" ? ( - - ) : isExecute && inputValue === "Define" ? ( - - ) : !isExecute ? ( -
-
- -
    - {filteredOptions.map((option: { label: string }, index: number) => ( -
  • setSelectedOption(option)} - className={`p-2 cursor-pointer ${selectedOption === option ? 'bg-blue-600 text-white border-2 border-blue-500' : '' - } hover:bg-gray-600`} - > - {option.label} -
  • - ))} -
-
-
- ) : null - ); -} - -export default CommandPalette; -- cgit v1.2.3