Sidebar.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Link from "next/link";
  2. import Image from "next/image";
  3. import React, { useState, useEffect } from "react";
  4. import DrawerIcon from "../../public/icons/drawer.svg";
  5. import SettingsIcon from "../../public/icons/settings.svg";
  6. import BotIcon from "../../public/icons/bot.svg";
  7. import DropdownIcon from "../../public/icons/dropdown.svg";
  8. import TwitterIcon from "../../public/icons/twitter.svg";
  9. import GithubIcon from "../../public/icons/github.svg";
  10. import LinkedinIcon from "../../public/icons/linkedin.svg";
  11. export default function Sidebar() {
  12. const [bots, setBots] = useState([]);
  13. useEffect(() => {
  14. const fetchBots = async () => {
  15. const response = await fetch("/api/get_bots");
  16. const data = await response.json();
  17. setBots(data);
  18. };
  19. fetchBots();
  20. }, []);
  21. const toggleDropdown = () => {
  22. const dropdown = document.getElementById("dropdown-toggle");
  23. dropdown.classList.toggle("hidden");
  24. };
  25. return (
  26. <>
  27. {/* Mobile Toggle */}
  28. <button
  29. data-drawer-target="logo-sidebar"
  30. data-drawer-toggle="logo-sidebar"
  31. aria-controls="logo-sidebar"
  32. type="button"
  33. className="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg sm:hidden hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-gray-200"
  34. >
  35. <DrawerIcon className="w-6 h-6" />
  36. </button>
  37. {/* Sidebar */}
  38. <div
  39. id="logo-sidebar"
  40. className="fixed top-0 left-0 z-40 w-64 h-screen transition-transform -translate-x-full sm:translate-x-0"
  41. >
  42. <div className="flex flex-col h-full px-3 py-4 overflow-y-auto bg-gray-100">
  43. <div className="pb-10">
  44. <Link href="/" className="flex items-center justify-evenly mb-5">
  45. <Image
  46. src="/images/embedchain.png"
  47. alt="Embedchain Logo"
  48. width={45}
  49. height={0}
  50. className="block h-auto w-auto"
  51. />
  52. <span className="self-center text-2xl font-bold whitespace-nowrap">
  53. Embedchain
  54. </span>
  55. </Link>
  56. <ul className="space-y-2 font-medium text-lg">
  57. {/* Settings */}
  58. <li>
  59. <Link
  60. href="/"
  61. className="flex items-center p-2 text-gray-900 rounded-lg hover:bg-gray-200 group"
  62. >
  63. <SettingsIcon className="w-6 h-6 text-gray-600 transition duration-75 group-hover:text-gray-900" />
  64. <span className="ml-3">Settings</span>
  65. </Link>
  66. </li>
  67. {/* Bots */}
  68. {bots.length !== 0 && (
  69. <li>
  70. <button
  71. type="button"
  72. className="flex items-center w-full p-2 text-base text-gray-900 transition duration-75 rounded-lg group hover:bg-gray-200"
  73. onClick={toggleDropdown}
  74. >
  75. <BotIcon className="w-6 h-6 text-gray-600 transition duration-75 group-hover:text-gray-900" />
  76. <span className="flex-1 ml-3 text-left whitespace-nowrap">
  77. Bots
  78. </span>
  79. <DropdownIcon className="w-3 h-3" />
  80. </button>
  81. <ul
  82. id="dropdown-toggle"
  83. className="hidden text-sm py-2 space-y-2"
  84. >
  85. {bots.map((bot, index) => (
  86. <React.Fragment key={index}>
  87. <li>
  88. <Link
  89. href={`/${bot.slug}/app`}
  90. className="flex items-center w-full p-2 text-gray-900 transition duration-75 rounded-lg pl-11 group hover:bg-gray-200"
  91. >
  92. {bot.name}
  93. </Link>
  94. </li>
  95. </React.Fragment>
  96. ))}
  97. </ul>
  98. </li>
  99. )}
  100. </ul>
  101. </div>
  102. <div className="bg-gray-200 absolute bottom-0 left-0 right-0 h-20"></div>
  103. {/* Social Icons */}
  104. <div className="mt-auto mb-3 flex flex-row justify-evenly sticky bottom-3">
  105. <a href="https://twitter.com/embedchain" target="blank">
  106. <TwitterIcon className="w-6 h-6 text-gray-600 transition duration-75 hover:text-gray-900" />
  107. </a>
  108. <a href="https://github.com/embedchain/embedchain" target="blank">
  109. <GithubIcon className="w-6 h-6 text-gray-600 transition duration-75 hover:text-gray-900" />
  110. </a>
  111. <a
  112. href="https://www.linkedin.com/company/embedchain"
  113. target="blank"
  114. >
  115. <LinkedinIcon className="w-6 h-6 text-gray-600 transition duration-75 hover:text-gray-900" />
  116. </a>
  117. </div>
  118. </div>
  119. </div>
  120. </>
  121. );
  122. }