Files
reflector/www/app/(app)/transcripts/useTopicWithWords.ts
Mathieu Virbel fbeeff4c4d feat: complete migration from @hey-api/openapi-ts to openapi-react-query
- Migrated all components from useApi compatibility layer to direct React Query hooks
- Added new hooks for participant operations, room meetings, and speaker operations
- Updated all imports from old api module to api-types
- Fixed TypeScript types and API endpoint signatures
- Removed deprecated useApi.ts compatibility layer
- Fixed SourceKind enum values to match OpenAPI spec
- Added @ts-ignore for Zulip endpoints not in OpenAPI spec yet
- Fixed all compilation errors and type issues
2025-08-29 09:36:55 -06:00

70 lines
1.5 KiB
TypeScript

import { GetTranscriptTopicWithWordsPerSpeaker } from "../../lib/api-types";
import { useTranscriptTopicsWithWordsPerSpeaker } from "../../lib/api-hooks";
type ErrorTopicWithWords = {
error: Error;
loading: false;
response: null;
};
type LoadingTopicWithWords = {
response: GetTranscriptTopicWithWordsPerSpeaker | null;
loading: true;
error: false;
};
type SuccessTopicWithWords = {
response: GetTranscriptTopicWithWordsPerSpeaker;
loading: false;
error: null;
};
export type UseTopicWithWords = { refetch: () => void } & (
| ErrorTopicWithWords
| LoadingTopicWithWords
| SuccessTopicWithWords
);
const useTopicWithWords = (
topicId: string | undefined,
transcriptId: string,
): UseTopicWithWords => {
const {
data: response,
isLoading: loading,
error,
refetch,
} = useTranscriptTopicsWithWordsPerSpeaker(
transcriptId || null,
topicId || null,
);
// Type-safe return based on state
if (error) {
return {
error: error as Error,
loading: false,
response: null,
refetch,
} as ErrorTopicWithWords & { refetch: () => void };
}
if (loading || !response) {
return {
response: response || null,
loading: true,
error: false,
refetch,
} as LoadingTopicWithWords & { refetch: () => void };
}
return {
response,
loading: false,
error: null,
refetch,
} as SuccessTopicWithWords & { refetch: () => void };
};
export default useTopicWithWords;