mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
- Migrate use-github-issues to useGitHubIssues query - Migrate use-issue-comments to useGitHubIssueComments infinite query - Migrate use-issue-validation to useGitHubValidations with mutations - Migrate github-prs-view to useGitHubPRs query - Support pagination for comments with useInfiniteQuery - Remove manual loading state management Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { useMemo, useCallback } from 'react';
|
|
import type { GitHubComment } from '@/lib/electron';
|
|
import { useAppStore } from '@/store/app-store';
|
|
import { useGitHubIssueComments } from '@/hooks/queries';
|
|
|
|
interface UseIssueCommentsResult {
|
|
comments: GitHubComment[];
|
|
totalCount: number;
|
|
loading: boolean;
|
|
loadingMore: boolean;
|
|
hasNextPage: boolean;
|
|
error: string | null;
|
|
loadMore: () => void;
|
|
refresh: () => void;
|
|
}
|
|
|
|
export function useIssueComments(issueNumber: number | null): UseIssueCommentsResult {
|
|
const { currentProject } = useAppStore();
|
|
|
|
// Use React Query infinite query
|
|
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage, refetch, error } =
|
|
useGitHubIssueComments(currentProject?.path, issueNumber ?? undefined);
|
|
|
|
// Flatten all pages into a single comments array
|
|
const comments = useMemo(() => {
|
|
return data?.pages.flatMap((page) => page.comments) ?? [];
|
|
}, [data?.pages]);
|
|
|
|
// Get total count from the first page
|
|
const totalCount = data?.pages[0]?.totalCount ?? 0;
|
|
|
|
const loadMore = useCallback(() => {
|
|
if (hasNextPage && !isFetchingNextPage) {
|
|
fetchNextPage();
|
|
}
|
|
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
|
|
|
const refresh = useCallback(() => {
|
|
refetch();
|
|
}, [refetch]);
|
|
|
|
return {
|
|
comments,
|
|
totalCount,
|
|
loading: isLoading,
|
|
loadingMore: isFetchingNextPage,
|
|
hasNextPage: hasNextPage ?? false,
|
|
error: error instanceof Error ? error.message : null,
|
|
loadMore,
|
|
refresh,
|
|
};
|
|
}
|