FE_Dev / api-client /pox /queries.ts
GitHub Actions
Deploy from GitHub Actions [dev] - 2025-10-31 07:28:50
68f7925
import type { SwotData } from '@/schema/pox';
import { getPox } from '@/services/gradio-with-dummy';
import { useGlobalStore } from '@/store/global';
import { useQuery } from '@tanstack/react-query';
export function usePox(commonDict: unknown, scoreDict: unknown, scoreTotal: unknown, userEmail: string) {
const { dummyMode, userIdentifier } = useGlobalStore();
return useQuery<SwotData>({
queryKey: ['pox', commonDict, scoreDict, scoreTotal, userEmail, dummyMode],
queryFn: async () => {
const userData = {
commonDict: commonDict as object,
scoreDict: scoreDict as object,
score_total: scoreTotal as object,
};
// Gradio APIを直接呼び出し
const result = await getPox(userData, userEmail || null, userIdentifier);
// 結果の最初の要素(基本SWOT)を返す
if (Array.isArray(result) && result.length > 0) {
return result[0] as SwotData;
}
throw new Error('Invalid POX response format');
},
enabled:
(dummyMode || userEmail !== '') &&
(dummyMode ||
(commonDict !== undefined &&
commonDict !== null &&
scoreDict !== undefined &&
scoreDict !== null &&
scoreTotal !== undefined &&
scoreTotal !== null)),
staleTime: 1000 * 60 * 5, // 5分間はキャッシュを使用
});
}