import classNames from 'classnames'; import styles from "./Item.module.scss"; import Tooltip from '../../common/Tooltip'; import IconButton from '../../ui/IconButton'; import { Localizer, Text } from "preact-i18n"; import { X, Crown } from "@styled-icons/boxicons-regular"; import { Children } from "../../../types/Preact"; import UserIcon from '../../common/user/UserIcon'; import ChannelIcon from '../../common/ChannelIcon'; import UserStatus from '../../common/user/UserStatus'; import { attachContextMenu } from 'preact-context-menu'; import { Channels, Users } from "revolt.js/dist/api/objects"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { useIntermediate } from '../../../context/intermediate/Intermediate'; import { stopPropagation } from '../../../lib/stopPropagation'; type CommonProps = Omit, 'children' | 'as'> & { active?: boolean alert?: 'unread' | 'mention' alertCount?: number } type UserProps = CommonProps & { user: Users.User, context?: Channels.Channel, channel?: Channels.DirectMessageChannel } export function UserButton(props: UserProps) { const { active, alert, alertCount, user, context, channel, ...divProps } = props; const { openScreen } = useIntermediate(); return (
{user.username}
{
{ channel?.last_message && alert ? ( channel.last_message.short ) : ( ) }
}
{ context?.channel_type === "Group" && context.owner === user._id && ( } > )} {alert &&
{ alertCount }
} { !isTouchscreenDevice && channel && stopPropagation(e) && openScreen({ id: 'special_prompt', type: 'close_dm', target: channel })}> }
) } type ChannelProps = CommonProps & { channel: Channels.Channel & { unread?: string }, user?: Users.User compact?: boolean } export function ChannelButton(props: ChannelProps) { const { active, alert, alertCount, channel, user, compact, ...divProps } = props; if (channel.channel_type === 'SavedMessages') throw "Invalid channel type."; if (channel.channel_type === 'DirectMessage') { if (typeof user === 'undefined') throw "No user provided."; return } const { openScreen } = useIntermediate(); return (
{channel.name}
{ channel.channel_type === 'Group' &&
{(channel.last_message && alert) ? ( channel.last_message.short ) : ( )}
}
{alert &&
{ alertCount }
} {!isTouchscreenDevice && channel.channel_type === "Group" && ( openScreen({ id: 'special_prompt', type: 'leave_group', target: channel })}> )}
) } type ButtonProps = CommonProps & { onClick?: () => void children?: Children className?: string compact?: boolean } export default function ButtonItem(props: ButtonProps) { const { active, alert, alertCount, onClick, className, children, compact, ...divProps } = props; return (
{ children }
{alert &&
{ alertCount }
}
) }