Skip to content

Commit

Permalink
feat: fetch and display template menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Jul 19, 2024
1 parent d22c017 commit 089116b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import {
} from "@/components/ui/menubar";
import { ModeToggle } from "./mode-toggle";
import Modal from "./modal";
import { TemplatesMenu } from "./templates-menu";

export function MenubarComponent() {
return (
<Menubar>
<MenubarMenu>
<MenubarTrigger>New</MenubarTrigger>
<MenubarContent>
<TemplatesMenu />
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Theme</MenubarTrigger>
<MenubarContent>
Expand Down
29 changes: 29 additions & 0 deletions components/templates-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from "react";

import { MenubarRadioGroup, MenubarRadioItem } from "@/components/ui/menubar";

async function getData() {
let url = `https://playground-next.test.aelf.dev/playground/templates`;
if (process.env.NODE_ENV === "production") {
url = `/playground/templates`;
}

const res = await fetch(url);
const data = await res.json();

return data as string[];
}

export async function TemplatesMenu() {
const data = await getData();

return (
<MenubarRadioGroup>
{data.map((i) => (
<MenubarRadioItem key={i} value={i}>
{i}
</MenubarRadioItem>
))}
</MenubarRadioGroup>
);
}

0 comments on commit 089116b

Please sign in to comment.