Add HistoryContext and integrate it into relevant components for improved job management
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useRef, useEffect } from 'react'
|
||||
import { useHistory } from '@/hooks/useHistory'
|
||||
import { useHistoryContext } from '@/contexts/HistoryContext'
|
||||
import { HistoryItem } from '@/components/HistoryItem'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import { Sheet, SheetContent } from '@/components/ui/sheet'
|
||||
@@ -15,7 +15,7 @@ interface HistorySidebarProps {
|
||||
}
|
||||
|
||||
function HistorySidebarContent({ onLoadParams }: Pick<HistorySidebarProps, 'onLoadParams'>) {
|
||||
const { jobs, loading, loadingMore, hasMore, loadMore, deleteJob, error, retry } = useHistory()
|
||||
const { jobs, loading, loadingMore, hasMore, loadMore, deleteJob, error, retry } = useHistoryContext()
|
||||
const observerTarget = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -99,7 +99,7 @@ function HistorySidebarContent({ onLoadParams }: Pick<HistorySidebarProps, 'onLo
|
||||
export function HistorySidebar({ open, onOpenChange, onLoadParams }: HistorySidebarProps) {
|
||||
return (
|
||||
<>
|
||||
<aside className="hidden lg:block w-[320px] border-r h-[calc(100vh-64px)]">
|
||||
<aside className="hidden lg:block w-[320px] border-r h-full">
|
||||
<HistorySidebarContent onLoadParams={onLoadParams} />
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { IconLabel } from '@/components/IconLabel'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { ttsApi, jobApi } from '@/lib/api'
|
||||
import { useJobPolling } from '@/hooks/useJobPolling'
|
||||
import { useHistoryContext } from '@/contexts/HistoryContext'
|
||||
import { LoadingState } from '@/components/LoadingState'
|
||||
import { AudioPlayer } from '@/components/AudioPlayer'
|
||||
import { PresetSelector } from '@/components/PresetSelector'
|
||||
@@ -53,6 +54,7 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
||||
})
|
||||
|
||||
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
|
||||
const { refresh } = useHistoryContext()
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -112,6 +114,9 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
||||
const result = await ttsApi.createCustomVoiceJob(data)
|
||||
toast.success('任务已创建')
|
||||
startPolling(result.job_id)
|
||||
try {
|
||||
await refresh()
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
toast.error('创建任务失败')
|
||||
} finally {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { IconLabel } from '@/components/IconLabel'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { ttsApi, jobApi } from '@/lib/api'
|
||||
import { useJobPolling } from '@/hooks/useJobPolling'
|
||||
import { useHistoryContext } from '@/contexts/HistoryContext'
|
||||
import { LoadingState } from '@/components/LoadingState'
|
||||
import { AudioPlayer } from '@/components/AudioPlayer'
|
||||
import { AudioInputSelector } from '@/components/AudioInputSelector'
|
||||
@@ -48,6 +49,7 @@ function VoiceCloneForm() {
|
||||
})
|
||||
|
||||
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
|
||||
const { refresh } = useHistoryContext()
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -93,6 +95,9 @@ function VoiceCloneForm() {
|
||||
})
|
||||
toast.success('任务已创建')
|
||||
startPolling(result.job_id)
|
||||
try {
|
||||
await refresh()
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
toast.error('创建任务失败')
|
||||
} finally {
|
||||
|
||||
@@ -14,6 +14,7 @@ import { IconLabel } from '@/components/IconLabel'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { ttsApi, jobApi } from '@/lib/api'
|
||||
import { useJobPolling } from '@/hooks/useJobPolling'
|
||||
import { useHistoryContext } from '@/contexts/HistoryContext'
|
||||
import { LoadingState } from '@/components/LoadingState'
|
||||
import { AudioPlayer } from '@/components/AudioPlayer'
|
||||
import { PresetSelector } from '@/components/PresetSelector'
|
||||
@@ -51,6 +52,7 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
|
||||
})
|
||||
|
||||
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
|
||||
const { refresh } = useHistoryContext()
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -103,6 +105,9 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
|
||||
const result = await ttsApi.createVoiceDesignJob(data)
|
||||
toast.success('任务已创建')
|
||||
startPolling(result.job_id)
|
||||
try {
|
||||
await refresh()
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
toast.error('创建任务失败')
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user