-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathAITypingIndicatorView.tsx
More file actions
63 lines (53 loc) · 1.76 KB
/
AITypingIndicatorView.tsx
File metadata and controls
63 lines (53 loc) · 1.76 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
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Channel } from 'stream-chat';
import { AIStates, useAIState } from './hooks/useAIState';
import { useChannelContext, useTheme, useTranslationContext } from '../../contexts';
import { primitives } from '../../theme';
export type AITypingIndicatorViewProps = {
channel?: Channel;
};
export const AITypingIndicatorView = ({
channel: channelFromProps,
}: AITypingIndicatorViewProps) => {
const { t } = useTranslationContext();
const { channel: channelFromContext } = useChannelContext();
const channel = channelFromProps || channelFromContext;
const { aiState } = useAIState(channel);
const allowedStates = {
[AIStates.Thinking]: t('Thinking...'),
[AIStates.Generating]: t('Generating...'),
};
const styles = useStyles();
return aiState in allowedStates ? (
<View style={styles.container}>
<Text style={styles.text}>{allowedStates[aiState]}</Text>
</View>
) : null;
};
AITypingIndicatorView.displayName = 'AITypingIndicatorView{messageItemView{content}}';
const useStyles = () => {
const {
theme: {
aiTypingIndicatorView: { container, text },
semantics,
},
} = useTheme();
return useMemo(() => {
return StyleSheet.create({
container: {
backgroundColor: semantics.backgroundCoreSurface,
paddingHorizontal: primitives.spacingMd,
paddingVertical: primitives.spacingLg,
...container,
},
text: {
color: semantics.textPrimary,
fontSize: primitives.typographyFontSizeMd,
fontWeight: primitives.typographyFontWeightSemiBold,
lineHeight: primitives.typographyLineHeightNormal,
...text,
},
});
}, [container, text, semantics]);
};