mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 20:23:36 +00:00
feat(ui): add React Query hooks for data fetching
- Add useFeatures, useFeature, useAgentOutput for feature data - Add useGitHubIssues, useGitHubPRs, useGitHubValidations, useGitHubIssueComments - Add useClaudeUsage, useCodexUsage with polling intervals - Add useRunningAgents, useRunningAgentsCount - Add useWorktrees, useWorktreeInfo, useWorktreeStatus, useWorktreeDiffs - Add useGlobalSettings, useProjectSettings, useCredentials - Add useAvailableModels, useCodexModels, useOpencodeModels - Add useSessions, useSessionHistory, useSessionQueue - Add useIdeationPrompts, useIdeas - Add CLI status queries (claude, cursor, codex, opencode, github) - Add useCursorPermissionsQuery, useWorkspaceDirectories - Add usePipelineConfig, useSpecFile, useSpecRegenerationStatus Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
122
apps/ui/src/hooks/queries/use-settings.ts
Normal file
122
apps/ui/src/hooks/queries/use-settings.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Settings Query Hooks
|
||||
*
|
||||
* React Query hooks for fetching global and project settings.
|
||||
*/
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getElectronAPI } from '@/lib/electron';
|
||||
import { queryKeys } from '@/lib/query-keys';
|
||||
import { STALE_TIMES } from '@/lib/query-client';
|
||||
import type { GlobalSettings, ProjectSettings } from '@automaker/types';
|
||||
|
||||
/**
|
||||
* Fetch global settings
|
||||
*
|
||||
* @returns Query result with global settings
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { data: settings, isLoading } = useGlobalSettings();
|
||||
* ```
|
||||
*/
|
||||
export function useGlobalSettings() {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.settings.global(),
|
||||
queryFn: async (): Promise<GlobalSettings> => {
|
||||
const api = getElectronAPI();
|
||||
const result = await api.settings.getGlobal();
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to fetch global settings');
|
||||
}
|
||||
return result.settings as GlobalSettings;
|
||||
},
|
||||
staleTime: STALE_TIMES.SETTINGS,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch project-specific settings
|
||||
*
|
||||
* @param projectPath - Path to the project
|
||||
* @returns Query result with project settings
|
||||
*/
|
||||
export function useProjectSettings(projectPath: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.settings.project(projectPath ?? ''),
|
||||
queryFn: async (): Promise<ProjectSettings> => {
|
||||
if (!projectPath) throw new Error('No project path');
|
||||
const api = getElectronAPI();
|
||||
const result = await api.settings.getProject(projectPath);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to fetch project settings');
|
||||
}
|
||||
return result.settings as ProjectSettings;
|
||||
},
|
||||
enabled: !!projectPath,
|
||||
staleTime: STALE_TIMES.SETTINGS,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch settings status (migration status, etc.)
|
||||
*
|
||||
* @returns Query result with settings status
|
||||
*/
|
||||
export function useSettingsStatus() {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.settings.status(),
|
||||
queryFn: async () => {
|
||||
const api = getElectronAPI();
|
||||
const result = await api.settings.getStatus();
|
||||
return result;
|
||||
},
|
||||
staleTime: STALE_TIMES.SETTINGS,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch credentials status (masked API keys)
|
||||
*
|
||||
* @returns Query result with credentials info
|
||||
*/
|
||||
export function useCredentials() {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.settings.credentials(),
|
||||
queryFn: async () => {
|
||||
const api = getElectronAPI();
|
||||
const result = await api.settings.getCredentials();
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to fetch credentials');
|
||||
}
|
||||
return result.credentials;
|
||||
},
|
||||
staleTime: STALE_TIMES.SETTINGS,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover agents for a project
|
||||
*
|
||||
* @param projectPath - Path to the project
|
||||
* @param sources - Sources to search ('user' | 'project')
|
||||
* @returns Query result with discovered agents
|
||||
*/
|
||||
export function useDiscoveredAgents(
|
||||
projectPath: string | undefined,
|
||||
sources?: Array<'user' | 'project'>
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.settings.agents(projectPath ?? ''),
|
||||
queryFn: async () => {
|
||||
const api = getElectronAPI();
|
||||
const result = await api.settings.discoverAgents(projectPath, sources);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to discover agents');
|
||||
}
|
||||
return result.agents ?? [];
|
||||
},
|
||||
enabled: !!projectPath,
|
||||
staleTime: STALE_TIMES.SETTINGS,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user