2022-08-30 21:30:06 +02:00
|
|
|
import { memo } from 'react'
|
2022-08-28 18:26:56 +02:00
|
|
|
import classNames from 'clsx'
|
2022-01-01 20:42:25 +01:00
|
|
|
import Link from 'next/link'
|
2022-04-07 16:54:05 +02:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { CogIcon } from '@heroicons/react/solid'
|
2022-01-01 20:42:25 +01:00
|
|
|
|
2022-08-31 21:44:33 +02:00
|
|
|
import type { GuildsChannelsPath } from '../Application'
|
|
|
|
import type { Channel as ChannelType } from '../../../models/Channel'
|
2022-08-23 21:51:20 +02:00
|
|
|
import { useGuildMember } from '../../../contexts/GuildMember'
|
|
|
|
import { IconButton } from '../../design/IconButton'
|
2022-01-01 20:42:25 +01:00
|
|
|
|
|
|
|
export interface ChannelProps {
|
|
|
|
path: GuildsChannelsPath
|
|
|
|
channel: ChannelType
|
|
|
|
selected?: boolean
|
|
|
|
}
|
|
|
|
|
2022-08-30 21:30:06 +02:00
|
|
|
const ChannelMemo: React.FC<ChannelProps> = (props) => {
|
2022-01-01 20:42:25 +01:00
|
|
|
const { channel, path, selected = false } = props
|
2022-04-07 16:54:05 +02:00
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const { member } = useGuildMember()
|
2022-01-01 20:42:25 +01:00
|
|
|
|
|
|
|
return (
|
2022-12-13 11:38:07 +01:00
|
|
|
<Link
|
|
|
|
href={`/application/${path.guildId}/${channel.id}`}
|
|
|
|
className={classNames(
|
2023-04-03 00:11:19 +02:00
|
|
|
'group relative mx-3 my-3 flex items-center justify-between overflow-hidden rounded-lg py-2 text-sm transition-all duration-200 hover:bg-gray-100 dark:hover:bg-gray-600',
|
2022-12-13 11:38:07 +01:00
|
|
|
{
|
|
|
|
'font-semibold text-green-800 dark:text-green-400': selected
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<span className='max-[315px] ml-2 mr-4 break-all' data-cy='channel-name'>
|
|
|
|
# {channel.name}
|
|
|
|
</span>
|
|
|
|
{member.isOwner && (
|
|
|
|
<IconButton
|
|
|
|
onClick={async () => {
|
|
|
|
await router.push(
|
|
|
|
`/application/${channel.guildId}/${channel.id}/settings`
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
className='bg-unherit absolute -right-10 h-full w-8 transition-all group-hover:right-0 group-hover:shadow-lg dark:group-hover:bg-gray-600'
|
|
|
|
title='Settings'
|
2022-04-07 16:54:05 +02:00
|
|
|
>
|
2022-12-13 11:38:07 +01:00
|
|
|
<CogIcon height={20} width={20} />
|
|
|
|
</IconButton>
|
|
|
|
)}
|
2022-01-01 20:42:25 +01:00
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
2022-08-30 21:30:06 +02:00
|
|
|
|
|
|
|
export const Channel = memo(ChannelMemo)
|