You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
/**
|
|
* 消息/沟通数据 hook:聚合会话、通知、面试、匹配结果
|
|
*/
|
|
import {
|
|
fetchConversations,
|
|
fetchInterviews,
|
|
fetchMatchResult,
|
|
fetchNotifications,
|
|
fetchPendingOfferCount,
|
|
} from '../api';
|
|
import { useAsyncData } from './useAsyncData';
|
|
|
|
/** 聚合拉取消息中心全部数据(模块级函数,引用稳定,避免 useAsyncData 反复触发) */
|
|
async function fetchMessageData() {
|
|
const [conversations, notifications, interviews, matchResult, pendingOfferCount] =
|
|
await Promise.all([
|
|
fetchConversations(),
|
|
fetchNotifications(),
|
|
fetchInterviews(),
|
|
fetchMatchResult(),
|
|
fetchPendingOfferCount(),
|
|
]);
|
|
return { conversations, notifications, interviews, matchResult, pendingOfferCount };
|
|
}
|
|
|
|
export function useMessageData() {
|
|
const { data, loading, error, refresh } = useAsyncData(fetchMessageData);
|
|
|
|
const conversations = data?.conversations ?? [];
|
|
const notifications = data?.notifications ?? [];
|
|
const interviews = data?.interviews ?? [];
|
|
const matchResult = data?.matchResult ?? null;
|
|
/** 待处理 Offer 数:为 0 时聊天页不渲染横幅,不再显示写死的「2 个」 */
|
|
const pendingOfferCount = data?.pendingOfferCount ?? 0;
|
|
// 空状态:加载完成且无错误、但三类列表均为空
|
|
const isEmpty =
|
|
!loading &&
|
|
!error &&
|
|
conversations.length === 0 &&
|
|
notifications.length === 0 &&
|
|
interviews.length === 0;
|
|
|
|
return {
|
|
conversations,
|
|
notifications,
|
|
interviews,
|
|
matchResult,
|
|
pendingOfferCount,
|
|
loading,
|
|
error,
|
|
refresh,
|
|
isEmpty,
|
|
};
|
|
}
|
|
|