import { Home, UserDetail, Wrench, Notepad, } from "@styled-icons/boxicons-solid"; import { Link, Redirect, useLocation, useParams } from "react-router-dom"; import { Channels } from "revolt.js/dist/api/objects"; import { Users as UsersNS } from "revolt.js/dist/api/objects"; import { Text } from "preact-i18n"; import { useContext, useEffect } from "preact/hooks"; import ConditionalLink from "../../../lib/ConditionalLink"; import PaintCounter from "../../../lib/PaintCounter"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { dispatch } from "../../../redux"; import { connectState } from "../../../redux/connector"; import { Unreads } from "../../../redux/reducers/unreads"; import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { AppContext } from "../../../context/revoltjs/RevoltClient"; import { useDMs, useForceUpdate, useUsers, } from "../../../context/revoltjs/hooks"; import Category from "../../ui/Category"; import placeholderSVG from "../items/placeholder.svg"; import { mapChannelWithUnread, useUnreads } from "./common"; import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase"; import ButtonItem, { ChannelButton } from "../items/ButtonItem"; import ConnectionStatus from "../items/ConnectionStatus"; type Props = { unreads: Unreads; }; function HomeSidebar(props: Props) { const { pathname } = useLocation(); const client = useContext(AppContext); const { channel } = useParams<{ channel: string }>(); const { openScreen } = useIntermediate(); const ctx = useForceUpdate(); const channels = useDMs(ctx); const obj = channels.find((x) => x?._id === channel); if (channel && !obj) return ; if (obj) useUnreads({ ...props, channel: obj }); useEffect(() => { if (!channel) return; dispatch({ type: "LAST_OPENED_SET", parent: "home", child: channel, }); }, [channel]); const channelsArr = channels .filter((x) => x.channel_type !== "SavedMessages") .map((x) => mapChannelWithUnread(x, props.unreads)); const users = useUsers(undefined, ctx); channelsArr.sort((b, a) => a.timestamp.localeCompare(b.timestamp)); return ( {!isTouchscreenDevice && ( <> user?.relationship === UsersNS.Relationship.Incoming, ) !== "undefined" ? "unread" : undefined }> )} {import.meta.env.DEV && ( )} } action={() => openScreen({ id: "special_input", type: "create_group", }) } /> {channelsArr.length === 0 && ( )} {channelsArr.map((x) => { let user; if (x.channel_type === "DirectMessage") { if (!x.active) return null; const recipient = client.channels.getRecipient(x._id); user = users.find((x) => x?._id === recipient); if (!user) { console.warn( `Skipped DM ${x._id} because user was missing.`, ); return null; } } return ( ); })} ); } export default connectState( HomeSidebar, (state) => { return { unreads: state.unreads, }; }, true, );