From 282ef825cb932b33f528eebc7bb042f1b06152ac Mon Sep 17 00:00:00 2001 From: shadcn Date: Tue, 13 Jun 2023 18:14:06 +0400 Subject: [PATCH] fix: update login button and sidebar --- components/header.tsx | 8 ++++---- components/login-button.tsx | 40 +++++++++++++++++++++++++++++++++++++ components/sidebar-list.tsx | 33 ++++++++++++++++++++---------- components/ui/sheet.tsx | 8 +------- components/user-menu.tsx | 23 +++++---------------- 5 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 components/login-button.tsx diff --git a/components/header.tsx b/components/header.tsx index b2ffc03..d59f67a 100644 --- a/components/header.tsx +++ b/components/header.tsx @@ -21,7 +21,7 @@ export async function Header() { -
+
@@ -33,15 +33,15 @@ export async function Header() { rel="noopener noreferrer" className={cn(buttonVariants({ variant: 'outline' }))} > - - GitHub + + GitHub - + Deploy to Vercel Deploy diff --git a/components/login-button.tsx b/components/login-button.tsx new file mode 100644 index 0000000..3aef62d --- /dev/null +++ b/components/login-button.tsx @@ -0,0 +1,40 @@ +'use client' + +import * as React from 'react' +import { signIn } from '@auth/nextjs/client' + +import { cn } from '@/lib/utils' +import { Button, type ButtonProps } from '@/components/ui/button' +import { IconGitHub, IconSpinner } from '@/components/ui/icons' + +interface LoginButtonProps extends ButtonProps { + text?: string +} + +export function LoginButton({ + className, + text = 'Login with GitHub', + ...props +}: LoginButtonProps) { + const [isLoading, setIsLoading] = React.useState(false) + + return ( + + ) +} diff --git a/components/sidebar-list.tsx b/components/sidebar-list.tsx index 22c405e..1e2278b 100644 --- a/components/sidebar-list.tsx +++ b/components/sidebar-list.tsx @@ -1,13 +1,30 @@ import { getChats } from '@/app/actions' import { Session } from '@auth/core/types' -import { SidebarItem } from './sidebar-item' + +import { SidebarItem } from '@/components/sidebar-item' +import { LoginButton } from '@/components/login-button' export interface SidebarListProps { session?: Session } -export async function SidebarList(props: SidebarListProps) { - const chats = await getChats(props.session?.user?.email) +export async function SidebarList({ session }: SidebarListProps) { + if (!session?.user?.email) { + return ( +
+
+

You are not logged in!

+

+ Please login for chat history. +

+
+ +
+ ) + } + + const chats = await getChats(session.user.email) + return (
{chats?.length ? ( @@ -16,7 +33,7 @@ export async function SidebarList(props: SidebarListProps) { @@ -24,13 +41,7 @@ export async function SidebarList(props: SidebarListProps) {
) : (
-

- {props?.session?.user ? ( - <>No chat history - ) : ( - <>Login for history - )} -

+

No chat history

)}
diff --git a/components/ui/sheet.tsx b/components/ui/sheet.tsx index 6d12ff7..d333799 100644 --- a/components/ui/sheet.tsx +++ b/components/ui/sheet.tsx @@ -85,13 +85,7 @@ const SheetHeader = ({ className, ...props }: React.HTMLAttributes) => ( -
+
) SheetHeader.displayName = 'SheetHeader' diff --git a/components/user-menu.tsx b/components/user-menu.tsx index 280fa3c..c5b96e2 100644 --- a/components/user-menu.tsx +++ b/components/user-menu.tsx @@ -1,37 +1,24 @@ 'use client' import * as React from 'react' -import { signIn } from '@auth/nextjs/client' import { type Session } from '@auth/nextjs/types' -import { Button } from '@/components/ui/button' -import { IconSpinner } from '@/components/ui/icons' +import { LoginButton } from '@/components/login-button' export interface UserMenuProps { session?: Session } export function UserMenu({ session }: UserMenuProps) { - const [isLoading, setIsLoading] = React.useState(false) - if (!session?.user) { return ( - + ) } return ( -

Logged in as {session.user.name}

+

+ {session.user.name} +

) }