import { useState } from 'react';
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useMessageData } from '../../src/hooks';
import type { Conversation, Interview, Notification } from '../../src/types';
import { colors } from '../../src/theme';
/** Tab 键 */
type TabKey = 'message' | 'notification' | 'interview';
/** Tab 配置 */
const TABS: { key: TabKey; label: string }[] = [
{ key: 'message', label: '消息' },
{ key: 'notification', label: '通知' },
{ key: 'interview', label: '面试' },
];
/** 会话卡片 */
function ConversationCard({ conversation }: { conversation: Conversation }) {
return (
{conversation.avatar}
{conversation.unread && }
{conversation.contactName}
{conversation.lastMessage}
{conversation.timestamp}
{conversation.matched && (
✓ 已匹配
)}
);
}
/** 通知卡片 */
function NotificationCard({ notification }: { notification: Notification }) {
return (
{!notification.read && }
{notification.title}
{notification.content}
{notification.timestamp}
);
}
/** 面试卡片 */
function InterviewCard({ interview }: { interview: Interview }) {
const isVideo = interview.type === 'video';
return (
{interview.companyName}·{interview.positionName}
{interview.time}
{isVideo ? '视频面试' : '线下面试'}
{
console.log(isVideo ? '加入会议' : '导航前往', interview.id);
}}
>
{isVideo ? '加入会议' : '导航前往'}
);
}
/**
* 消息/沟通页
*/
export default function ChatScreen() {
const [tab, setTab] = useState('message');
const { conversations, notifications, interviews, matchResult, loading, error, refresh } =
useMessageData();
// 加载态
if (loading) {
return (
);
}
// 错误态
if (error) {
return (
加载失败,请重试
重试
);
}
return (
{/* 顶部导航 */}
消息
{/* Tab 切换栏 */}
{TABS.map((item) => {
const active = tab === item.key;
return (
setTab(item.key)}>
{item.label}
);
})}
{/* 内容区 */}
{tab === 'message' && (
<>
{/* 双向匹配成功横幅 */}
{matchResult && (
{
console.log('查看匹配详情', matchResult.companies);
}}
>
恭喜!您与{matchResult.total}家企业双向匹配成功
点击查看详情
)}
{/* 会话列表 */}
{conversations.length === 0 ? (
暂无消息
) : (
conversations.map((conversation) => (
))
)}
>
)}
{tab === 'notification' && (
<>
{/* Offer 待处理横幅 */}
{
console.log('查看 Offer 列表');
}}
>
您有2个Offer待处理
立即查看 >
{/* 系统通知列表 */}
{notifications.length === 0 ? (
暂无通知
) : (
notifications.map((notification) => (
))
)}
>
)}
{tab === 'interview' && (
<>
{/* 面试日程标题 */}
今日面试
{
console.log('查看全部日程');
}}
>
全部日程 >
{/* 面试卡片 */}
{interviews.length === 0 ? (
暂无面试
) : (
interviews.map((interview) => (
))
)}
>
)}
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: colors.pageBg,
},
loading: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
stateText: {
marginTop: 12,
fontSize: 14,
color: colors.textSecondary,
},
retryBtn: {
marginTop: 16,
paddingHorizontal: 24,
paddingVertical: 8,
borderRadius: 18,
backgroundColor: colors.primaryBtn,
},
retryText: {
fontSize: 13,
fontWeight: '600',
color: colors.white,
},
emptyText: {
paddingVertical: 24,
fontSize: 14,
color: colors.textSecondary,
textAlign: 'center',
},
nav: {
paddingHorizontal: 20,
paddingTop: 8,
paddingBottom: 12,
},
navTitle: {
fontSize: 24,
fontWeight: '700',
color: colors.textPrimary,
},
tabBar: {
flexDirection: 'row',
paddingHorizontal: 20,
borderBottomWidth: 1,
borderBottomColor: colors.border,
},
tabItem: {
flex: 1,
alignItems: 'center',
paddingTop: 4,
},
tabLabel: {
fontSize: 15,
color: colors.textSecondary,
paddingBottom: 8,
},
tabLabelActive: {
color: colors.textPrimary,
fontWeight: '600',
},
tabIndicator: {
height: 2,
width: 24,
borderRadius: 1,
backgroundColor: 'transparent',
marginBottom: -1,
},
tabIndicatorActive: {
backgroundColor: colors.primary,
},
scroll: {
flex: 1,
},
content: {
paddingHorizontal: 20,
paddingTop: 16,
paddingBottom: 24,
},
// 匹配横幅
matchBanner: {
backgroundColor: colors.primaryLight,
borderRadius: 16,
padding: 16,
marginBottom: 16,
},
matchBannerTitle: {
fontSize: 15,
fontWeight: '700',
color: colors.primaryDark,
},
matchBannerLink: {
marginTop: 6,
fontSize: 13,
color: colors.primary,
},
// 会话卡片
convCard: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 12,
},
avatarWrap: {
position: 'relative',
},
avatar: {
width: 44,
height: 44,
borderRadius: 22,
backgroundColor: colors.primaryLight,
alignItems: 'center',
justifyContent: 'center',
},
avatarText: {
fontSize: 16,
fontWeight: '700',
color: colors.primary,
},
unreadDot: {
position: 'absolute',
top: 0,
right: 0,
width: 10,
height: 10,
borderRadius: 5,
backgroundColor: colors.danger,
borderWidth: 1.5,
borderColor: colors.white,
},
convBody: {
flex: 1,
marginLeft: 12,
},
contactName: {
fontSize: 15,
fontWeight: '600',
color: colors.textPrimary,
},
lastMessage: {
marginTop: 4,
fontSize: 13,
color: colors.textSecondary,
},
convRight: {
alignItems: 'flex-end',
marginLeft: 8,
},
time: {
fontSize: 12,
color: colors.textSecondary,
},
matchedTag: {
marginTop: 6,
backgroundColor: colors.primaryLight,
borderRadius: 8,
paddingHorizontal: 6,
paddingVertical: 2,
},
matchedText: {
fontSize: 11,
color: colors.primaryDark,
},
// Offer 横幅
offerBanner: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: colors.actionLight,
borderRadius: 16,
padding: 16,
marginBottom: 16,
},
offerTitle: {
flex: 1,
fontSize: 15,
fontWeight: '700',
color: colors.textPrimary,
},
offerLink: {
fontSize: 13,
fontWeight: '600',
color: colors.action,
},
// 通知卡片
notiCard: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 12,
},
notiTitleRow: {
flexDirection: 'row',
alignItems: 'center',
},
notiDot: {
width: 8,
height: 8,
borderRadius: 4,
backgroundColor: colors.danger,
marginRight: 6,
},
notiTitle: {
fontSize: 15,
fontWeight: '600',
color: colors.textPrimary,
},
notiContent: {
marginTop: 6,
fontSize: 13,
lineHeight: 18,
color: colors.textSecondary,
},
notiTime: {
marginTop: 8,
fontSize: 12,
color: colors.textSecondary,
},
// 面试
sectionHeader: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: 12,
},
sectionTitle: {
fontSize: 18,
fontWeight: '700',
color: colors.textPrimary,
},
sectionLink: {
fontSize: 13,
color: colors.primary,
},
interviewCard: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 12,
},
interviewHeader: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
interviewTitle: {
flex: 1,
fontSize: 15,
fontWeight: '700',
color: colors.textPrimary,
},
interviewTime: {
marginLeft: 8,
fontSize: 16,
fontWeight: '700',
color: colors.textPrimary,
},
interviewFooter: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginTop: 12,
},
typeTag: {
borderRadius: 8,
paddingHorizontal: 8,
paddingVertical: 3,
},
typeTagVideo: {
backgroundColor: colors.primaryLight,
},
typeTagOffline: {
backgroundColor: colors.border,
},
typeText: {
fontSize: 12,
fontWeight: '600',
},
typeTextVideo: {
color: colors.primary,
},
typeTextOffline: {
color: colors.textSecondary,
},
actionBtn: {
backgroundColor: colors.primaryBtn,
borderRadius: 18,
paddingHorizontal: 16,
paddingVertical: 8,
},
actionText: {
fontSize: 13,
fontWeight: '600',
color: colors.white,
},
});