fix(frontend): remove client-side Directus calls causing hydration errors

This commit is contained in:
cawcenter
2025-12-14 21:57:45 -05:00
parent 47654f51fb
commit 209a7e65ae
3 changed files with 108 additions and 13 deletions

View File

@@ -1,6 +1,5 @@
import React, { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getDirectusClient, readItems, deleteItem } from '@/lib/directus/client';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Plus, Search, Map } from 'lucide-react';
@@ -10,34 +9,34 @@ import GeoStats from './GeoStats';
import ClusterCard from './ClusterCard';
import GeoMap from './GeoMap';
// Client-side API fetcher (no Directus client needed)
async function fetchGeoData(collection: string) {
const res = await fetch(`/api/directus/${collection}`);
if (!res.ok) throw new Error('Failed to fetch');
return res.json();
}
export default function GeoIntelligenceManager() {
const queryClient = useQueryClient();
const client = getDirectusClient();
const [search, setSearch] = useState('');
const [showMap, setShowMap] = useState(true);
// 1. Fetch Data
// 1. Fetch Data via API (not Directus client)
const { data: clusters = [], isLoading: isLoadingClusters } = useQuery({
queryKey: ['geo_clusters'],
queryFn: async () => {
// @ts-ignore
return await client.request(readItems('geo_clusters', { limit: -1 }));
}
queryFn: () => fetchGeoData('geo_clusters')
});
const { data: locations = [], isLoading: isLoadingLocations } = useQuery({
queryKey: ['geo_locations'],
queryFn: async () => {
// @ts-ignore
return await client.request(readItems('geo_locations', { limit: -1 }));
}
queryFn: () => fetchGeoData('geo_locations')
});
// 2. Mutations
const deleteMutation = useMutation({
mutationFn: async (id: string) => {
// @ts-ignore
await client.request(deleteItem('geo_clusters', id));
const res = await fetch(`/api/directus/geo_clusters/${id}`, { method: 'DELETE' });
if (!res.ok) throw new Error('Delete failed');
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['geo_clusters'] });