diff --git a/src/components/App.css b/src/components/App.scss similarity index 78% rename from src/components/App.css rename to src/components/App.scss index 10564a5..4ca81e6 100755 --- a/src/components/App.css +++ b/src/components/App.scss @@ -1,3 +1,5 @@ +@import "./vars.scss"; + .App { background-color: white; color: rgb(110,109,95); @@ -14,6 +16,17 @@ font-size: .625rem; } } + h2 { + font-size: .75rem; + } + h3 { + font-size: .75rem; + } + hr { + border-top: solid 1px $dark-gray; + height: 0; + margin: 20px 0 0; + } .buttons { display: flex; flex-direction: column; @@ -46,6 +59,13 @@ } } + .error-message { + color: #d00; + font-size: .75rem; + margin: 0; + padding: 0; + } + .visually-hidden { border: 0; clip: rect(0, 0, 0, 0); diff --git a/src/components/App.tsx b/src/components/App.tsx index 0372187..db71fe3 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -6,8 +6,9 @@ import { ChatTranscriptComponent } from "./chat-transcript"; import { ChatTranscript, ChatMessage } from "../types"; import { timeStamp } from "../utils"; import { ReadAloudMenu } from "./readaloud-menu"; +import { KeyboardShortcutControls } from "./keyboard-shortcut-controls"; -import "./App.css"; +import "./App.scss"; const kPluginName = "DAVAI"; const kVersion = "0.0.1"; @@ -30,15 +31,27 @@ export const App = () => { const [chatTranscript, setChatTranscript] = useState({messages: [{speaker: "DAVAI", content: greeting, timestamp: timeStamp()}]}); const [readAloudEnabled, setReadAloudEnabled] = useState(false); const [playbackSpeed, setPlaybackSpeed] = useState(1); + const [keyboardShortcutEnabled, setKeyboardShortcutEnabled] = useState(true); + const [keyboardShortcutKeys, setKeyboardShortcutKeys] = useState("Ctrl+Command+A"); useEffect(() => { initializePlugin({pluginName: kPluginName, version: kVersion, dimensions: kInitialDimensions}); + selectSelf(); }, []); const handleFocusShortcut = () => { selectSelf(); }; + const handleToggleShortcut = () => { + setKeyboardShortcutEnabled(!keyboardShortcutEnabled); + }; + + const handleCustomizeShortcut = (shortcut: string) => { + console.log("2 Customizing shortcut to", shortcut); + setKeyboardShortcutKeys(shortcut); + }; + const handleSetReadAloudEnabled = () => { setReadAloudEnabled(!readAloudEnabled); }; @@ -68,13 +81,25 @@ export const App = () => { - + +
+

Options

+ ); }; diff --git a/src/components/chat-input.scss b/src/components/chat-input.scss index 6e30342..43604ea 100644 --- a/src/components/chat-input.scss +++ b/src/components/chat-input.scss @@ -19,13 +19,6 @@ padding: 8px 10px; } - .error { - color: #d00; - font-size: .75rem; - margin: 0; - padding: 0; - } - .buttons-container { align-items: center; display: flex; diff --git a/src/components/chat-input.test.tsx b/src/components/chat-input.test.tsx index 0bccbc6..0c4fcb1 100644 --- a/src/components/chat-input.test.tsx +++ b/src/components/chat-input.test.tsx @@ -7,7 +7,7 @@ describe("test chat input component", () => { const mockHandleSubmit = jest.fn(); it("renders a textarea and submit button that lets user send chat messages", () => { - render(); + render(); const chatInput = screen.getByTestId("chat-input"); const chatInputLabel = within(chatInput).getByTestId("chat-input-label"); diff --git a/src/components/chat-input.tsx b/src/components/chat-input.tsx index 317f557..145e6d2 100644 --- a/src/components/chat-input.tsx +++ b/src/components/chat-input.tsx @@ -5,11 +5,12 @@ import { isInputElement } from "../utils"; import "./chat-input.scss"; interface IProps { + keyboardShortcutEnabled: boolean; onKeyboardShortcut: () => void; onSubmit: (messageText: string) => void; } -export const ChatInputComponent = ({onKeyboardShortcut, onSubmit}: IProps) => { +export const ChatInputComponent = ({keyboardShortcutEnabled, onKeyboardShortcut, onSubmit}: IProps) => { const textAreaRef = useRef(null); // const [browserSupportsDictation, setBrowserSupportsDictation] = useState(false); // const [dictationEnabled, setDictationEnabled] = useState(false); @@ -118,24 +119,22 @@ export const ChatInputComponent = ({onKeyboardShortcut, onSubmit}: IProps) => { useEffect(() => { const keydownListeners: (() => void)[] = []; - // Add keyboard shortcut listener to the parent window if one exists. - if (window.parent && window.parent !== window) { - keydownListeners.push(addShortcutListener(window.parent)); - } - // Add keyboard shortcut listener to the current window. - keydownListeners.push(addShortcutListener(window)); + if (keyboardShortcutEnabled) { + // Add keyboard shortcut listener to the parent window if one exists. + if (window.parent && window.parent !== window) { + keydownListeners.push(addShortcutListener(window.parent)); + } + + // Add keyboard shortcut listener to the current window. + keydownListeners.push(addShortcutListener(window)); + } // Clean up the listeners when the component unmounts. return () => { keydownListeners.forEach((cleanup) => cleanup()); }; - }, [addShortcutListener]); - - useEffect(() => { - // Set focus on textarea when component first mounts. - textAreaRef.current?.focus(); - }, []); + }, [addShortcutListener, keyboardShortcutEnabled]); return (
@@ -158,7 +157,7 @@ export const ChatInputComponent = ({onKeyboardShortcut, onSubmit}: IProps) => { {showError &&