Refactor: replace endpointsConfig recoil store with react query (#1085)

This commit is contained in:
Danny Avila 2023-10-21 13:50:29 -04:00 committed by GitHub
parent 7d6a1d260f
commit 4073b7d05d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 83 additions and 49 deletions

View file

@ -3,7 +3,6 @@ import { useEffect, useState } from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { Outlet } from 'react-router-dom';
import {
useGetEndpointsQuery,
useGetModelsQuery,
useGetPresetsQuery,
useGetSearchEnabledQuery,
@ -26,10 +25,8 @@ export default function Root() {
const setPresets = useSetRecoilState(store.presets);
const setIsSearchEnabled = useSetRecoilState(store.isSearchEnabled);
const setEndpointsConfig = useSetRecoilState(store.endpointsConfig);
const setModelsConfig = useSetRecoilState(store.modelsConfig);
const endpointsQuery = useGetEndpointsQuery();
const searchEnabledQuery = useGetSearchEnabledQuery({ enabled: isAuthenticated });
const modelsQuery = useGetModelsQuery({ enabled: isAuthenticated });
const presetsQuery = useGetPresetsQuery({ enabled: !!user });
@ -38,14 +35,6 @@ export default function Root() {
localStorage.setItem('navVisible', JSON.stringify(navVisible));
}, [navVisible]);
useEffect(() => {
if (endpointsQuery.data) {
setEndpointsConfig(endpointsQuery.data);
} else if (endpointsQuery.isError) {
console.error('Failed to get endpoints', endpointsQuery.error);
}
}, [endpointsQuery.data, endpointsQuery.isError]);
useEffect(() => {
if (modelsQuery.data) {
setModelsConfig(modelsQuery.data);