From e4786e723038e5f2ed4a500fb034504737c4b201 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 27 Jun 2021 00:14:58 +0100 Subject: [PATCH] Render server categories. --- package.json | 2 +- .../navigation/left/ServerSidebar.tsx | 59 ++++++++++++------- yarn.lock | 8 +-- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 3c711314..6878f1e8 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "react-scroll": "^1.8.2", "react-tippy": "^1.4.0", "redux": "^4.1.0", - "revolt.js": "4.3.3-alpha.1", + "revolt.js": "4.3.3-alpha.2", "rimraf": "^3.0.2", "sass": "^1.35.1", "shade-blend-color": "^1.0.0", diff --git a/src/components/navigation/left/ServerSidebar.tsx b/src/components/navigation/left/ServerSidebar.tsx index d987af1e..2b8bcb77 100644 --- a/src/components/navigation/left/ServerSidebar.tsx +++ b/src/components/navigation/left/ServerSidebar.tsx @@ -1,14 +1,10 @@ -import { Link } from "react-router-dom"; -import { Settings } from "@styled-icons/feather"; import { Redirect, useParams } from "react-router"; import { ChannelButton } from "../items/ButtonItem"; import { Channels } from "revolt.js/dist/api/objects"; -import { ServerPermission } from "revolt.js/dist/api/permissions"; import { Unreads } from "../../../redux/reducers/unreads"; import { WithDispatcher } from "../../../redux/reducers"; -import { useChannels, useForceUpdate, useServer, useServerPermission } from "../../../context/revoltjs/hooks"; +import { useChannels, useForceUpdate, useServer } from "../../../context/revoltjs/hooks"; import { mapChannelWithUnread, useUnreads } from "./common"; -import Header from '../../ui/Header'; import ConnectionStatus from '../items/ConnectionStatus'; import { connectState } from "../../../redux/connector"; import PaintCounter from "../../../lib/PaintCounter"; @@ -16,6 +12,7 @@ import styled from "styled-components"; import { attachContextMenu } from 'preact-context-menu'; import ServerHeader from "../../common/ServerHeader"; import { useEffect } from "preact/hooks"; +import Category from "../../ui/Category"; import ConditionalLink from "../../../lib/ConditionalLink"; interface Props { @@ -66,26 +63,48 @@ function ServerSidebar(props: Props & WithDispatcher) { }); }, [ channel_id ]); + let uncategorised = new Set(server.channels); + let elements = []; + function addChannel(id: string) { + const entry = channels.find(x => x._id === id); + if (!entry) return; + + const active = channel?._id === entry._id; + + return ( + + + + ); + } + + if (server.categories) { + for (let category of server.categories) { + elements.push(); + + for (let id of category.channels) { + uncategorised.delete(id); + elements.push(addChannel(id)); + } + } + } + + for (let id of uncategorised) { + elements.unshift(addChannel(id)); + } + return ( - {channels.map(entry => { - const active = channel?._id === entry._id; - - return ( - - - - ); - })} + { elements } diff --git a/yarn.lock b/yarn.lock index 595a23ce..fbe2cb2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3412,10 +3412,10 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -revolt.js@4.3.3-alpha.1: - version "4.3.3-alpha.1" - resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.1.tgz#b60a18e5cbe9f2c569e7f46974450931826e10d4" - integrity sha512-MxjTOWqg83cLYdpuqLCl3nOTD+jFxSSjrnvczuijam1YjeZ3IB27C6G4Qar3BwMn7B+zH8MgEDecW3YBmKBpIw== +revolt.js@4.3.3-alpha.2: + version "4.3.3-alpha.2" + resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.2.tgz#1fb876205d74712c45e5f022624ac8d176ab01a1" + integrity sha512-/irTDDtBj63yQtpBk1asnqCNacc+HQXcz0jBOBk1VaOeDsjE6lTO2tGue6wFAG76AL89z9bziQbHIa6cQmWIjg== dependencies: "@insertish/mutable" "1.1.0" axios "^0.19.2"