2025-06-20 05:23:50 +08:00
|
|
|
import { AuthOverlay } from '@/components/AuthOverlay';
|
2025-06-17 04:21:36 +08:00
|
|
|
import { ChatContainer } from '@/components/ChatContainer';
|
|
|
|
import { ChatHeader } from '@/components/ChatHeader';
|
|
|
|
import { PanelContainer } from '@/components/PanelContainer';
|
2025-06-20 06:43:45 +08:00
|
|
|
import { Skeleton } from '@/components/Skeleton';
|
2025-06-20 05:23:50 +08:00
|
|
|
import { useAuth } from '@/hooks/useAuth';
|
2025-06-25 05:59:07 +08:00
|
|
|
import { useChatSession, useNewChatSession } from '@/hooks/useChatHooks';
|
2025-06-17 04:21:36 +08:00
|
|
|
import { useThemedStyles } from '@/hooks/useThemeColor';
|
2025-06-24 05:15:02 +08:00
|
|
|
import {
|
2025-06-25 05:59:07 +08:00
|
|
|
useIsNewChatMode,
|
2025-06-24 05:15:02 +08:00
|
|
|
useLeftPanelVisible,
|
|
|
|
useRightPanelVisible,
|
2025-06-25 05:59:07 +08:00
|
|
|
useSelectedProject,
|
2025-06-24 05:15:02 +08:00
|
|
|
useSetLeftPanelVisible,
|
|
|
|
useSetRightPanelVisible
|
|
|
|
} from '@/stores/ui-store';
|
2025-06-20 06:43:45 +08:00
|
|
|
import { View } from 'react-native';
|
2025-06-17 04:21:36 +08:00
|
|
|
|
|
|
|
export default function HomeScreen() {
|
2025-06-24 05:15:02 +08:00
|
|
|
// Use store state instead of local state for panel visibility
|
|
|
|
const leftPanelVisible = useLeftPanelVisible();
|
|
|
|
const rightPanelVisible = useRightPanelVisible();
|
|
|
|
const setLeftPanelVisible = useSetLeftPanelVisible();
|
|
|
|
const setRightPanelVisible = useSetRightPanelVisible();
|
|
|
|
|
2025-06-20 05:23:50 +08:00
|
|
|
const { user, loading } = useAuth();
|
2025-06-25 05:59:07 +08:00
|
|
|
const selectedProject = useSelectedProject();
|
|
|
|
const isNewChatMode = useIsNewChatMode();
|
2025-06-17 04:21:36 +08:00
|
|
|
|
2025-06-25 05:59:07 +08:00
|
|
|
// Use appropriate chat session based on mode
|
|
|
|
const projectChatSession = useChatSession(
|
|
|
|
(!isNewChatMode && selectedProject?.id && selectedProject.id !== 'new-chat-temp')
|
|
|
|
? selectedProject.id
|
|
|
|
: ''
|
|
|
|
);
|
|
|
|
const newChatSession = useNewChatSession();
|
|
|
|
|
2025-07-03 05:07:40 +08:00
|
|
|
// Extract messages from both sessions
|
|
|
|
const newChatMessages = newChatSession.messages;
|
|
|
|
const projectMessages = projectChatSession.messages;
|
|
|
|
|
2025-06-25 05:59:07 +08:00
|
|
|
// Select the right session based on mode
|
|
|
|
const { messages } = isNewChatMode ? newChatSession : projectChatSession;
|
2025-06-24 05:15:02 +08:00
|
|
|
|
2025-07-03 05:07:40 +08:00
|
|
|
// Simple fallback for tools panel - use newChatMessages OR messages
|
|
|
|
const newchatmessages = (newChatMessages && newChatMessages.length > 0) ? newChatMessages : messages;
|
|
|
|
|
|
|
|
// Basic logging to see which message state we have
|
|
|
|
console.log('=== MESSAGE STATE DEBUG ===');
|
|
|
|
console.log('isNewChatMode:', isNewChatMode);
|
|
|
|
console.log('newChatMessages length:', newChatMessages?.length || 0);
|
|
|
|
console.log('projectMessages length:', projectMessages?.length || 0);
|
|
|
|
console.log('selected messages length:', messages?.length || 0);
|
|
|
|
console.log('fallback newchatmessages length:', newchatmessages?.length || 0);
|
|
|
|
console.log('=============================');
|
|
|
|
|
2025-06-17 04:39:00 +08:00
|
|
|
const toggleLeftPanel = () => setLeftPanelVisible(!leftPanelVisible);
|
|
|
|
const toggleRightPanel = () => setRightPanelVisible(!rightPanelVisible);
|
2025-06-17 04:21:36 +08:00
|
|
|
|
|
|
|
const styles = useThemedStyles((theme) => ({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: theme.background,
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
backgroundColor: theme.background,
|
2025-06-24 05:15:02 +08:00
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderBottomColor: theme.border,
|
|
|
|
justifyContent: 'center' as const,
|
2025-06-17 04:21:36 +08:00
|
|
|
},
|
|
|
|
chatContainer: {
|
|
|
|
flex: 1,
|
2025-06-20 05:23:50 +08:00
|
|
|
},
|
2025-06-17 04:21:36 +08:00
|
|
|
}));
|
|
|
|
|
2025-06-20 05:23:50 +08:00
|
|
|
if (loading) {
|
|
|
|
return (
|
2025-06-24 05:15:02 +08:00
|
|
|
<View style={styles.container}>
|
|
|
|
<Skeleton />
|
2025-06-20 05:23:50 +08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2025-07-02 04:00:56 +08:00
|
|
|
<AuthOverlay
|
|
|
|
visible={true}
|
|
|
|
onClose={() => { }}
|
|
|
|
/>
|
2025-06-20 05:23:50 +08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-06-17 04:21:36 +08:00
|
|
|
return (
|
2025-06-24 05:15:02 +08:00
|
|
|
<View style={styles.container}>
|
|
|
|
<PanelContainer
|
|
|
|
leftPanelVisible={leftPanelVisible}
|
|
|
|
rightPanelVisible={rightPanelVisible}
|
|
|
|
onCloseLeft={() => {
|
|
|
|
console.log('onCloseLeft called');
|
|
|
|
setLeftPanelVisible(false);
|
|
|
|
}}
|
|
|
|
onCloseRight={() => setRightPanelVisible(false)}
|
|
|
|
onOpenLeft={() => setLeftPanelVisible(true)}
|
2025-07-03 05:07:40 +08:00
|
|
|
messages={newchatmessages}
|
2025-06-24 05:15:02 +08:00
|
|
|
>
|
2025-06-17 04:21:36 +08:00
|
|
|
<View style={styles.header}>
|
|
|
|
<ChatHeader
|
|
|
|
onMenuPress={toggleLeftPanel}
|
|
|
|
onSettingsPress={toggleRightPanel}
|
2025-06-25 04:43:44 +08:00
|
|
|
selectedProject={selectedProject}
|
2025-06-17 04:21:36 +08:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.chatContainer}>
|
2025-06-20 06:09:25 +08:00
|
|
|
<ChatContainer />
|
2025-06-17 04:21:36 +08:00
|
|
|
</View>
|
2025-06-24 05:15:02 +08:00
|
|
|
</PanelContainer>
|
|
|
|
</View>
|
2025-06-17 04:21:36 +08:00
|
|
|
);
|
|
|
|
}
|