72df234636
* refactor(frontend): optimize network queries and improve code readability
- useThreadStream: Add useStream with fetchStateHistory: {limit: 1}
- useThreads: Add select fields and disable refetchOnWindowFocus
- useModels: Disable refetchOnWindowFocus
- ChatPage and titleOfThread: Improve thread title logic
- loadModels: Refactor code for better readability
* fix: address the review comments of Copilot
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
14 lines
376 B
TypeScript
14 lines
376 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { loadModels } from "./api";
|
|
|
|
export function useModels({ enabled = true }: { enabled?: boolean } = {}) {
|
|
const { data, isLoading, error } = useQuery({
|
|
queryKey: ["models"],
|
|
queryFn: () => loadModels(),
|
|
enabled,
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
return { models: data ?? [], isLoading, error };
|
|
}
|