From 2489ec43fe348785bd562eb1dd69c4107135e3bb Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Sun, 4 Dec 2022 23:04:33 -0500 Subject: [PATCH] Sidebar tweaks --- .gitignore | 1 + src/Sidebar/ui/SidebarAccordion.tsx | 11 ++- src/Sidebar/ui/SidebarItem.tsx | 18 ++--- src/Sidebar/ui/SidebarRoot.tsx | 100 ++++++++++------------------ 4 files changed, 49 insertions(+), 81 deletions(-) diff --git a/.gitignore b/.gitignore index 3931325ad..b6311a1a2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ Netburner.txt .idea/ *.bundle.* index.html +tsdoc-metadata.json diff --git a/src/Sidebar/ui/SidebarAccordion.tsx b/src/Sidebar/ui/SidebarAccordion.tsx index 4e505caba..046739f29 100644 --- a/src/Sidebar/ui/SidebarAccordion.tsx +++ b/src/Sidebar/ui/SidebarAccordion.tsx @@ -17,7 +17,7 @@ interface IProps { clickPage: (page: Page) => void; flash: Page | null; items: (IItemProps | boolean)[]; - icon: React.ReactElement; + icon: React.ReactElement["type"]; sidebarOpen: boolean; classes: any; } @@ -44,10 +44,7 @@ function getClickFn(toWrap: (page: Page) => void, page: Page) { // This can't be usefully memoized, because props.items is a new array every time. export function SidebarAccordion(props: IProps): React.ReactElement { const [open, setOpen] = useState(true); - // Obnoxious, because we can't modify props at all. const li_classes = useMemo(() => ({ root: props.classes.listitem }), [props.classes.listitem]); - const icon = Object.assign({}, props.icon); - icon.props = Object.assign({ color: "primary" }, icon.props); // Explicitily useMemo() to save rerendering deep chunks of this tree. // memo() can't be (easily) used on components like , because the @@ -58,13 +55,15 @@ export function SidebarAccordion(props: IProps): React.ReactElement { () => ( setOpen((open) => !open)}> - + + + {props.key_}} /> {open ? : } ), - [li_classes, props.sidebarOpen, props.key_, open, props.icon.type], + [li_classes, props.sidebarOpen, props.key_, open, props.icon], )} {props.items.map((x) => { diff --git a/src/Sidebar/ui/SidebarItem.tsx b/src/Sidebar/ui/SidebarItem.tsx index 8ce637388..581cef0b9 100644 --- a/src/Sidebar/ui/SidebarItem.tsx +++ b/src/Sidebar/ui/SidebarItem.tsx @@ -10,7 +10,7 @@ import type { Page } from "../../ui/Router"; export interface ICreateProps { key_: Page; - icon: React.ReactElement; + icon: React.ReactElement["type"]; count?: number; active?: boolean; } @@ -23,15 +23,7 @@ export interface IProps extends ICreateProps { } export const SidebarItem = memo(function (props: IProps): React.ReactElement { - // Use icon as a template. (We can't modify props) - const icon: React.ReactElement = { - type: props.icon.type, - key: props.icon.key, - props: { - color: props.flash ? "error" : !props.active ? "secondary" : "primary", - ...props.icon.props, - }, - }; + const color = props.flash ? "error" : props.active ? "primary" : "secondary"; return ( 0 ? props.count : undefined} color="error"> - + + + - + ); diff --git a/src/Sidebar/ui/SidebarRoot.tsx b/src/Sidebar/ui/SidebarRoot.tsx index a5b30b926..f07fc448a 100644 --- a/src/Sidebar/ui/SidebarRoot.tsx +++ b/src/Sidebar/ui/SidebarRoot.tsx @@ -55,38 +55,9 @@ import { InvitationsSeen } from "../../Faction/ui/FactionsRoot"; import { hash } from "../../hash/hash"; import { Locations } from "../../Locations/Locations"; -// All icon instances need to be constant, so they have stable object identity. -// Otherwise, the memoization of all the higher-level components doesn't work. -const computerIcon = ; -const lastPageIcon = ; -const createIcon = ; -const storageIcon = ; -const bugReportIcon = ; -const equalizerIcon = ; -const contactsIcon = ; -const doubleArrowIcon = ; -const accountTreeIcon = ; -const peopleAltIcon = ; -const locationCityIcon = ; -const airplanemodeActiveIcon = ; -const workIcon = ; -const trendingUpIcon = ; -const formatBoldIcon = ; -const businessIcon = ; -const sportsMmaIcon = ; -const checkIcon = ; -const helpIcon = ; -const settingsIcon = ; -const developerBoardIcon = ; -const emojiEventsIcon = ; -const accountBoxIcon = ; -const publicIcon = ; -const liveHelpIcon = ; -const chevronLeftIcon = ; -const chevronRightIcon = ; - -// Use constant Dividers just for performance -const divider = ; +const RotatedDoubleArrowIcon = (props: { color: "primary" | "secondary" | "error" }) => ( + +); const openedMixin = (theme: Theme): CSSObject => ({ width: theme.spacing(31), @@ -295,6 +266,7 @@ export function SidebarRoot(props: IProps): React.ReactElement { return !old; }); const li_classes = useMemo(() => ({ root: classes.listitem }), [classes.listitem]); + const ChevronOpenClose = open ? ChevronLeftIcon : ChevronRightIcon; // Explicitily useMemo() to save rerendering deep chunks of this tree. // memo() can't be (easily) used on components like , because the @@ -304,7 +276,9 @@ export function SidebarRoot(props: IProps): React.ReactElement { {useMemo( () => ( - {!open ? chevronRightIcon : chevronLeftIcon} + + + @@ -316,88 +290,88 @@ export function SidebarRoot(props: IProps): React.ReactElement { ), [li_classes, open], )} - {divider} + - {divider} + - {divider} + - {divider} +