account button

This commit is contained in:
Nate 2025-03-15 08:54:41 -07:00
parent 7dac4f837f
commit 18f439c85c
3 changed files with 64 additions and 46 deletions

View file

@ -1,4 +1,5 @@
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import { AccountButton } from "../pages/config/AccountButton";
export interface PageHeaderProps {
onTitleClick?: () => void;
@ -21,17 +22,20 @@ export default function PageHeader({
: ""
}`}
>
<div className="flex items-center">
<div className="flex w-full items-center justify-between pr-4">
{title && (
<div
className="cursor-pointer transition-colors duration-200 hover:text-zinc-100"
onClick={onTitleClick}
>
<ArrowLeftIcon className="ml-3 inline-block h-3 w-3" />
<span className="m-2 inline-block text-base font-bold">
{title}
</span>
</div>
<>
<div
className="cursor-pointer transition-colors duration-200 hover:text-zinc-100"
onClick={onTitleClick}
>
<ArrowLeftIcon className="ml-3 inline-block h-3 w-3" />
<span className="m-2 inline-block text-base font-bold">
{title}
</span>
</div>
<AccountButton />
</>
)}
</div>
<div className="ml-auto">{rightContent}</div>

View file

@ -0,0 +1,48 @@
import { Popover, Transition } from "@headlessui/react";
import { UserCircleIcon } from "@heroicons/react/24/outline";
import { Fragment } from "react";
import { SecondaryButton } from "../../components";
import { useAuth } from "../../context/Auth";
export function AccountButton() {
const { session, logout, login } = useAuth();
if (!session) {
return (
<SecondaryButton onClick={() => login(false)}>Sign in</SecondaryButton>
);
}
return (
<Popover className="relative">
<Popover.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border border-solid">
<UserCircleIcon className="h-6 w-6" />
</Popover.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel className="bg-vsc-input-background absolute right-0 z-10 mt-2 w-[250px] rounded-md border border-zinc-700 p-4 shadow-lg">
<div className="flex flex-col gap-3">
<div className="flex flex-col">
<span className="font-medium">{session.account.label}</span>
<span className="text-lightgray text-sm">
{session.account.id}
</span>
</div>
<SecondaryButton onClick={logout} className="w-full justify-center">
Sign out
</SecondaryButton>
</div>
</Popover.Panel>
</Transition>
</Popover>
);
}

View file

@ -6,7 +6,6 @@ import {
ChevronUpDownIcon,
PlusCircleIcon,
SparklesIcon,
UserCircleIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { ModelDescription } from "core";
@ -16,7 +15,7 @@ import {
} from "core/config/sharedConfig";
import { Fragment, useContext, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Input, SecondaryButton } from "../../components";
import { Input } from "../../components";
import NumberInput from "../../components/gui/NumberInput";
import { Select } from "../../components/gui/Select";
import ToggleSwitch from "../../components/gui/Switch";
@ -182,40 +181,7 @@ function ConfigPage() {
<div className="overflow-y-scroll">
<PageHeader showBorder onTitleClick={() => navigate("/")} title="Chat" />
<div className="divide-x-0 divide-y-2 divide-solid divide-zinc-700 px-4 pt-4">
{(session || hubEnabled || controlServerBetaEnabled) && (
<div className="flex flex-col">
<div className="flex max-w-[400px] flex-col gap-4 pb-4">
<h2 className="mb-1 mt-0">Account</h2>
{!session ? (
<div className="flex flex-col gap-2">
<span>You are not signed in.</span>
<SecondaryButton onClick={() => login(false)}>
Sign in
</SecondaryButton>
</div>
) : (
<div className="flex flex-col gap-4">
<div className="flex flex-row items-center gap-2">
<UserCircleIcon className="h-6 w-6" />
<span>
{session.account.label === ""
? "Signed in"
: session.account.label}
</span>
<span
onClick={logout}
className="text-lightgray cursor-pointer underline"
>
(Sign out)
</span>
</div>
</div>
)}
</div>
</div>
)}
<div className="divide-x-0 divide-y-2 divide-solid divide-zinc-700 px-4">
<div className="flex flex-col">
<div className="flex max-w-[400px] flex-col gap-4 py-6">
<h2 className="mb-1 mt-0">Configuration</h2>