Browse Source

Fix: use debounce for switch (#3585)

tags/0.6.4
KVOJJJin 1 year ago
parent
commit
8cc1944160
No account linked to committer's email address
1 changed files with 11 additions and 2 deletions
  1. 11
    2
      web/app/components/datasets/documents/list.tsx

+ 11
- 2
web/app/components/datasets/documents/list.tsx View File

@@ -2,6 +2,7 @@
'use client'
import type { FC, SVGProps } from 'react'
import React, { useEffect, useState } from 'react'
import { useDebounceFn } from 'ahooks'
import { ArrowDownIcon, TrashIcon } from '@heroicons/react/24/outline'
import { ExclamationCircleIcon } from '@heroicons/react/24/solid'
import dayjs from 'dayjs'
@@ -154,6 +155,14 @@ export const OperationAction: FC<{
onUpdate(operationName)
}

const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
if (operationName === 'enable' && enabled)
return
if (operationName === 'disable' && !enabled)
return
onOperate(operationName)
}, { wait: 500 })

return <div className='flex items-center' onClick={e => e.stopPropagation()}>
{isListScene && !embeddingAvailable && (
<Switch defaultValue={false} onChange={() => { }} disabled={true} size='md' />
@@ -166,7 +175,7 @@ export const OperationAction: FC<{
<Switch defaultValue={false} onChange={() => { }} disabled={true} size='md' />
</div>
</Tooltip>
: <Switch defaultValue={enabled} onChange={v => onOperate(v ? 'enable' : 'disable')} size='md' />
: <Switch defaultValue={enabled} onChange={v => handleSwitch(v ? 'enable' : 'disable')} size='md' />
}
<Divider className='!ml-4 !mr-2 !h-3' type='vertical' />
</>
@@ -189,7 +198,7 @@ export const OperationAction: FC<{
<div>
<Switch
defaultValue={archived ? false : enabled}
onChange={v => !archived && onOperate(v ? 'enable' : 'disable')}
onChange={v => !archived && handleSwitch(v ? 'enable' : 'disable')}
disabled={archived}
size='md'
/>

Loading…
Cancel
Save