Giter VIP home page Giter VIP logo

Comments (3)

ozgurozbek avatar ozgurozbek commented on July 17, 2024

Something alongside this

/**
   *
   * @param items Array of [label, iconName, pageComponent]
   * @returns
   */
  const getItems = (items: [string, string, JSX.Element][]) => {
    return items.map((item, index) => {
      return getItem(item[0], index, getIcon(item[1], collapsed), item[2]);
    });
  };

  const items = getItems([
    ["Common Lore", "CommonLore", <CommonLorePage />],
    ["Planes of Existence", "Locations", <LocationsPage />],
    ["Deities", "Deities", <DeitiesPage />],
    ["Races", "Races", <RacesPage />],
    ["Tables", "Tables", <TablesPage />],
    ["Library", "Library", <LibraryPage />],
    ["Pricing", "Pricing", <PricingPage />],
    ["Tools", "Tools", <ToolsPage />],
    ["Homebrews", "Homebrews", <HomebrewsPage />],
    ["Map Overlay", "MapOverlay", <MapOverlayPage />],
    ["Map Legend", "MapLegend", <MapLegendPage />],
  ]);```

from teothe.

ozgurozbek avatar ozgurozbek commented on July 17, 2024
import { useEffect, useState } from "react";
import { render } from "react-dom";
import { Menu, Image, Avatar } from "antd";
import Sider from "antd/es/layout/Sider";

import type { MenuProps } from "antd";

import CommonLorePage from "Pages/PageCommonLore";
import DeitiesPage from "Pages/PageDeities";
import TablesPage from "Pages/PageTables";
import LibraryPage from "Pages/PageLibrary";
import MapLegendPage from "Pages/PageMapLegend";
import MapOverlayPage from "Pages/PageMapOverlay";
import LocationsPage from "Pages/PageLocations";
import RacesPage from "Pages/PageRaces";
import HomebrewsPage from "Pages/PageHomebrews";
import PricingPage from "Pages/PageCommonPricing";
import ToolsPage from "Pages/PageTools";

type MenuItem = Required<MenuProps>["items"][number];

function loadPage(pageComponent: React.ReactElement) {
  render(pageComponent, document.getElementById("PageContent"));
}

function getIcon(pageName: string, avatarSize: boolean) {
  return (
    <Avatar
      size={avatarSize ? 16 : 24}
      src={"./Icons/SideNav/" + pageName + ".svg"}
      alt={pageName + " Icon"}
      draggable={false}
      shape="square"
    ></Avatar>
  );
}

function getItem(
  label: React.ReactNode,
  key?: React.Key | null,
  icon?: React.ReactNode,
  children?: any
): MenuItem {
  return {
    key,
    icon,
    children,
    label,
  } as MenuItem;
}

export default function Sidebar() {
  const [collapsed, setCollapsed] = useState(false);

  useEffect(() => {
    loadPage(<CommonLorePage />);
  }, []);

  /**
   *
   * @param items Array of [label, iconName, pageComponent]
   * @returns
   */
  const getItems = (items: [string, string, JSX.Element][]) => {
    return items.map((item, index) => {
      return getItem(item[0], index, getIcon(item[1], collapsed), item[2]);
    });
  };

  const items = getItems([
    ["Common Lore", "CommonLore", <CommonLorePage />],
    ["Planes of Existence", "Locations", <LocationsPage />],
    ["Deities", "Deities", <DeitiesPage />],
    ["Races", "Races", <RacesPage />],
    ["Tables", "Tables", <TablesPage />],
    ["Library", "Library", <LibraryPage />],
    ["Pricing", "Pricing", <PricingPage />],
    ["Tools", "Tools", <ToolsPage />],
    ["Homebrews", "Homebrews", <HomebrewsPage />],
    ["Map Overlay", "MapOverlay", <MapOverlayPage />],
    ["Map Legend", "MapLegend", <MapLegendPage />],
  ]);

  return (
    <Sider
      collapsible
      collapsed={collapsed}
      onCollapse={(value) => {
        setCollapsed(value);
      }}
    >
      <Image width="200px" height="83px" src="./teothe3K.png" alt="Teothe3K Icon" preview={false} />
      <Menu theme="dark" mode="inline" defaultSelectedKeys={["1"]}>
        {items.map((item: any) => {
          return (
            <Menu.Item
              key={item.key}
              icon={item.icon}
              onClick={() => {
                loadPage(item.children);
              }}
            >
              {item.label}
            </Menu.Item>
          );
        })}
      </Menu>
    </Sider>
  );
}

Fixed on an older branch, decided not to merge - this doesn't help with the initial rendering problem.

from teothe.

ozgurozbek avatar ozgurozbek commented on July 17, 2024

Removed the fixed property from SideNav and children.

from teothe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.