index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use client'
  2. import React, { useRef } from 'react'
  3. import { useRouter } from 'next/navigation'
  4. import { useHover } from 'ahooks'
  5. import s from './style.module.css'
  6. import cn from '@/utils/classnames'
  7. import ItemOperation from '@/app/components/explore/item-operation'
  8. import AppIcon from '@/app/components/base/app-icon'
  9. import type { AppIconType } from '@/types/app'
  10. export type IAppNavItemProps = {
  11. isMobile: boolean
  12. name: string
  13. id: string
  14. icon_type: AppIconType | null
  15. icon: string
  16. icon_background: string
  17. icon_url: string
  18. isSelected: boolean
  19. isPinned: boolean
  20. togglePin: () => void
  21. uninstallable: boolean
  22. onDelete: (id: string) => void
  23. }
  24. export default function AppNavItem({
  25. isMobile,
  26. name,
  27. id,
  28. icon_type,
  29. icon,
  30. icon_background,
  31. icon_url,
  32. isSelected,
  33. isPinned,
  34. togglePin,
  35. uninstallable,
  36. onDelete,
  37. }: IAppNavItemProps) {
  38. const router = useRouter()
  39. const url = `/explore/installed/${id}`
  40. const ref = useRef(null)
  41. const isHovering = useHover(ref)
  42. return (
  43. <div
  44. ref={ref}
  45. key={id}
  46. className={cn(
  47. s.item,
  48. isSelected ? s.active : 'hover:bg-gray-200',
  49. 'flex h-8 items-center justify-between mobile:justify-center px-2 mobile:px-1 rounded-lg text-sm font-normal',
  50. )}
  51. onClick={() => {
  52. router.push(url) // use Link causes popup item always trigger jump. Can not be solved by e.stopPropagation().
  53. }}
  54. >
  55. {isMobile && <AppIcon size='tiny' iconType={icon_type} icon={icon} background={icon_background} imageUrl={icon_url} />}
  56. {!isMobile && (
  57. <>
  58. <div className='flex items-center space-x-2 w-0 grow'>
  59. <AppIcon size='tiny' iconType={icon_type} icon={icon} background={icon_background} imageUrl={icon_url} />
  60. <div className='overflow-hidden text-ellipsis whitespace-nowrap' title={name}>{name}</div>
  61. </div>
  62. <div className='shrink-0 h-6' onClick={e => e.stopPropagation()}>
  63. <ItemOperation
  64. isPinned={isPinned}
  65. isItemHovering={isHovering}
  66. togglePin={togglePin}
  67. isShowDelete={!uninstallable && !isSelected}
  68. onDelete={() => onDelete(id)}
  69. />
  70. </div>
  71. </>
  72. )}
  73. </div>
  74. )
  75. }