- Configure to a hub in AirDC++ and then select a default hub here. -
diff --git a/src/client/components/Settings/AirDCPPSettings/AirDCPPHubsForm.tsx b/src/client/components/Settings/AirDCPPSettings/AirDCPPHubsForm.tsx index 21e61d6..8da4166 100644 --- a/src/client/components/Settings/AirDCPPSettings/AirDCPPHubsForm.tsx +++ b/src/client/components/Settings/AirDCPPSettings/AirDCPPHubsForm.tsx @@ -1,9 +1,10 @@ -import React, { ReactElement, useEffect, useState, useContext } from "react"; +import React, { ReactElement, useState } from "react"; import { Form, Field } from "react-final-form"; import { isEmpty, isNil, isUndefined } from "lodash"; import Select from "react-select"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import axios from "axios"; +import { produce } from "immer"; import { AIRDCPP_SERVICE_BASE_URI } from "../../../constants/endpoints"; export const AirDCPPHubsForm = (): ReactElement => { @@ -13,6 +14,7 @@ export const AirDCPPHubsForm = (): ReactElement => { data: settings, isLoading, isError, + refetch, } = useQuery({ queryKey: ["settings"], queryFn: async () => @@ -20,11 +22,9 @@ export const AirDCPPHubsForm = (): ReactElement => { url: "http://localhost:3000/api/settings/getAllSettings", method: "GET", }), + staleTime: Infinity, }); - /** - * Get the hubs list from an AirDCPP Socket - */ const { data: hubs } = useQuery({ queryKey: ["hubs"], queryFn: async () => @@ -37,14 +37,16 @@ export const AirDCPPHubsForm = (): ReactElement => { }), enabled: !isEmpty(settings?.data.directConnect?.client?.host), }); - let hubList = {}; + + let hubList: any[] = []; if (!isNil(hubs)) { hubList = hubs?.data.map(({ hub_url, identity }) => ({ value: hub_url, label: identity.name, })); } - const { mutate } = useMutation({ + + const mutation = useMutation({ mutationFn: async (values) => await axios({ url: `http://localhost:3000/api/settings/saveSettings`, @@ -55,21 +57,43 @@ export const AirDCPPHubsForm = (): ReactElement => { settingsKey: "directConnect", }, }), - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["settings"] }); + onSuccess: (data) => { + queryClient.setQueryData(["settings"], (oldData: any) => + produce(oldData, (draft: any) => { + draft.data.directConnect.client = { + ...draft.data.directConnect.client, + ...data.data.directConnect.client, + }; + }), + ); }, }); - const validate = async () => {}; + + const validate = async (values) => { + const errors = {}; + // Add any validation logic here if needed + return errors; + }; const SelectAdapter = ({ input, ...rest }) => { return ; }; + if (isLoading) { + return