import { Localizer, Text } from "preact-i18n";
import { useContext } from "preact/hooks";
import { Home, Users, Tool, Save } from "@styled-icons/feather";
import { Link, Redirect, useLocation, useParams } from "react-router-dom";
import { WithDispatcher } from "../../../redux/reducers";
import { Unreads } from "../../../redux/reducers/unreads";
import { connectState } from "../../../redux/connector";
import { AppContext } from "../../../context/revoltjs/RevoltClient";
import { useChannels, useForceUpdate, useUsers } from "../../../context/revoltjs/hooks";
import { Users as UsersNS } from 'revolt.js/dist/api/objects';
import { mapChannelWithUnread, useUnreads } from "./common";
import { Channels } from "revolt.js/dist/api/objects";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import ConnectionStatus from '../items/ConnectionStatus';
import ButtonItem, { ChannelButton } from '../items/ButtonItem';
import styled from "styled-components";
import UserHeader from "../../common/UserHeader";
import Category from '../../ui/Category';
import PaintCounter from "../../../lib/PaintCounter";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
type Props = WithDispatcher & {
unreads: Unreads;
}
const HomeBase = styled.div`
height: 100%;
width: 240px;
display: flex;
flex-shrink: 0;
flex-direction: column;
background: var(--secondary-background);
`;
const HomeList = styled.div`
padding: 6px;
flex-grow: 1;
overflow-y: scroll;
> svg {
width: 100%;
}
`;
function HomeSidebar(props: Props) {
const { pathname } = useLocation();
const client = useContext(AppContext);
const { channel } = useParams<{ channel: string }>();
const { openScreen, writeClipboard } = useIntermediate();
const ctx = useForceUpdate();
const users = useUsers(undefined, ctx);
const channels = useChannels(undefined, ctx);
const obj = channels.find(x => x?._id === channel);
if (channel && !obj) return ;
if (obj) useUnreads({ ...props, channel: obj });
const channelsArr = (channels
.filter(
x => x && (x.channel_type === "Group" || (x.channel_type === 'DirectMessage' && x.active))
) as (Channels.GroupChannel | Channels.DirectMessageChannel)[])
.map(x => mapChannelWithUnread(x, props.unreads));
channelsArr.sort((b, a) => a.timestamp.localeCompare(b.timestamp));
return (
{!isTouchscreenDevice && (
<>
user?.relationship ===
UsersNS.Relationship.Incoming
) !== "undefined" ? 'unread' : undefined
}
>
>
)}
{import.meta.env.DEV && (
)}
) as any
}
action={() => openScreen({ id: "special_input", type: "create_group" })}
/>
{channelsArr.length === 0 && }
{channelsArr.map(x => {
let user;
if (x.channel_type === 'DirectMessage') {
let recipient = client.channels.getRecipient(x._id);
user = users.find(x => x!._id === recipient);
}
return (
);
})}
);
};
export default connectState(
HomeSidebar,
state => {
return {
unreads: state.unreads
};
},
true,
true
);