mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 10:31:13 -05:00
feat: Implement Phase 4 cleanup and polish
This commit is contained in:
32
src/hooks/companies/useCompanyDetail.ts
Normal file
32
src/hooks/companies/useCompanyDetail.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Company Detail Hook
|
||||
*
|
||||
* Fetches company details with caching for efficient data access.
|
||||
*/
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
|
||||
export function useCompanyDetail(slug: string | undefined, companyType: string) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.companies.detail(slug || '', companyType),
|
||||
queryFn: async () => {
|
||||
if (!slug) return null;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('companies')
|
||||
.select('*')
|
||||
.eq('slug', slug)
|
||||
.eq('company_type', companyType)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
},
|
||||
enabled: !!slug,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
gcTime: 15 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user