Skip to content

Commit

Permalink
Merge pull request #191 from microsoft/add-collapsible-menu
Browse files Browse the repository at this point in the history
Add collapsible menu
  • Loading branch information
davidxw authored Sep 27, 2023
2 parents 20ea2f4 + 84c7785 commit 3a5fd42
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
Binary file modified images/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/app/chat/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChatMenu } from "@/features/chat/chat-menu/chat-menu";
import { ChatMenuContainer } from "@/features/chat/chat-menu/chat-menu-container";
import { MainMenu } from "@/features/menu/menu";
import { AI_NAME } from "@/features/theme/customise";

Expand All @@ -16,7 +17,10 @@ export default async function RootLayout({
<>
<MainMenu />
<div className="flex-1 flex rounded-md overflow-hidden bg-card/70">
<ChatMenu /> {children}
<ChatMenuContainer>
<ChatMenu />
</ChatMenuContainer>
{children}
</div>
</>
);
Expand Down
7 changes: 0 additions & 7 deletions src/app/chat/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { Card } from "@/components/ui/card";
import { FindAllChatThreadForCurrentUser } from "@/features/chat/chat-services/chat-thread-service";
import { StartNewChat } from "@/features/chat/chat-ui/start-new-chat";
import { redirect } from "next/navigation";

export default async function Home() {
const chats = await FindAllChatThreadForCurrentUser();
if (chats.length > 0) {
redirect(`/chat/${chats[0].id}`);
}

return (
<Card className="h-full items-center flex justify-center flex-1">
<StartNewChat />
Expand Down
12 changes: 12 additions & 0 deletions src/features/chat/chat-menu/chat-menu-container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { useMenuContext } from "@/features/menu/menu-context";

export const ChatMenuContainer = ({
children,
}: {
children: React.ReactNode;
}) => {
const { isMenuOpen } = useMenuContext();
return <>{isMenuOpen ? children : null}</>;
};
27 changes: 27 additions & 0 deletions src/features/menu/menu-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { createContext, useState } from "react";

interface MenuContextProps {
isMenuOpen: boolean;
toggleMenu: () => void;
}

export const MenuContext = createContext<MenuContextProps>({
isMenuOpen: true,
toggleMenu: () => {},
});

export const MenuProvider = ({ children }: { children: React.ReactNode }) => {
const [isMenuOpen, setIsMenuOpen] = useState(true);

const toggleMenu = () => {
setIsMenuOpen(!isMenuOpen);
};

return (
<MenuContext.Provider value={{ isMenuOpen, toggleMenu }}>
{children}
</MenuContext.Provider>
);
};

export const useMenuContext = () => React.useContext(MenuContext);
24 changes: 20 additions & 4 deletions src/features/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
"use client";

import { Button } from "@/components/ui/button";
import { LayoutDashboard, MessageCircle } from "lucide-react";
import {
LayoutDashboard,
MessageCircle,
PanelLeftClose,
PanelRightClose,
} from "lucide-react";
import Link from "next/link";
import { ThemeToggle } from "../theme/theme-toggle";
import { UserProfile } from "../user-profile";

import { useSession } from "next-auth/react";
import { useMenuContext } from "./menu-context";

export const MainMenu = () => {
const { data: session } = useSession();
const { isMenuOpen, toggleMenu } = useMenuContext();
return (
<div className="flex flex-col justify-between p-2">
<div className="flex gap-2 flex-col items-center">
<Button
<div className="flex gap-2 flex-col items-center">
<Button
onClick={toggleMenu}
className="rounded-full w-[40px] h-[40px] p-1 text-primary"
variant={"outline"}
>
{isMenuOpen ? <PanelLeftClose /> : <PanelRightClose />}
</Button>
<Button
asChild
className="rounded-full w-[40px] h-[40px] p-1 text-primary"
variant={"outline"}
Expand Down Expand Up @@ -41,7 +55,9 @@ export const MainMenu = () => {
<LayoutDashboard />
</Link>
</Button>
) : (<></>)}
) : (
<></>
)}
</div>
<div className="flex flex-col gap-2">
<ThemeToggle />
Expand Down
7 changes: 6 additions & 1 deletion src/features/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"use client";

import { SessionProvider } from "next-auth/react";
import { MenuProvider } from "./menu/menu-context";

export const Providers = ({ children }: { children: React.ReactNode }) => {
return <SessionProvider>{children}</SessionProvider>;
return (
<SessionProvider>
<MenuProvider>{children}</MenuProvider>
</SessionProvider>
);
};

0 comments on commit 3a5fd42

Please sign in to comment.