use-check-installed.tsx 814 B

12345678910111213141516171819202122232425262728293031323334
  1. import { useCheckInstalled as useDoCheckInstalled } from '@/service/use-plugins'
  2. import { useMemo } from 'react'
  3. import type { VersionInfo } from '../../types'
  4. type Props = {
  5. pluginIds: string[],
  6. enabled: boolean
  7. }
  8. const useCheckInstalled = (props: Props) => {
  9. const { data, isLoading, error } = useDoCheckInstalled(props)
  10. const installedInfo = useMemo(() => {
  11. if (!data)
  12. return undefined
  13. const res: Record<string, VersionInfo> = {}
  14. data?.plugins.forEach((plugin) => {
  15. res[plugin.plugin_id] = {
  16. installedId: plugin.id,
  17. installedVersion: plugin.declaration.version,
  18. uniqueIdentifier: plugin.plugin_unique_identifier,
  19. }
  20. })
  21. return res
  22. }, [data])
  23. return {
  24. installedInfo,
  25. isLoading,
  26. error,
  27. }
  28. }
  29. export default useCheckInstalled