index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import Link from 'next/link'
  4. import classNames from '@/utils/classnames'
  5. import { Group } from '@/app/components/base/icons/src/vender/other'
  6. import { useSelectedLayoutSegment } from 'next/navigation'
  7. import DownloadingIcon from './downloading-icon'
  8. import { usePluginTaskStatus } from '@/app/components/plugins/plugin-page/plugin-tasks/hooks'
  9. import Indicator from '@/app/components/header/indicator'
  10. type PluginsNavProps = {
  11. className?: string
  12. }
  13. const PluginsNav = ({
  14. className,
  15. }: PluginsNavProps) => {
  16. const { t } = useTranslation()
  17. const selectedSegment = useSelectedLayoutSegment()
  18. const activated = selectedSegment === 'plugins'
  19. const {
  20. isInstalling,
  21. isInstallingWithError,
  22. isFailed,
  23. } = usePluginTaskStatus()
  24. return (
  25. <Link href="/plugins" className={classNames(
  26. className, 'group', 'plugins-nav-button', // used for use-fold-anim-into.ts
  27. )}>
  28. <div
  29. className={classNames(
  30. 'relative flex flex-row h-8 p-1.5 gap-0.5 border border-transparent items-center justify-center rounded-xl system-sm-medium-uppercase',
  31. activated && 'border-components-main-nav-nav-button-border bg-components-main-nav-nav-button-bg-active shadow-md text-components-main-nav-nav-button-text',
  32. !activated && 'text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
  33. (isInstallingWithError || isFailed) && !activated && 'border-components-panel-border-subtle',
  34. )}
  35. >
  36. {
  37. (isFailed || isInstallingWithError) && !activated && (
  38. <Indicator
  39. color='red'
  40. className='absolute top-[-1px] left-[-1px]'
  41. />
  42. )
  43. }
  44. <div className='flex mr-0.5 w-5 h-5 justify-center items-center'>
  45. {
  46. (!(isInstalling || isInstallingWithError) || activated) && (
  47. <Group className='w-4 h-4' />
  48. )
  49. }
  50. {
  51. (isInstalling || isInstallingWithError) && !activated && (
  52. <DownloadingIcon />
  53. )
  54. }
  55. </div>
  56. <span className='px-0.5'>{t('common.menus.plugins')}</span>
  57. </div>
  58. </Link>
  59. )
  60. }
  61. export default PluginsNav