url-input.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. const I18N_PREFIX = 'datasetCreation.stepOne.website'
  8. type Props = {
  9. isRunning: boolean
  10. onRun: (url: string) => void
  11. }
  12. const UrlInput: FC<Props> = ({
  13. isRunning,
  14. onRun,
  15. }) => {
  16. const { t } = useTranslation()
  17. const [url, setUrl] = useState('')
  18. const handleUrlChange = useCallback((url: string | number) => {
  19. setUrl(url as string)
  20. }, [])
  21. const handleOnRun = useCallback(() => {
  22. if (isRunning)
  23. return
  24. onRun(url)
  25. }, [isRunning, onRun, url])
  26. return (
  27. <div className='flex items-center justify-between'>
  28. <Input
  29. value={url}
  30. onChange={handleUrlChange}
  31. placeholder='https://docs.dify.ai'
  32. />
  33. <Button
  34. variant='primary'
  35. onClick={handleOnRun}
  36. className='ml-2'
  37. loading={isRunning}
  38. >
  39. {!isRunning ? t(`${I18N_PREFIX}.run`) : ''}
  40. </Button>
  41. </div>
  42. )
  43. }
  44. export default React.memo(UrlInput)