Skip to content

Commit

Permalink
Add a sidebar and app skeleton (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
homanp authored Mar 23, 2023
1 parent 3c0710c commit 31e1dca
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/app/container.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use client";
import React from "react";
import { Flex } from "@chakra-ui/react";
import { Flex, useColorModeValue } from "@chakra-ui/react";
import Sidebar from "./sidebar";

export default function AppContainer({ children }) {
const backgroundColor = useColorModeValue("white", "#111");
return (
<Flex height="100vh">
<Flex height="100vh" backgroundColor={backgroundColor}>
<Sidebar />
{children}
</Flex>
Expand Down
81 changes: 78 additions & 3 deletions app/app/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,86 @@
"use client";
import React from "react";
import { Stack, Text } from "@chakra-ui/react";
import PropTypes from "prop-types";
import { useRouter } from "next/navigation";
import {
Box,
Button,
Icon,
Stack,
useColorMode,
useColorModeValue,
} from "@chakra-ui/react";
import { SIDEBAR_MENU } from "@/lib/sidebar";
import UserMenu from "@/components/user-menu";

function SidebarItem({ id, href, label, icon, ...properties }) {
const router = useRouter();

return (
<Button
key={id}
width="full"
size="sm"
variant="ghost"
justifyContent="flex-start"
leftIcon={<Icon as={icon} fontSize="lg" />}
onClick={() => router.push(href)}
{...properties}
>
{label}
</Button>
);
}

SidebarItem.propTypes = {
id: PropTypes.string,
href: PropTypes.string,
label: PropTypes.string,
icon: PropTypes.func,
};

export default function Sidebar() {
const { colorMode, toggleColorMode } = useColorMode();
const isLight = colorMode === "light";

return (
<Stack width="60px" height="100vh" borderRightWidth="1px">
<Text>Test</Text>
<Stack
width="200px"
height="100vh"
borderRightWidth={0.5}
justifyContent="space-between"
paddingBottom={4}
>
<Stack spacing={4}>
<UserMenu padding={2} />
<Box paddingX={1}>
{SIDEBAR_MENU.filter(({ placement }) => placement === "top").map(
({ id, label, href, icon, iconDark }) => (
<SidebarItem
key={id}
id={id}
label={label}
icon={isLight ? icon : iconDark || icon}
href={href}
/>
)
)}
</Box>
</Stack>
<Stack paddingX={1} spacing={0}>
{SIDEBAR_MENU.filter(({ placement }) => placement === "bottom").map(
({ id, label, labelDark, href, icon, iconDark }) => (
<SidebarItem
key={id}
id={id}
label={isLight ? label : labelDark || label}
icon={isLight ? icon : iconDark || icon}
href={href}
onClick={id === "dark_mode" && toggleColorMode}
/>
)
)}
</Stack>
</Stack>
);
}
24 changes: 24 additions & 0 deletions components/user-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import { Avatar, Divider, HStack, Stack, Text } from "@chakra-ui/react";
import { useSession } from "next-auth/react";

export default function UserMenu({ ...properties }) {
const { data: session, status } = useSession();

return (
<Stack spacing={0}>
<HStack alignItems="center" {...properties}>
<Avatar src={session?.user.image} size="sm" />
<Stack spacing={0} justifyContent="center">
<Text fontSize="sm" noOfLines={1}>
{session?.user.name}
</Text>
<Text fontSize="xs" color="gray.500" noOfLines={1}>
{session?.user.email}
</Text>
</Stack>
</HStack>
<Divider />
</Stack>
);
}
77 changes: 77 additions & 0 deletions lib/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
TbDatabase,
TbHeadset,
TbFileText,
TbLanguage,
TbMessage,
TbPrompt,
TbSettings,
TbMoon,
TbSun,
} from "react-icons/tb";

const PLACEMENT = {
top: "top",
bottom: "bottom",
};

export const SIDEBAR_MENU = [
{
id: "documents",
label: "Documents",
href: "/app/documents",
icon: TbFileText,
placement: PLACEMENT.top,
},
{
id: "prompt_templates",
label: "Prompt templates",
href: "/app/prompt-templates",
icon: TbPrompt,
placement: PLACEMENT.top,
},
{
id: "indexes",
label: "Indexes",
href: "/app/indexes",
icon: TbDatabase,
placement: PLACEMENT.top,
},
{
id: "llm",
label: "LLMs",
href: "/app/llm",
icon: TbLanguage,
placement: PLACEMENT.top,
},
{
id: "agents",
label: "Agents",
href: "/app/agents",
icon: TbHeadset,
placement: PLACEMENT.top,
},
{
id: "chatbots",
label: "Chatbots",
href: "/app/chatbots",
icon: TbMessage,
placement: PLACEMENT.top,
},
{
id: "dark_mode",
label: "Dark",
labelDark: "Light",
href: "/app/settings",
icon: TbMoon,
iconDark: TbSun,
placement: PLACEMENT.bottom,
},
{
id: "settings",
label: "Settings",
href: "/app/settings",
icon: TbSettings,
placement: PLACEMENT.bottom,
},
];

1 comment on commit 31e1dca

@vercel
Copy link

@vercel vercel bot commented on 31e1dca Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

langchain-ui – ./

langchain-ui-homanp.vercel.app
langchain-ui-git-main-homanp.vercel.app
langchain-ui.vercel.app

Please sign in to comment.