diff --git a/components/Dashboard/TeamVoiceLine.tsx b/components/Dashboard/TeamVoiceLine.tsx index 9f8ff13..cd23dad 100644 --- a/components/Dashboard/TeamVoiceLine.tsx +++ b/components/Dashboard/TeamVoiceLine.tsx @@ -106,8 +106,8 @@ export default function TeamVoiceLine() { return; }); - document.addEventListener("keypress", handleKeyboardShortcut); - document.addEventListener("keydown", handleRecording); + document.addEventListener("keydown", handleKeyboardShortcut); + document.addEventListener("keyup", handleKeyUp); } } catch (error) { console.log(error); @@ -121,8 +121,8 @@ export default function TeamVoiceLine() { return () => { unsubs.map((listener) => listener()); - document.removeEventListener("keypress", handleKeyboardShortcut); - document.removeEventListener("keydown", handleRecording); + document.removeEventListener("keydown", handleKeyboardShortcut); + document.removeEventListener("keyup", handleKeyUp); }; }, []); @@ -137,6 +137,7 @@ export default function TeamVoiceLine() { // SECTION: set up for shortcuts and recording and such const [selectedTeammate, setSelectedTeammate] = useState(); // id of selected teammate + const [isRecording, setIsRecording] = useState(false); const shortcutMappings = new Map(); // keycode number to the user id teamUsers.forEach((tmUser, i) => { @@ -147,23 +148,35 @@ export default function TeamVoiceLine() { } }); - function handleRecording(event) { - // recording + function handleKeyUp(event) { + console.log("on key up"); + + // if was recording and released R, then stop recording if (event.keyCode == KeyCode.R) { - console.log("recording"); + console.log("stopped recording"); + setIsRecording(false); } } function handleKeyboardShortcut(event) { + if (event.repeat) { + return; + } + console.log(event.keyCode); + // recordingr + if (event.keyCode == KeyCode.R) { + console.log("started recording"); + setIsRecording(true); + } // if we have a valid user for such a shortcut, then go ahead...otherwise - if (shortcutMappings.has(event.keyCode)) { + else if (shortcutMappings.has(event.keyCode)) { setSelectedTeammate(shortcutMappings.get(event.keyCode)); } else if (event.keyCode == KeyCode.Escape) { setSelectedTeammate(null); } else { - console.log("Invalid teammate selection."); + toast("Invalid teammate selection."); } // todo if we press the same shortcut twice, deactive selected user @@ -252,9 +265,15 @@ export default function TeamVoiceLine() { - + {isRecording ? ( + + ) : ( + + )}