Skip to content

Commit

Permalink
refactor(use-fetch-state): fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 1, 2025
1 parent d67929e commit 7a8a72e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/settings/settings-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SettingsChat = () => {
const badgeColor = isOnline ? 'green' : 'red'
const badgeText = isOnline ? 'Online' : 'Offline'

const { error: modelsError, models } = useListModels(chatProvider, [chatProvider])
const { models } = useListModels(chatProvider, [chatProvider])

return (
<>
Expand Down Expand Up @@ -86,7 +86,7 @@ export const SettingsChat = () => {
Chat Model
</Text>
{/* eslint-disable-next-line @masknet/jsx-no-logical */}
{modelsError
{models.length === 0
? (
<DebouncedTextField onBlurValueChange={setChatModel} value={chatModel} />
)
Expand All @@ -105,7 +105,7 @@ export const SettingsChat = () => {
Embed Model
</Text>
{/* eslint-disable-next-line @masknet/jsx-no-logical */}
{modelsError
{models.length === 0
? (
<DebouncedTextField onBlurValueChange={setEmbedModel} value={embedModel} />
)
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/xsai/_use-fetch-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import { useState } from 'react'
export const useFetchState = <T>(getData: (signal: AbortSignal) => Promise<T>, initialState: T, deps: DependencyList) => {
const [data, setData] = useState<T>(initialState)
const [error, setError] = useState<Error | undefined>()
const [isLoading, setIsLoading] = useState(true)
const [isLoading, setIsLoading] = useState(false)

useAbortableEffect((signal) => {
setIsLoading(true)
// eslint-disable-next-line @masknet/no-then
getData(signal)
.then((data) => {
if (!signal.aborted)
setData(data)
})
.catch((error: Error) => {
if (!signal.aborted)
// eslint-disable-next-line @masknet/prefer-early-return
if (!signal.aborted) {
setData(initialState)
setError(error)
}
})
.finally(() => {
if (!signal.aborted)
Expand Down

0 comments on commit 7a8a72e

Please sign in to comment.