Spaces:
Sleeping
Sleeping
| import type { ThemeExtractionRequest, ThemeExtractionResponse } from '@/schema/theme-extraction'; | |
| import { useMutation, useQuery } from '@tanstack/react-query'; | |
| import { themeExtractionApi } from './index'; | |
| /** | |
| * テーマ抽出用のReact Queryフック | |
| */ | |
| export const useThemeExtraction = () => { | |
| return useMutation<ThemeExtractionResponse, Error, ThemeExtractionRequest>({ | |
| mutationFn: themeExtractionApi.extractTheme, | |
| onSuccess: (data) => { | |
| console.log('[useThemeExtraction] Theme extraction completed:', data); | |
| }, | |
| onError: (error) => { | |
| console.error('[useThemeExtraction] Theme extraction failed:', error); | |
| }, | |
| }); | |
| }; | |
| /** | |
| * 利用可能なプロバイダー取得用のReact Queryフック | |
| */ | |
| export const useThemeExtractionProviders = (enabled: boolean = true) => { | |
| return useQuery({ | |
| queryKey: ['theme-extraction', 'providers'], | |
| queryFn: themeExtractionApi.getProviders, | |
| enabled, | |
| staleTime: 5 * 60 * 1000, // 5分間キャッシュ | |
| retry: 2, | |
| }); | |
| }; | |
| /** | |
| * テーマ抽出ヘルスチェック用のReact Queryフック | |
| */ | |
| export const useThemeExtractionHealth = (enabled: boolean = false) => { | |
| return useQuery({ | |
| queryKey: ['theme-extraction', 'health'], | |
| queryFn: themeExtractionApi.healthCheck, | |
| enabled, | |
| staleTime: 1 * 60 * 1000, // 1分間キャッシュ | |
| retry: 1, | |
| }); | |
| }; | |