2021-06-21 16:11:53 -04:00
|
|
|
import styled from "styled-components";
|
|
|
|
import { Channel, User } from "revolt.js";
|
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
import Header from "../../components/ui/Header";
|
2021-06-23 09:52:33 -04:00
|
|
|
import HeaderActions from "./actions/HeaderActions";
|
2021-06-21 16:11:53 -04:00
|
|
|
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";
|
2021-06-27 06:17:59 -04:00
|
|
|
import { Save, At, Group, Hash } from "@styled-icons/boxicons-regular";
|
2021-06-21 16:11:53 -04:00
|
|
|
import { useStatusColour } from "../../components/common/user/UserIcon";
|
|
|
|
import { useIntermediate } from "../../context/intermediate/Intermediate";
|
|
|
|
|
2021-06-23 09:52:33 -04:00
|
|
|
export interface ChannelHeaderProps {
|
2021-06-21 16:11:53 -04:00
|
|
|
channel: Channel,
|
|
|
|
toggleSidebar?: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const Info = styled.div`
|
|
|
|
flex-grow: 1;
|
|
|
|
min-width: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
2021-07-02 04:38:43 -04:00
|
|
|
display: flex;
|
|
|
|
gap: 8px;
|
|
|
|
align-items: baseline;
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
* {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-06-23 09:52:33 -04:00
|
|
|
export default function ChannelHeader({ channel, toggleSidebar }: ChannelHeaderProps) {
|
2021-06-21 16:11:53 -04:00
|
|
|
const { openScreen } = useIntermediate();
|
|
|
|
const client = useContext(AppContext);
|
|
|
|
|
|
|
|
const name = getChannelName(client, channel);
|
|
|
|
let icon, recipient;
|
|
|
|
switch (channel.channel_type) {
|
|
|
|
case "SavedMessages":
|
2021-06-27 06:17:59 -04:00
|
|
|
icon = <Save size={20} />;
|
2021-06-21 16:11:53 -04:00
|
|
|
break;
|
|
|
|
case "DirectMessage":
|
2021-06-27 06:17:59 -04:00
|
|
|
icon = <At size={20} />;
|
2021-06-21 16:11:53 -04:00
|
|
|
const uid = client.channels.getRecipient(channel._id);
|
|
|
|
recipient = client.users.get(uid);
|
|
|
|
break;
|
|
|
|
case "Group":
|
2021-06-27 06:17:59 -04:00
|
|
|
icon = <Group size={20} />;
|
2021-06-21 16:11:53 -04:00
|
|
|
break;
|
|
|
|
case "TextChannel":
|
2021-06-27 06:17:59 -04:00
|
|
|
icon = <Hash size={20} />;
|
2021-06-21 16:11:53 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Header placement="primary">
|
|
|
|
{ icon }
|
|
|
|
<Info>
|
|
|
|
<span className="name">{ name }</span>
|
|
|
|
{channel.channel_type === "DirectMessage" && (
|
|
|
|
<>
|
|
|
|
<div className="divider" />
|
|
|
|
<span className="desc">
|
|
|
|
<div className="status" style={{ backgroundColor: useStatusColour(recipient as User) }} />
|
|
|
|
<UserStatus user={recipient as User} />
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{(channel.channel_type === "Group" || channel.channel_type === "TextChannel") && channel.description && (
|
|
|
|
<>
|
|
|
|
<div className="divider" />
|
|
|
|
<span
|
|
|
|
className="desc"
|
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "channel_info",
|
|
|
|
channel_id: channel._id
|
|
|
|
})
|
|
|
|
}>
|
|
|
|
<Markdown content={channel.description.split("\n")[0] ?? ""} disallowBigEmoji />
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Info>
|
2021-06-23 09:52:33 -04:00
|
|
|
<HeaderActions channel={channel} toggleSidebar={toggleSidebar} />
|
2021-06-21 16:11:53 -04:00
|
|
|
</Header>
|
|
|
|
)
|
|
|
|
}
|