aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DictationButton.tsx
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2025-03-04 04:32:50 -0500
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2025-03-04 04:32:50 -0500
commit95abdada5a275fc258fa72781f7f3c40c0b306ea (patch)
tree6d729cebe0937ae81108005de9895b5398d1f475 /src/client/views/DictationButton.tsx
parent0a8f3739cf5c30852f18751a4c05d81e0dabe928 (diff)
parent215ad40efa2e343e290d18bffbc55884829f1a0d (diff)
Merge branch 'master' of https://github.com/brown-dash/Dash-Web into Merge
Diffstat (limited to 'src/client/views/DictationButton.tsx')
-rw-r--r--src/client/views/DictationButton.tsx57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/client/views/DictationButton.tsx b/src/client/views/DictationButton.tsx
new file mode 100644
index 000000000..0ce586df4
--- /dev/null
+++ b/src/client/views/DictationButton.tsx
@@ -0,0 +1,57 @@
+import { IconButton, Type } from '@dash/components';
+import { action, makeObservable, observable } from 'mobx';
+import { observer } from 'mobx-react';
+import * as React from 'react';
+import { BiMicrophone } from 'react-icons/bi';
+import { DictationManager } from '../util/DictationManager';
+import { SnappingManager } from '../util/SnappingManager';
+
+export interface DictationButtonProps {
+ setInput: (val: string) => void;
+ inputRef?: HTMLInputElement | null | undefined;
+}
+@observer
+export class DictationButton extends React.Component<DictationButtonProps> {
+ @observable private _isRecording = false;
+ constructor(props: DictationButtonProps) {
+ super(props);
+ makeObservable(this);
+ }
+
+ stopDictation = action(() => {
+ this._isRecording = false;
+ DictationManager.Controls.stop();
+ });
+
+ render() {
+ return (
+ <IconButton
+ type={Type.TERT}
+ color={this._isRecording ? '#2bcaff' : SnappingManager.userVariantColor}
+ tooltip="Record"
+ icon={<BiMicrophone size="16px" />}
+ onClick={action(() => {
+ if (!this._isRecording) {
+ this._isRecording = true;
+ DictationManager.Controls.listen({
+ interimHandler: (value: string) => {
+ this.props.setInput(value);
+ if (this.props.inputRef) {
+ this.props.inputRef.focus();
+ this.props.inputRef.scrollLeft = 1000000;
+ }
+ },
+ continuous: { indefinite: false },
+ }).then(results => {
+ if (results && [DictationManager.Controls.Infringed].includes(results)) {
+ DictationManager.Controls.stop();
+ }
+ });
+ } else {
+ this.stopDictation();
+ }
+ })}
+ />
+ );
+ }
+}