您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

url-input.tsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import Input from './input'
  6. import Button from '@/app/components/base/button'
  7. import { useDocLink } from '@/context/i18n'
  8. const I18N_PREFIX = 'datasetCreation.stepOne.website'
  9. type Props = {
  10. isRunning: boolean
  11. onRun: (url: string) => void
  12. }
  13. const UrlInput: FC<Props> = ({
  14. isRunning,
  15. onRun,
  16. }) => {
  17. const { t } = useTranslation()
  18. const docLink = useDocLink()
  19. const [url, setUrl] = useState('')
  20. const handleUrlChange = useCallback((url: string | number) => {
  21. setUrl(url as string)
  22. }, [])
  23. const handleOnRun = useCallback(() => {
  24. if (isRunning)
  25. return
  26. onRun(url)
  27. }, [isRunning, onRun, url])
  28. return (
  29. <div className='flex items-center justify-between'>
  30. <Input
  31. value={url}
  32. onChange={handleUrlChange}
  33. placeholder={docLink()}
  34. />
  35. <Button
  36. variant='primary'
  37. onClick={handleOnRun}
  38. className='ml-2'
  39. loading={isRunning}
  40. >
  41. {!isRunning ? t(`${I18N_PREFIX}.run`) : ''}
  42. </Button>
  43. </div>
  44. )
  45. }
  46. export default React.memo(UrlInput)