轻松聘
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.
 
 
 

42 lines
1.3 KiB

/**
* 企业端人才推荐数据 hook。
* Tab 与搜索词状态放在这里,过滤规则由接口层(filterTalentCandidates)给出,
* 页面只把点击/输入转成 setTab / setKeyword 再渲染 candidates。
*/
import { useCallback, useState } from 'react';
import { fetchTalentRecommendation, filterTalentCandidates } from '../api';
import type { TalentCandidate, TalentRecommendation } from '../types';
import { useAsyncData } from './useAsyncData';
export function useTalentRecommendation() {
const fetcher = useCallback(
async (): Promise<TalentRecommendation> => fetchTalentRecommendation(),
[],
);
const { data, loading, error, refresh } = useAsyncData(fetcher);
const [activeTab, setActiveTab] = useState('all');
const [keyword, setKeyword] = useState('');
const recommendation = data ?? null;
/** 按当前 Tab + 关键词过滤后的候选人 */
const candidates: TalentCandidate[] = recommendation
? filterTalentCandidates(recommendation.candidates, activeTab, keyword)
: [];
/** 有关键词但一条没命中 */
const isEmptySearch = recommendation !== null && keyword.trim() !== '' && candidates.length === 0;
return {
recommendation,
activeTab,
setActiveTab,
keyword,
setKeyword,
candidates,
isEmptySearch,
loading,
error,
refresh,
};
}