diff --git a/docs/pr-evidence/gen-2821-header-desktop.png b/docs/pr-evidence/gen-2821-header-desktop.png new file mode 100644 index 00000000..1092df0a Binary files /dev/null and b/docs/pr-evidence/gen-2821-header-desktop.png differ diff --git a/docs/pr-evidence/gen-2821-header-mobile.png b/docs/pr-evidence/gen-2821-header-mobile.png new file mode 100644 index 00000000..7feafb4f Binary files /dev/null and b/docs/pr-evidence/gen-2821-header-mobile.png differ diff --git a/packages/api/test/static-slice.e2e.test.ts b/packages/api/test/static-slice.e2e.test.ts index 6af507bc..39e4abd7 100644 --- a/packages/api/test/static-slice.e2e.test.ts +++ b/packages/api/test/static-slice.e2e.test.ts @@ -63,8 +63,10 @@ describe.skipIf(!url)("compiled React + actual Worker API + PostgreSQL", () => { await page.getByRole("img", { name: "Status: Succeeded", exact: true }).waitFor(); } await page.goto(`https://factorize.test/projects/${f.projectId}`); - await page.getByRole("link", { name: "owner@example.test", exact: true }).waitFor(); - await page.locator("#project-switcher").waitFor(); + await page.getByRole("link", { name: "owner", exact: true }).waitFor(); + await page.getByRole("link", { name: "Default", exact: true }).waitFor(); + await page.getByRole("button", { name: "Switch project", exact: true }).click(); + await page.getByRole("combobox", { name: "Search projects", exact: true }).waitFor(); expect(await page.getByRole("link", { name: "Factorize", exact: true }).count()).toBe(0); expect(await page.locator("html").getAttribute("data-theme")).toBe("light"); expect(await page.locator("body").evaluate((element: any) => (globalThis as any).getComputedStyle(element).backgroundColor)).toBe("rgb(252, 251, 246)"); diff --git a/packages/app/src/features/auth/account-bar.tsx b/packages/app/src/features/auth/account-bar.tsx index 557f96c2..8b671b23 100644 --- a/packages/app/src/features/auth/account-bar.tsx +++ b/packages/app/src/features/auth/account-bar.tsx @@ -1,17 +1,23 @@ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { Button } from "../../shared/ui"; import { SearchLauncher } from "../search/launcher"; import { ThemeToggle } from "../../shared/theme"; -import { Link } from "@tanstack/react-router"; +import { Link, useNavigate, useRouterState } from "@tanstack/react-router"; import { useMutation, useQuery } from "@tanstack/react-query"; import { api } from "factorize-api-client"; import { messageOf, refreshIdentity, sessionQuery } from "./session"; -import { projectsQuery } from "../projects/queries"; -import { useNavigate } from "@tanstack/react-router"; +import { projectQuery, projectsQuery } from "../projects/queries"; +import beeMark from "../../assets/bee-mark-monochrome.png"; export function AccountBar() { const session = useQuery(sessionQuery); - const projects = useQuery({ ...projectsQuery, enabled: !!session.data?.authenticated }); + const authenticated = session.data?.authenticated; + const projects = useQuery({ ...projectsQuery, enabled: !!authenticated }); + const pathname = useRouterState({ select: state => state.location.pathname }); + const match = pathname.match(/^\/projects\/([^/]+)/); + const routeProjectId = match && match[1] !== "new" ? decodeURIComponent(match[1]) : undefined; + const routeProject = useQuery({ ...projectQuery(routeProjectId ?? ""), enabled: !!authenticated && !!routeProjectId, retry: false }); + const currentProject = projects.data?.find(project => project.id === routeProjectId) ?? routeProject.data; const navigate = useNavigate(); const logout = useMutation({ retry: false, @@ -21,28 +27,65 @@ export function AccountBar() { await refreshIdentity(); }, }); - const [open, setOpen] = useState(false); - const menu = useRef(null), trigger = useRef(null); + const [open, setOpen] = useState(false), [search, setSearch] = useState(""), [active, setActive] = useState(0); + const [accountOpen, setAccountOpen] = useState(false); + const menu = useRef(null), trigger = useRef(null), searchInput = useRef(null), accountMenu = useRef(null), accountTrigger = useRef(null); + const options = useMemo(() => (projects.data ?? []).filter(project => project.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase())), [projects.data, search]); useEffect(() => { - if (!open) return; - const click = (event: PointerEvent) => { if (!menu.current?.contains(event.target as Node)) setOpen(false); }; - const key = (event: KeyboardEvent) => { if (event.key === "Escape") { setOpen(false); trigger.current?.focus(); } }; + if (!open && !accountOpen) return; + const click = (event: PointerEvent) => { + if (open && !menu.current?.contains(event.target as Node)) setOpen(false); + if (accountOpen && !accountMenu.current?.contains(event.target as Node)) setAccountOpen(false); + }; + const key = (event: KeyboardEvent) => { + if (event.key === "Escape") { + if (open) { setOpen(false); trigger.current?.focus(); } + if (accountOpen) { setAccountOpen(false); accountTrigger.current?.focus(); } + } + }; document.addEventListener("pointerdown", click); document.addEventListener("keydown", key); return () => { document.removeEventListener("pointerdown", click); document.removeEventListener("keydown", key); }; - }, [open]); - const authenticated = session.data?.authenticated; + }, [open, accountOpen]); + const choose = (id: string) => { setOpen(false); setSearch(""); void navigate({ to: "/projects/$projectId", params: { projectId: id } }); }; + const email = session.data?.authenticated ? session.data.user.email ?? "" : ""; + const initials = (email || "?").split("@")[0].split(/[._-]/).filter(Boolean).slice(0, 2).map((part: string) => part[0]).join("").toUpperCase() || "?"; + // The current session contract exposes email only. Use its local part as a readable + // display identity and retain the full address in the account menu. + const displayName = email.split("@")[0] || "Account"; return
Skip to content -