Replace state blob with resource-oriented API endpoints
Split /api/v1/state into dedicated resource endpoints: - /api/v1/operator, /api/v1/central-domain - /api/v1/ddns/config, /api/v1/dns/settings - /api/v1/dhcp/config (moved from /dnsmasq/dhcp/) - /api/v1/nftables/config, /api/v1/haproxy/routes Each page now talks to its own resource instead of deep-merging a blob. Removes useConfig hook, CentralState type, and legacy config methods.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
export { useMessages } from './useMessages';
|
||||
export { useStatus } from './useStatus';
|
||||
export { useHealth } from './useHealth';
|
||||
export { useConfig } from './useConfig';
|
||||
export { useDnsmasq } from './useDnsmasq';
|
||||
export { useCentralStatus } from './useCentralStatus';
|
||||
export { useCloudflare } from './useCloudflare';
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { apiService } from '../services/api-legacy';
|
||||
import type { CentralState, CentralStateResponse } from '../types';
|
||||
|
||||
interface CreateConfigResponse {
|
||||
status: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for managing Wild Central runtime state
|
||||
* Endpoint: /api/v1/state
|
||||
* File: {dataDir}/state.yaml
|
||||
*/
|
||||
export const useConfig = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const [showConfigSetup, setShowConfigSetup] = useState(false);
|
||||
|
||||
const stateQuery = useQuery<CentralStateResponse>({
|
||||
queryKey: ['state'],
|
||||
queryFn: () => apiService.getConfig(),
|
||||
});
|
||||
|
||||
// Update showConfigSetup based on query data
|
||||
useEffect(() => {
|
||||
if (stateQuery.data) {
|
||||
setShowConfigSetup(stateQuery.data.configured === false);
|
||||
}
|
||||
}, [stateQuery.data]);
|
||||
|
||||
const createStateMutation = useMutation<CreateConfigResponse, Error, CentralState>({
|
||||
mutationFn: (state) => apiService.createConfig(state),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['state'] });
|
||||
setShowConfigSetup(false);
|
||||
},
|
||||
});
|
||||
|
||||
const updateStateMutation = useMutation<CreateConfigResponse, Error, CentralState>({
|
||||
mutationFn: (state) => apiService.updateConfig(state),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['state'] });
|
||||
// Immediately re-check daemon status so the pending-restart banner appears
|
||||
queryClient.invalidateQueries({ queryKey: ['central', 'status'] });
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
config: stateQuery.data?.state || null,
|
||||
isConfigured: stateQuery.data?.configured || false,
|
||||
showConfigSetup,
|
||||
setShowConfigSetup,
|
||||
isLoading: stateQuery.isLoading,
|
||||
isCreating: createStateMutation.isPending,
|
||||
isUpdating: updateStateMutation.isPending,
|
||||
error: stateQuery.error || createStateMutation.error || updateStateMutation.error,
|
||||
createConfig: createStateMutation.mutate,
|
||||
updateConfig: updateStateMutation.mutateAsync,
|
||||
refetch: stateQuery.refetch,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user