refactor(usage): consolidate query logic to eliminate DRY violations
Breaking Changes: - Removed useAutoUsageQuery hook (119 lines) - Unified all usage queries into single useUsageQuery hook Technical Improvements: - Eliminated duplicate state management (React Query + manual useState) - Fixed single source of truth principle violation - Replaced manual setInterval with React Query's built-in refetchInterval - Reduced UsageFooter complexity by 28% (54 → 39 lines) New Features: - useUsageQuery now accepts autoQueryInterval option - Automatic query interval control (0 = disabled, min 1 minute) - Built-in lastQueriedAt timestamp from dataUpdatedAt - Auto-query only enabled for currently active provider Architecture Benefits: - Single data source: manual and auto queries share same cache - No more state inconsistency between manual/auto query results - Leverages React Query's caching, deduplication, and background updates - Cleaner separation of concerns Code Changes: - src/lib/query/queries.ts: Enhanced useUsageQuery with auto-query support - src/components/UsageFooter.tsx: Simplified to use single query hook - src/hooks/useAutoUsageQuery.ts: Deleted (redundant) - All type checks passed
This commit is contained in:
@@ -6,7 +6,7 @@ import i18n from "@/i18n";
|
||||
export const usageApi = {
|
||||
async query(providerId: string, appId: AppId): Promise<UsageResult> {
|
||||
try {
|
||||
return await invoke("query_provider_usage", {
|
||||
return await invoke("queryProviderUsage", {
|
||||
providerId: providerId,
|
||||
app: appId,
|
||||
});
|
||||
@@ -36,7 +36,7 @@ export const usageApi = {
|
||||
userId?: string
|
||||
): Promise<UsageResult> {
|
||||
try {
|
||||
return await invoke("test_usage_script", {
|
||||
return await invoke("testUsageScript", {
|
||||
providerId: providerId,
|
||||
app: appId,
|
||||
scriptCode: scriptCode,
|
||||
@@ -59,4 +59,3 @@ export const usageApi = {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user