wip: prepare endpoints

This commit is contained in:
Carlos Valente
2023-11-22 22:30:31 +01:00
parent f39c8b46bb
commit cdca5eaad3
8 changed files with 73 additions and 58 deletions
+8 -11
View File
@@ -110,13 +110,18 @@ export async function getOSC(): Promise<OSCSettings> {
* @return {Promise}
*/
export async function getHTTP(): Promise<HTTPSettings> {
console.log('getHTTP');
const res = await axios.get(`${ontimeURL}/http`);
console.log(res);
return res.data;
}
/**
* @description HTTP request to mutate http settings
* @return {Promise}
*/
export async function postHTTP(data: HTTPSettings) {
return axios.post(`${ontimeURL}/http`, data);
}
/**
* @description HTTP request to mutate osc settings
* @return {Promise}
@@ -133,14 +138,6 @@ export async function postOscSubscriptions(data: Subscription) {
return axios.post(`${ontimeURL}/osc-subscriptions`, data);
}
/**
* @description HTTP request to mutate osc subscriptions
* @return {Promise}
*/
export async function postHttpSubscriptions(data: Subscription) {
return axios.post(`${ontimeURL}/http-subscriptions`, data);
}
/**
* @description HTTP request to download db in CSV format
*/
@@ -4,11 +4,11 @@ import { HTTPSettings } from 'ontime-types';
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
import { HTTP_SETTINGS } from '../api/apiConstants';
import { logAxiosError } from '../api/apiUtils';
import { getHTTP, postHttpSubscriptions } from '../api/ontimeApi';
import { getHTTP, postHTTP } from '../api/ontimeApi';
import { httpPlaceholder } from '../models/Http';
import { ontimeQueryClient } from '../queryClient';
export default function useHttpSettings() {
export function useHttpSettings() {
const { data, status, isFetching, isError, refetch } = useQuery({
queryKey: HTTP_SETTINGS,
queryFn: getHTTP,
@@ -23,12 +23,11 @@ export default function useHttpSettings() {
return { data: data! as unknown as HTTPSettings, status, isFetching, isError, refetch };
}
export function usePostHttpSubscriptions() {
const { isLoading, mutateAsync } = useMutation({
mutationFn: postHttpSubscriptions,
export function usePostHttpSettings() {
const { isPending, mutateAsync } = useMutation({
mutationFn: postHTTP,
onError: (error) => logAxiosError('Error saving HTTP settings', error),
onSettled: () => ontimeQueryClient.invalidateQueries({ queryKey: HTTP_SETTINGS }),
});
return { isLoading, mutateAsync };
return { isPending, mutateAsync };
}