-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sidebar and app skeleton (#13)
- Loading branch information
Showing
4 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; |
31e1dca
There was a problem hiding this comment.
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