import styled from "styled-components";
import { Channel, User } from "revolt.js";
import { useContext } from "preact/hooks";
import { useHistory } from "react-router-dom";
import Header from "../../components/ui/Header";
import IconButton from "../../components/ui/IconButton";
import Markdown from "../../components/markdown/Markdown";
import { getChannelName } from "../../context/revoltjs/util";
import UserStatus from "../../components/common/user/UserStatus";
import { AppContext } from "../../context/revoltjs/RevoltClient";
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
import { useStatusColour } from "../../components/common/user/UserIcon";
import { useIntermediate } from "../../context/intermediate/Intermediate";
import { Save, AtSign, Users, Hash, UserPlus, Settings, Sidebar as SidebarIcon } from "@styled-icons/feather";
interface Props {
channel: Channel,
toggleSidebar?: () => void
}
const Info = styled.div`
flex-grow: 1;
min-width: 0;
overflow: hidden;
white-space: nowrap;
* {
display: inline-block;
}
.divider {
height: 14px;
margin: 0 5px;
padding-left: 1px;
background-color: var(--tertiary-background);
}
.status {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
margin-inline-end: 6px;
}
.desc {
cursor: pointer;
font-size: 0.8em;
font-weight: 400;
color: var(--secondary-foreground);
}
`;
export default function ChannelHeader({ channel, toggleSidebar }: Props) {
const { openScreen } = useIntermediate();
const client = useContext(AppContext);
const history = useHistory();
const name = getChannelName(client, channel);
let icon, recipient;
switch (channel.channel_type) {
case "SavedMessages":
icon = ;
break;
case "DirectMessage":
icon = ;
const uid = client.channels.getRecipient(channel._id);
recipient = client.users.get(uid);
break;
case "Group":
icon = ;
break;
case "TextChannel":
icon = ;
break;
}
return (
{ icon }
{ name }
{channel.channel_type === "DirectMessage" && (
<>
>
)}
{(channel.channel_type === "Group" || channel.channel_type === "TextChannel") && channel.description && (
<>
openScreen({
id: "channel_info",
channel_id: channel._id
})
}>
>
)}
<>
{ channel.channel_type === "Group" && (
<>
openScreen({
id: "user_picker",
omit: channel.recipients,
callback: async users => {
for (const user of users) {
await client.channels.addMember(channel._id, user);
}
}
})}>
history.push(`/channel/${channel._id}/settings`)}>
>
) }
{ channel.channel_type === "Group" && !isTouchscreenDevice && (
) }
>
)
}