mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-23 00:54:22 +01:00
ui: refresh selected model (#2002)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import type { View } from '../../../App';
|
import type { View } from '../../../App';
|
||||||
import ModelSettingsButtons from './subcomponents/ModelSettingsButtons';
|
import ModelSettingsButtons from './subcomponents/ModelSettingsButtons';
|
||||||
import { useConfig } from '../../ConfigContext';
|
import { useConfig } from '../../ConfigContext';
|
||||||
@@ -15,17 +15,7 @@ export default function ModelsSection({ setView }: ModelsSectionProps) {
|
|||||||
const [model, setModel] = useState<string>('');
|
const [model, setModel] = useState<string>('');
|
||||||
const { read, getProviders } = useConfig();
|
const { read, getProviders } = useConfig();
|
||||||
|
|
||||||
// Use a ref to prevent multiple loads
|
// Function to load model data
|
||||||
const isLoadingRef = useRef(false);
|
|
||||||
const isLoadedRef = useRef(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// Prevent the effect from running again if it's already loading or loaded
|
|
||||||
if (isLoadingRef.current || isLoadedRef.current) return;
|
|
||||||
|
|
||||||
// Mark as loading
|
|
||||||
isLoadingRef.current = true;
|
|
||||||
|
|
||||||
const loadModelData = async () => {
|
const loadModelData = async () => {
|
||||||
try {
|
try {
|
||||||
const gooseModel = (await read('GOOSE_MODEL', false)) as string;
|
const gooseModel = (await read('GOOSE_MODEL', false)) as string;
|
||||||
@@ -47,27 +37,24 @@ export default function ModelsSection({ setView }: ModelsSectionProps) {
|
|||||||
setModel(gooseModel);
|
setModel(gooseModel);
|
||||||
setProvider(providerDisplayName);
|
setProvider(providerDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as loaded and not loading
|
|
||||||
isLoadedRef.current = true;
|
|
||||||
isLoadingRef.current = false;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading model data:', error);
|
console.error('Error loading model data:', error);
|
||||||
isLoadingRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Initial load
|
||||||
loadModelData();
|
loadModelData();
|
||||||
|
|
||||||
// Clean up function
|
// Set up polling interval to check for changes
|
||||||
return () => {
|
const interval = setInterval(() => {
|
||||||
isLoadingRef.current = false;
|
loadModelData();
|
||||||
isLoadedRef.current = false;
|
}, 1000); // Check every second
|
||||||
};
|
|
||||||
|
|
||||||
// Run this effect only once when the component mounts
|
// Clean up interval on unmount
|
||||||
// We're using refs to control the actual execution, so we don't need dependencies
|
return () => {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
clearInterval(interval);
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user