Skip to content

Commit

Permalink
fix(docs): fix bugs (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamgambhir97 authored Dec 20, 2024
1 parent 1f94e76 commit 5ae5f47
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
27 changes: 23 additions & 4 deletions components/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ export const OsDropDown: React.FC<OsDropDownProps> = ({
const handleOptionSelect = (option: string) => {
onOptionSelect(option);
setIsOpen(false);
if (typeof window !== "undefined") {
localStorage.setItem("storedOsOption", JSON.stringify(option));
}
};

const selectedOptionData = options.find((opt) => opt.name === selectedOption);

return (
<div className="os-dropdown">
<div
Expand Down Expand Up @@ -158,9 +160,9 @@ export const Dropdown: React.FC<DropdownProps> = ({
<span className="dropdown-text dark:nx-text-white-80">
{selectedOption || placeholder}
</span>
<DropDownArrow />
{options?.length > 1 && <DropDownArrow />}
</div>
{isDropdownOpen && (
{options?.length > 1 && isDropdownOpen && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
Expand Down Expand Up @@ -272,6 +274,18 @@ const agentType = [
{ name: "Agentverse", label: "hosted" },
];

const safeParse = (key: string) => {
if (typeof window === "undefined") return null;

try {
const storedData = localStorage.getItem(key);
return storedData ? JSON.parse(storedData) : null;
} catch (error) {
console.error(`Error parsing value for key "${key}":`, error);
return null;
}
};

export const CustomPre: React.FC<CodeBoxProps> = ({
hasCopyCode,
isLocalHostedFile,
Expand All @@ -296,8 +310,13 @@ export const CustomPre: React.FC<CodeBoxProps> = ({
child?.length === 1 && !child[0]?.props?.local
? agentType[1].name
: agentType[0].name;

const [selectedType, setSelectedType] = useState(localHostdType);
const [selectedOS, setSelectedOS] = useState("windows");
const [selectedOS, setSelectedOS] = useState<string>("windows");
useEffect(() => {
const osFromStorage = safeParse("storedOsOption");
setSelectedOS(osFromStorage || "windows");
}, []);

const filteredAgentType =
child?.length === 2
Expand Down
2 changes: 1 addition & 1 deletion pages/references/uagents/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"uagents-api": { "title": "Agents API", "timestamp": true },
"api": { "title": "Agents API", "timestamp": true },
"uagents-protocols": { "title": "Agents protocols", "timestamp": true }
}
3 changes: 2 additions & 1 deletion theme/fetch-ai-docs/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useActiveAnchor, useConfig, useMenu } from "../contexts";
import { renderComponent } from "../utils";
import { Anchor } from "./anchor";
import { Collapse } from "./collapse";
import { WITH_INDEXED_PAGES } from "../constants";

const TreeState: Record<string, boolean> = Object.create(null);

Expand Down Expand Up @@ -143,7 +144,7 @@ function FolderImpl({ item, anchors }: FolderProps): ReactElement {
return (
<>
<li className={cn({ open, active }, "nx-w-full")}>
{(!isLink || ["Ledger", "Indexer"].includes(item.title)) && (
{(!isLink || WITH_INDEXED_PAGES.includes(item.title)) && (
<ComponentToUse
id={`sidebar${item.route?.split("/").join("-").toLowerCase()}`}
href={isLink ? item.route : undefined}
Expand Down
6 changes: 6 additions & 0 deletions theme/fetch-ai-docs/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,9 @@ export const DEEP_OBJECT_KEYS = Object.entries(DEFAULT_THEME)
}
})
.filter(Boolean);

export const WITH_INDEXED_PAGES = [
"Ledger",
"Indexer",
"Agents: uAgents Framework",
];

0 comments on commit 5ae5f47

Please sign in to comment.