|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import React, { type FC, useEffect, useRef, useState } from 'react'
|
|
|
|
|
import React, { type FC, useRef, useState } from 'react'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import { RiLoader2Line } from '@remixicon/react'
|
|
|
|
|
import { useCountDown } from 'ahooks'
|
|
|
|
|
import Modal from '@/app/components/base/modal'
|
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
|
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
|
|
|
|
@ -18,15 +19,15 @@ const DefaultContent: FC<IDefaultContentProps> = React.memo(({
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className='p-6 pb-4'>
|
|
|
|
|
<span className='text-text-primary title-2xl-semi-bold'>{t('datasetDocuments.segment.regenerationConfirm')}</span>
|
|
|
|
|
<p className='text-text-secondary system-md-regular'>{t('datasetDocuments.segment.regenerationWarning')}</p>
|
|
|
|
|
<div className='pb-4'>
|
|
|
|
|
<span className='text-text-primary title-2xl-semi-bold'>{t('datasetDocuments.segment.regenerationConfirmTitle')}</span>
|
|
|
|
|
<p className='text-text-secondary system-md-regular'>{t('datasetDocuments.segment.regenerationConfirmMessage')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='flex justify-end gap-x-2 p-6'>
|
|
|
|
|
<div className='flex justify-end gap-x-2 pt-6'>
|
|
|
|
|
<Button onClick={onCancel}>
|
|
|
|
|
{t('common.operation.cancel')}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button destructive onClick={onConfirm}>
|
|
|
|
|
<Button variant='warning' destructive onClick={onConfirm}>
|
|
|
|
|
{t('common.operation.regenerate')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
@ -34,18 +35,20 @@ const DefaultContent: FC<IDefaultContentProps> = React.memo(({
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
DefaultContent.displayName = 'DefaultContent'
|
|
|
|
|
|
|
|
|
|
const RegeneratingContent: FC = React.memo(() => {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className='p-6 pb-4'>
|
|
|
|
|
<div className='pb-4'>
|
|
|
|
|
<span className='text-text-primary title-2xl-semi-bold'>{t('datasetDocuments.segment.regeneratingTitle')}</span>
|
|
|
|
|
<p className='text-text-secondary system-md-regular'>{t('datasetDocuments.segment.regeneratingMessage')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='flex justify-end p-6'>
|
|
|
|
|
<Button destructive disabled className='inline-flex items-center gap-x-0.5'>
|
|
|
|
|
<RiLoader2Line className='w-4 h-4 text-components-button-destructive-primary-text-disabled' />
|
|
|
|
|
<div className='flex justify-end pt-6'>
|
|
|
|
|
<Button variant='warning' destructive disabled className='inline-flex items-center gap-x-0.5'>
|
|
|
|
|
<RiLoader2Line className='w-4 h-4 text-components-button-destructive-primary-text-disabled animate-spin' />
|
|
|
|
|
<span>{t('common.operation.regenerate')}</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
@ -53,6 +56,8 @@ const RegeneratingContent: FC = React.memo(() => {
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
RegeneratingContent.displayName = 'RegeneratingContent'
|
|
|
|
|
|
|
|
|
|
type IRegenerationCompletedContentProps = {
|
|
|
|
|
onClose: () => void
|
|
|
|
|
}
|
|
|
|
|
@ -61,67 +66,64 @@ const RegenerationCompletedContent: FC<IRegenerationCompletedContentProps> = Rea
|
|
|
|
|
onClose,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const [countDown, setCountDown] = useState(5)
|
|
|
|
|
const timerRef = useRef<any>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
timerRef.current = setInterval(() => {
|
|
|
|
|
if (countDown > 0)
|
|
|
|
|
setCountDown(countDown - 1)
|
|
|
|
|
else
|
|
|
|
|
clearInterval(timerRef.current)
|
|
|
|
|
}, 1000)
|
|
|
|
|
return () => {
|
|
|
|
|
clearInterval(timerRef.current)
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
|
|
|
|
const targetTime = useRef(Date.now() + 5000)
|
|
|
|
|
const [countdown] = useCountDown({
|
|
|
|
|
targetDate: targetTime.current,
|
|
|
|
|
onEnd: () => {
|
|
|
|
|
onClose()
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className='p-6 pb-4'>
|
|
|
|
|
<div className='pb-4'>
|
|
|
|
|
<span className='text-text-primary title-2xl-semi-bold'>{t('datasetDocuments.segment.regenerationSuccessTitle')}</span>
|
|
|
|
|
<p className='text-text-secondary system-md-regular'>{t('datasetDocuments.segment.regenerationSuccessMessage')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='flex justify-end p-6'>
|
|
|
|
|
<div className='flex justify-end pt-6'>
|
|
|
|
|
<Button variant='primary' onClick={onClose}>
|
|
|
|
|
{`${t('common.operation.close')}(${countDown})`}
|
|
|
|
|
{`${t('common.operation.close')}${countdown === 0 ? '' : `(${Math.round(countdown / 1000)})`}`}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
RegenerationCompletedContent.displayName = 'RegenerationCompletedContent'
|
|
|
|
|
|
|
|
|
|
type IRegenerationModalProps = {
|
|
|
|
|
isShow: boolean
|
|
|
|
|
onConfirm: () => void
|
|
|
|
|
onCancel: () => void
|
|
|
|
|
onClose: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RegenerationModal: FC<IRegenerationModalProps> = ({
|
|
|
|
|
isShow,
|
|
|
|
|
onConfirm,
|
|
|
|
|
onCancel,
|
|
|
|
|
onClose,
|
|
|
|
|
}) => {
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
const [updateSuccess, setUpdateSuccess] = useState(false)
|
|
|
|
|
const [updateSucceeded, setUpdateSucceeded] = useState(false)
|
|
|
|
|
const { eventEmitter } = useEventEmitterContextContext()
|
|
|
|
|
|
|
|
|
|
eventEmitter?.useSubscription((v) => {
|
|
|
|
|
if (v === 'update-segment') {
|
|
|
|
|
setLoading(true)
|
|
|
|
|
setUpdateSuccess(false)
|
|
|
|
|
setUpdateSucceeded(false)
|
|
|
|
|
}
|
|
|
|
|
if (v === 'update-segment-success')
|
|
|
|
|
setUpdateSuccess(true)
|
|
|
|
|
setUpdateSucceeded(true)
|
|
|
|
|
if (v === 'update-segment-done')
|
|
|
|
|
setLoading(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal isShow={isShow} onClose={() => {}} className='!max-w-[480px] !rounded-2xl'>
|
|
|
|
|
{(!loading && !updateSuccess) && <DefaultContent onCancel={onCancel} onConfirm={onConfirm} />}
|
|
|
|
|
{(loading && !updateSuccess) && <RegeneratingContent />}
|
|
|
|
|
{!loading && updateSuccess && <RegenerationCompletedContent onClose={onCancel} />}
|
|
|
|
|
{!loading && !updateSucceeded && <DefaultContent onCancel={onCancel} onConfirm={onConfirm} />}
|
|
|
|
|
{loading && !updateSucceeded && <RegeneratingContent />}
|
|
|
|
|
{!loading && updateSucceeded && <RegenerationCompletedContent onClose={onClose} />}
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|