|
| 1 | +import React, { useState, useEffect } from "react"; |
| 2 | +import Link from "@docusaurus/Link"; |
| 3 | +import Heading from "@theme/Heading"; |
| 4 | +import toolsDataRaw from "@site/src/data/developerTools.json"; |
| 5 | + |
| 6 | +// Define the type for tool items |
| 7 | +type ToolItem = { |
| 8 | + name: string; |
| 9 | + link: string; |
| 10 | + subtext?: string; |
| 11 | +}; |
| 12 | + |
| 13 | +// Define the type for categories |
| 14 | +type ToolCategories = { |
| 15 | + [category: string]: ToolItem[]; |
| 16 | +}; |
| 17 | + |
| 18 | +// Define the type for network data |
| 19 | +type NetworkData = { |
| 20 | + name: string; |
| 21 | + categories: ToolCategories; |
| 22 | +}; |
| 23 | + |
| 24 | +// Define the type for network tools |
| 25 | +type NetworkTools = { |
| 26 | + [network: string]: NetworkData; |
| 27 | +}; |
| 28 | + |
| 29 | +// Define the type for the complete tools data |
| 30 | +type ToolsData = { |
| 31 | + toolDescriptions: { [key: string]: string }; |
| 32 | + networkTools: NetworkTools; |
| 33 | +}; |
| 34 | + |
| 35 | +const DeveloperTools = () => { |
| 36 | + const [activeNetwork, setActiveNetwork] = useState("flare"); |
| 37 | + const [isClient, setIsClient] = useState(false); |
| 38 | + |
| 39 | + // Parse the imported JSON file |
| 40 | + const toolsData = toolsDataRaw as ToolsData; |
| 41 | + const { toolDescriptions, networkTools } = toolsData; |
| 42 | + |
| 43 | + // Handle client-side only rendering and scroll to anchor if present |
| 44 | + useEffect(() => { |
| 45 | + setIsClient(true); |
| 46 | + |
| 47 | + // Handle anchor scrolling |
| 48 | + if (typeof window !== "undefined") { |
| 49 | + const hash = window.location.hash; |
| 50 | + if (hash) { |
| 51 | + // Remove the '#' character |
| 52 | + const id = hash.substring(1); |
| 53 | + setTimeout(() => { |
| 54 | + const element = document.getElementById(id); |
| 55 | + if (element) { |
| 56 | + element.scrollIntoView({ behavior: "smooth" }); |
| 57 | + } |
| 58 | + }, 100); |
| 59 | + } |
| 60 | + } |
| 61 | + }, []); |
| 62 | + |
| 63 | + if (!isClient || !networkTools[activeNetwork]) { |
| 64 | + return null; |
| 65 | + } |
| 66 | + |
| 67 | + const networkData = networkTools[activeNetwork]; |
| 68 | + |
| 69 | + return ( |
| 70 | + <div className="developer-tools-container"> |
| 71 | + <div className="developer-tools-header"> |
| 72 | + <p> |
| 73 | + Developer tools for Flare built by the community including RPCs, |
| 74 | + bridges, indexers, account abstraction, wallet SDKs, and more. |
| 75 | + </p> |
| 76 | + |
| 77 | + <div className="network-selector-container"> |
| 78 | + <div className="network-selector"> |
| 79 | + <label htmlFor="network-select">Network:</label> |
| 80 | + <select |
| 81 | + id="network-select" |
| 82 | + value={activeNetwork} |
| 83 | + onChange={(e) => setActiveNetwork(e.target.value)} |
| 84 | + className="network-select" |
| 85 | + aria-label="Select a network" |
| 86 | + > |
| 87 | + {Object.keys(networkTools).map((networkKey) => ( |
| 88 | + <option key={networkKey} value={networkKey}> |
| 89 | + {networkTools[networkKey].name} |
| 90 | + </option> |
| 91 | + ))} |
| 92 | + </select> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + |
| 97 | + <div className="tools-grid"> |
| 98 | + {Object.entries(networkData.categories).map(([category, tools]) => ( |
| 99 | + <div key={category} className="category-section"> |
| 100 | + <Heading |
| 101 | + as="h2" |
| 102 | + className="category-title" |
| 103 | + id={`${category.toLowerCase().replace(/\s+/g, "-")}`} |
| 104 | + > |
| 105 | + {category} |
| 106 | + </Heading> |
| 107 | + <div className="tools-cards"> |
| 108 | + {Array.isArray(tools) && tools.length === 0 ? ( |
| 109 | + <div className="empty-category"> |
| 110 | + No tools available in this category |
| 111 | + </div> |
| 112 | + ) : ( |
| 113 | + Array.isArray(tools) && |
| 114 | + tools.map((tool) => ( |
| 115 | + <Link |
| 116 | + key={tool.name} |
| 117 | + to={tool.link} |
| 118 | + target="_blank" |
| 119 | + rel="noopener noreferrer" |
| 120 | + className="tool-card" |
| 121 | + > |
| 122 | + <div className="tool-info"> |
| 123 | + <Heading as="h3" className="tool-name"> |
| 124 | + {tool.name} |
| 125 | + {tool.subtext && ( |
| 126 | + <span className="tool-subtext"> {tool.subtext}</span> |
| 127 | + )} |
| 128 | + </Heading> |
| 129 | + <p className="tool-description"> |
| 130 | + {toolDescriptions[tool.name] || |
| 131 | + "A tool for Flare ecosystem development."} |
| 132 | + </p> |
| 133 | + </div> |
| 134 | + <div className="tool-arrow" aria-hidden="true"> |
| 135 | + → |
| 136 | + </div> |
| 137 | + </Link> |
| 138 | + )) |
| 139 | + )} |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + ))} |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + ); |
| 146 | +}; |
| 147 | + |
| 148 | +export default DeveloperTools; |
0 commit comments