ready-to-install.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback, useState } from 'react'
  4. import { InstallStep } from '../../types'
  5. import Install from './steps/install'
  6. import Installed from './steps/installed'
  7. import type { Dependency, InstallStatusResponse, Plugin } from '../../types'
  8. type Props = {
  9. step: InstallStep
  10. onStepChange: (step: InstallStep) => void,
  11. onStartToInstall: () => void
  12. setIsInstalling: (isInstalling: boolean) => void
  13. allPlugins: Dependency[]
  14. onClose: () => void
  15. isFromMarketPlace?: boolean
  16. }
  17. const ReadyToInstall: FC<Props> = ({
  18. step,
  19. onStepChange,
  20. onStartToInstall,
  21. setIsInstalling,
  22. allPlugins,
  23. onClose,
  24. isFromMarketPlace,
  25. }) => {
  26. const [installedPlugins, setInstalledPlugins] = useState<Plugin[]>([])
  27. const [installStatus, setInstallStatus] = useState<InstallStatusResponse[]>([])
  28. const handleInstalled = useCallback((plugins: Plugin[], installStatus: InstallStatusResponse[]) => {
  29. setInstallStatus(installStatus)
  30. setInstalledPlugins(plugins)
  31. onStepChange(InstallStep.installed)
  32. setIsInstalling(false)
  33. }, [onStepChange, setIsInstalling])
  34. return (
  35. <>
  36. {step === InstallStep.readyToInstall && (
  37. <Install
  38. allPlugins={allPlugins}
  39. onCancel={onClose}
  40. onStartToInstall={onStartToInstall}
  41. onInstalled={handleInstalled}
  42. isFromMarketPlace={isFromMarketPlace}
  43. />
  44. )}
  45. {step === InstallStep.installed && (
  46. <Installed
  47. list={installedPlugins}
  48. installStatus={installStatus}
  49. onCancel={onClose}
  50. />
  51. )}
  52. </>
  53. )
  54. }
  55. export default React.memo(ReadyToInstall)