-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTranscriptIcon.tsx
More file actions
122 lines (113 loc) · 4.06 KB
/
Copy pathTranscriptIcon.tsx
File metadata and controls
122 lines (113 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {StyleSheet, View} from 'react-native';
import React from 'react';
import {SidePanelType, useSidePanel} from 'customization-api';
import IconButton, {IconButtonProps} from '../../atoms/IconButton';
import LanguageSelectorPopup from './LanguageSelectorPopup';
import {useCaption} from './useCaption';
import {useString} from '../../utils/useString';
import {toolbarItemTranscriptText} from '../../language/default-labels/videoCallScreenLabels';
import {useToolbarProps} from '../../atoms/ToolbarItem';
import {LanguageType} from './utils';
interface TranscriptIconProps {
plainIconHoverEffect?: boolean;
showToolTip?: boolean;
showLabel?: boolean;
disabled?: boolean;
isOnActionSheet?: boolean;
isMobileView?: boolean;
}
const TranscriptIcon = (props: TranscriptIconProps) => {
const {label: labelCustom = null, onPress: onPressCustom = null} =
useToolbarProps();
const {setSidePanel, sidePanel} = useSidePanel();
const {
showToolTip = false,
showLabel = $config.ICON_TEXT,
disabled = false,
isOnActionSheet = false,
isMobileView = false,
} = props;
// const {start, restart, isAuthorizedTranscriptUser} = useSTTAPI();
const {isSTTActive, isSTTError, sttDepsReady, confirmSpokenLanguageChange} =
useCaption();
// const isDisabled = !isAuthorizedTranscriptUser();
const isDisabled = !sttDepsReady || props?.disabled;
const [isLanguagePopupOpen, setLanguagePopup] =
React.useState<boolean>(false);
// const isFirstTimePopupOpen = React.useRef(false);
const isTranscriptON = sidePanel === SidePanelType.Transcript;
const onPress = () => {
if (isSTTError || !isSTTActive) {
setLanguagePopup(true);
} else {
// isFirstTimePopupOpen.current = true;
setSidePanel(
isTranscriptON ? SidePanelType.None : SidePanelType.Transcript,
);
}
};
const label = useString<boolean>(toolbarItemTranscriptText);
const iconButtonProps: IconButtonProps = {
onPress: onPressCustom || onPress,
disabled: isDisabled,
iconProps: {
name: 'transcript',
iconBackgroundColor: isTranscriptON
? $config.PRIMARY_ACTION_BRAND_COLOR
: '',
tintColor: isDisabled
? $config.SEMANTIC_NEUTRAL
: isTranscriptON
? $config.PRIMARY_ACTION_TEXT_COLOR
: $config.SECONDARY_ACTION_COLOR,
},
btnTextProps: {
text: showLabel
? isOnActionSheet
? labelCustom || label(isTranscriptON)?.replace(' ', '\n')
: labelCustom || label(isTranscriptON)
: '',
textColor: isDisabled ? $config.SEMANTIC_NEUTRAL : $config.FONT_COLOR,
numberOfLines: 2,
},
};
iconButtonProps.isOnActionSheet = isOnActionSheet;
if (!isOnActionSheet) {
iconButtonProps.toolTipMessage = label(isTranscriptON);
}
const onConfirm = async (newSpokenLang: LanguageType) => {
// isFirstTimePopupOpen.current = false;
// const method = isTranscriptON ? 'stop' : 'start';
// if (method === 'stop') return; // not closing the stt service as it will stop for whole channel
// if (method === 'start' && isSTTActive === true) return; // not triggering the start service if STT Service already started by anyone else in the channel
setLanguagePopup(false);
try {
// const res = await start(language, userOwnLanguages);
// if (res?.message.includes('STARTED')) {
// // channel is already started now restart
// await restart(language, userOwnLanguages);
// }
await confirmSpokenLanguageChange(newSpokenLang);
if (!isTranscriptON) {
setSidePanel(SidePanelType.Transcript);
} else {
setSidePanel(SidePanelType.None);
}
} catch (error) {
console.log('eror in starting stt', error);
}
};
return (
<View>
<IconButton {...iconButtonProps} />
<LanguageSelectorPopup
modalVisible={isLanguagePopupOpen}
setModalVisible={setLanguagePopup}
onConfirm={onConfirm}
// isFirstTimePopupOpen={isFirstTimePopupOpen.current}
/>
</View>
);
};
export default TranscriptIcon;
const styles = StyleSheet.create({});