Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/data/server/socket.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useStore } from '@/data';
import { MayaRequest, MayaUpdate, WSUpdate } from '@/data/types';
import { MayaRequest, MayaUpdate, WSUpdate, ThinkingUpdate } from '@/data/types';
import { client } from '@/data/server/updates';
import { WS_URL, WEB, logger } from '@/data';
import 'react-native-get-random-values';
Expand All @@ -23,6 +23,7 @@ class Socket {
related: client.handleRelatedUpdate,
search: client.handleSearchUpdate,
slug: client.handleSlugUpdate,
thinking: client.handleThinkingUpdate,
};
}

Expand Down Expand Up @@ -131,6 +132,14 @@ class Socket {

logger.info('sending request: ', message.command);
};

public setThinkingHandler(handler: (data: ThinkingUpdate) => void) {
this.updateHandlers.thinking = handler;
}

public removeThinkingHandler() {
this.updateHandlers.thinking = client.handleThinkingUpdate;
}
}

export const socket = new Socket();
6 changes: 6 additions & 0 deletions src/data/server/updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SearchResult,
SlugData,
UpdateInfo,
ThinkingUpdate,
} from '@/data/types';

class ClientUpdate {
Expand Down Expand Up @@ -119,6 +120,11 @@ class ClientUpdate {
state.clearUser();
}
}

handleThinkingUpdate(data: ThinkingUpdate) {
// Handle thinking state updates
logger.info('thinking update:', data.isThinking);
}
}

export const client = new ClientUpdate();
8 changes: 7 additions & 1 deletion src/data/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type WSUpdate =
| "confidence"
| "related"
| "search"
| "slug";
| "slug"
| "thinking";
export type SuccessCode =
| "success"
| "token sent"
Expand Down Expand Up @@ -282,3 +283,8 @@ export interface UserUpdate {
update?: WSUpdate & string;
background?: boolean;
}
export interface ThinkingUpdate {
isThinking: boolean;
update?: WSUpdate & string;
background?: boolean;
}
2 changes: 1 addition & 1 deletion src/data/utils/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ENV: Environment = 'local';
export let DEV_SCREEN: Screen;

// Reset local state & storage on app load
export let RESET_STATE = false;
export let RESET_STATE = true;

//////////////////////////////////

Expand Down
27 changes: 26 additions & 1 deletion src/views/chat/components/message/message.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, ActivityIndicator, Text } from 'react-native';
import { Message, Confidence, Profile } from '@/data/types';
import {
Bubble,
Expand Down Expand Up @@ -31,6 +31,7 @@ interface MessageProps {
position?: 'left' | 'right';
stream?: boolean;
info?: boolean;
isThinking?: boolean;
}

const MessageUI: React.FC<MessageProps> = props => {
Expand All @@ -43,6 +44,7 @@ const MessageUI: React.FC<MessageProps> = props => {
profiles = [],
stream = false,
info = false,
isThinking = true,
position = 'left',
} = props;

Expand Down Expand Up @@ -161,6 +163,18 @@ const MessageUI: React.FC<MessageProps> = props => {
);
};

const renderThinkingIndicator = () => {
if (isThinking) {
return (
<View style={styles.base.thinkingContainer}>
<ActivityIndicator size="small" color="#666" />
<Text style={styles.base.thinkingText}>Thinking...</Text>
</View>
);
}
return null;
};

return (
<View
style={[
Expand All @@ -180,6 +194,7 @@ const MessageUI: React.FC<MessageProps> = props => {
/>
{position === 'right' && renderAvatar()}
</View>
{renderThinkingIndicator()}
{renderButtons()}
</View>
);
Expand Down Expand Up @@ -239,6 +254,16 @@ const getStyles = () => ({
thumbsUp: {
paddingBottom: 2,
},
thinkingContainer: {
flexDirection: 'row',
alignItems: 'center',
marginLeft: 62,
marginTop: 8,
},
thinkingText: {
marginLeft: 8,
color: '#666',
},
}),
left: StyleSheet.create({
container: {
Expand Down
2 changes: 2 additions & 0 deletions src/views/chat/components/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface MessageListProps {
style?: ViewStyle;
info?: boolean;
chatid: string;
isThinking?: boolean;
}

const MessageList = forwardRef<FlatList<any>, MessageListProps>(
Expand Down Expand Up @@ -49,6 +50,7 @@ const MessageList = forwardRef<FlatList<any>, MessageListProps>(
username={usernames[current.sender] || ''}
profiles={profiles}
info={info}
isThinking={props.isThinking}
/>
);
}
Expand Down
22 changes: 21 additions & 1 deletion src/views/chat/screens/discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
KeyboardAvoidingView,
FlatList,
Keyboard,
ActivityIndicator,
Text,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { StackNavigationProp } from '@react-navigation/stack';
Expand All @@ -14,7 +16,8 @@ import { useRoute } from '@react-navigation/native';
import { RootStackParamList } from '@/views/navigator';
import { Theme, useTheme } from '@/ui/theme';
import { IconButton, Words, Divider } from '@/ui/atoms';
import { Message, Profile } from '@/data/types';
import { Message, Profile, ThinkingUpdate } from '@/data/types';
import { socket } from '@/data/server';
import {
State,
useStore,
Expand Down Expand Up @@ -195,6 +198,22 @@ const Discussion: React.FC = () => {
// Additional logic for handling the selected topic
};

const [isThinking, setIsThinking] = useState(false);

useEffect(() => {
// Listen for thinking state updates
const handleThinkingUpdate = (update: ThinkingUpdate) => {
setIsThinking(update.isThinking);
};

// Subscribe to thinking updates
socket.setThinkingHandler(handleThinkingUpdate);

return () => {
socket.removeThinkingHandler();
};
}, []);

return (
<SafeAreaView edges={['top']} style={styles.container}>
<KeyboardAvoidingView
Expand Down Expand Up @@ -230,6 +249,7 @@ const Discussion: React.FC = () => {
info
chatid={thread}
ref={messagesRef}
isThinking={isThinking}
/>

{!WEB && <InputToolbar onSend={onSend} />}
Expand Down