Files
immich-redaktions-plugin/docs/superpowers/plans/2026-08-11-mobile-portal-navigation.md

14 KiB
Raw Permalink Blame History

Mobile Portal Navigation Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Add an accessible mobile-only dropdown that exposes every role-specific portal destination, theme control and sign-out action while leaving desktop navigation unchanged.

Architecture: A focused client component owns the dropdown interaction and receives the existing NavItem[] from the server-rendered PortalShell. PortalShell renders this component only for mobile layouts and keeps its existing desktop controls behind the sm breakpoint, avoiding duplicated route catalogues or new dependencies.

Tech Stack: Next.js 16 App Router, React 19, TypeScript, Tailwind CSS 4, Lucide React, Vitest, Testing Library, jsdom.

Global Constraints

  • The mobile menu is visible only below the Tailwind sm breakpoint.
  • The existing desktop navigation, route names, authorization and sign-out behavior remain unchanged.
  • The component consumes the existing role-specific nav: NavItem[]; no second navigation catalogue is allowed.
  • The menu closes on link activation, Escape and outside pointer interaction.
  • Escape returns focus to the trigger.
  • The active route uses aria-current="page" and a high-contrast visual state.
  • Touch targets are at least 44 pixels high.
  • No new runtime dependency or animation framework may be added.

Task 1: Accessible mobile dropdown behavior

Files:

  • Create: src/components/layout/mobile-portal-menu.tsx
  • Create: src/components/layout/mobile-portal-menu.test.tsx

Interfaces:

  • Consumes: NavItem from @/components/layout/portal-shell, ThemeToggle, LogoutButton, and usePathname().

  • Produces: MobilePortalMenu({ nav, sectionLabel }: { nav: NavItem[]; sectionLabel: string }): JSX.Element.

  • Step 1: Write the failing interaction tests

Create src/components/layout/mobile-portal-menu.test.tsx with jsdom, a controlled usePathname() mock, and real child controls:

// @vitest-environment jsdom

import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, expect, test, vi } from "vitest";

const { usePathname } = vi.hoisted(() => ({
  usePathname: vi.fn(),
}));

vi.mock("next/navigation", () => ({ usePathname }));

import { MobilePortalMenu } from "./mobile-portal-menu";

const nav = [
  { href: "/admin", label: "Dashboard" },
  { href: "/admin/redaktionen", label: "Redaktionen" },
  { href: "/admin/abrechnungen", label: "Abrechnungen" },
  { href: "/admin/audit", label: "Audit" },
];

beforeEach(() => usePathname.mockReturnValue("/admin/redaktionen/abc"));
afterEach(cleanup);

test("opens every mobile portal action and marks the most specific active route", () => {
  render(<MobilePortalMenu nav={nav} sectionLabel="Administration" />);

  const trigger = screen.getByRole("button", { name: /menü öffnen/i });
  expect(trigger.getAttribute("aria-expanded")).toBe("false");
  expect(screen.queryByRole("navigation", { name: /mobile navigation/i })).toBeNull();

  fireEvent.click(trigger);

  expect(trigger.getAttribute("aria-expanded")).toBe("true");
  expect(screen.getByRole("link", { name: "Dashboard" })).toBeTruthy();
  expect(screen.getByRole("link", { name: "Redaktionen" }).getAttribute("aria-current")).toBe("page");
  expect(screen.getByRole("link", { name: "Abrechnungen" })).toBeTruthy();
  expect(screen.getByRole("link", { name: "Audit" })).toBeTruthy();
  expect(screen.getByRole("button", { name: /design umschalten/i })).toBeTruthy();
  expect(screen.getByRole("button", { name: /abmelden/i })).toBeTruthy();
});

test("closes after navigation, Escape and an outside pointer interaction", () => {
  render(
    <div>
      <MobilePortalMenu nav={nav} sectionLabel="Administration" />
      <button type="button">Außerhalb</button>
    </div>,
  );

  const trigger = screen.getByRole("button", { name: /menü öffnen/i });
  fireEvent.click(trigger);
  fireEvent.click(screen.getByRole("link", { name: "Audit" }));
  expect(trigger.getAttribute("aria-expanded")).toBe("false");

  fireEvent.click(trigger);
  fireEvent.keyDown(document, { key: "Escape" });
  expect(trigger.getAttribute("aria-expanded")).toBe("false");
  expect(document.activeElement).toBe(trigger);

  fireEvent.click(trigger);
  fireEvent.pointerDown(screen.getByRole("button", { name: "Außerhalb" }));
  expect(trigger.getAttribute("aria-expanded")).toBe("false");
});
  • Step 2: Run the focused test and verify RED

Run:

./node_modules/.bin/vitest run src/components/layout/mobile-portal-menu.test.tsx

Expected: FAIL because ./mobile-portal-menu does not exist.

  • Step 3: Implement the minimal client component

Create src/components/layout/mobile-portal-menu.tsx:

"use client";

import { useEffect, useMemo, useRef, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Menu, X } from "lucide-react";

import type { NavItem } from "@/components/layout/portal-shell";
import { LogoutButton } from "@/components/layout/logout-button";
import { ThemeToggle } from "@/components/theme-toggle";

type MobilePortalMenuProps = {
  nav: NavItem[];
  sectionLabel: string;
};

export function MobilePortalMenu({ nav, sectionLabel }: Readonly<MobilePortalMenuProps>) {
  const pathname = usePathname();
  const [open, setOpen] = useState(false);
  const containerRef = useRef<HTMLDivElement>(null);
  const triggerRef = useRef<HTMLButtonElement>(null);
  const menuId = "mobile-portal-menu";

  const activeHref = useMemo(
    () => nav
      .filter(({ href }) => pathname === href || pathname.startsWith(`${href}/`))
      .sort((left, right) => right.href.length - left.href.length)[0]?.href,
    [nav, pathname],
  );

  useEffect(() => {
    if (!open) return;

    function closeOnOutsidePointer(event: PointerEvent) {
      if (!containerRef.current?.contains(event.target as Node)) setOpen(false);
    }

    function closeOnEscape(event: KeyboardEvent) {
      if (event.key !== "Escape") return;
      setOpen(false);
      triggerRef.current?.focus();
    }

    document.addEventListener("pointerdown", closeOnOutsidePointer);
    document.addEventListener("keydown", closeOnEscape);
    return () => {
      document.removeEventListener("pointerdown", closeOnOutsidePointer);
      document.removeEventListener("keydown", closeOnEscape);
    };
  }, [open]);

  return (
    <div ref={containerRef} className="relative sm:hidden">
      <button
        ref={triggerRef}
        type="button"
        aria-controls={menuId}
        aria-expanded={open}
        aria-label={open ? "Menü schließen" : "Menü öffnen"}
        className="inline-flex min-h-11 items-center gap-2 rounded-md border border-border bg-background px-3 text-sm font-semibold"
        onClick={() => setOpen((current) => !current)}
      >
        {open ? <X aria-hidden="true" className="size-5" /> : <Menu aria-hidden="true" className="size-5" />}
        Menü
      </button>

      {open ? (
        <div
          id={menuId}
          className="absolute right-0 top-[calc(100%+0.75rem)] z-50 w-[min(22rem,calc(100vw-2rem))] animate-in fade-in slide-in-from-top-2 rounded-xl border border-border bg-background p-2 shadow-xl duration-150 motion-reduce:animate-none"
        >
          <p className="px-3 py-2 text-xs font-bold uppercase tracking-widest text-muted-foreground">
            {sectionLabel}
          </p>
          <nav aria-label="Mobile Navigation" className="grid gap-1">
            {nav.map((item) => {
              const active = item.href === activeHref;
              return (
                <Link
                  key={item.href}
                  href={item.href}
                  aria-current={active ? "page" : undefined}
                  className={active
                    ? "flex min-h-11 items-center rounded-lg bg-foreground px-3 font-semibold text-background"
                    : "flex min-h-11 items-center rounded-lg px-3 font-medium hover:bg-muted"}
                  onClick={() => setOpen(false)}
                >
                  {item.label}
                </Link>
              );
            })}
          </nav>
          <div className="mt-2 flex min-h-11 items-center justify-between border-t border-border px-3 pt-2">
            <span className="text-sm text-muted-foreground">Darstellung</span>
            <ThemeToggle />
          </div>
          <div className="mt-2 border-t border-border px-3 pt-2">
            <LogoutButton />
          </div>
        </div>
      ) : null}
    </div>
  );
}
  • Step 4: Run the focused test and verify GREEN

Run:

./node_modules/.bin/vitest run src/components/layout/mobile-portal-menu.test.tsx

Expected: 1 file and 2 tests PASS.

  • Step 5: Run typecheck and lint for the new boundary

Run:

./node_modules/.bin/tsc --noEmit
./node_modules/.bin/eslint src/components/layout/mobile-portal-menu.tsx src/components/layout/mobile-portal-menu.test.tsx

Expected: both commands exit 0 with no errors.

  • Step 6: Commit the independently tested component
git add src/components/layout/mobile-portal-menu.tsx src/components/layout/mobile-portal-menu.test.tsx
git commit -m "feat: add accessible mobile portal menu"

Task 2: Integrate the menu into the shared portal shell

Files:

  • Modify: src/components/layout/portal-shell.tsx
  • Modify: src/components/brand/logo.test.tsx

Interfaces:

  • Consumes: MobilePortalMenu({ nav, sectionLabel }) from Task 1 and the existing PortalShellProps.

  • Produces: one shared responsive header used unchanged by src/app/admin/layout.tsx and src/app/redaktion/layout.tsx.

  • Step 1: Extend the existing shell test with the mobile contract

In src/components/brand/logo.test.tsx, mock usePathname() before imports and extend the PortalShell test:

import { fireEvent, render, screen } from "@testing-library/react";
import { expect, test, vi } from "vitest";

vi.mock("next/navigation", () => ({
  usePathname: () => "/redaktion/alben",
}));

// Existing tests remain. In the PortalShell test, add:
const menuTrigger = screen.getByRole("button", { name: /menü öffnen/i });
expect(menuTrigger.parentElement?.className).toContain("sm:hidden");
fireEvent.click(menuTrigger);
expect(screen.getAllByRole("link", { name: "Alben" })).toHaveLength(2);
expect(screen.getByRole("navigation", { name: /mobile navigation/i })).toBeTruthy();

The two Alben links demonstrate that the unchanged desktop link and the mobile dropdown consume the same supplied nav entry. The CSS visibility classes ensure only one is exposed visually at a given breakpoint.

  • Step 2: Run the shell test and verify RED

Run:

./node_modules/.bin/vitest run src/components/brand/logo.test.tsx

Expected: FAIL because PortalShell does not yet expose the mobile trigger.

  • Step 3: Integrate mobile and desktop control groups

Modify src/components/layout/portal-shell.tsx:

import { MobilePortalMenu } from "@/components/layout/mobile-portal-menu";

// Inside the right-hand header container, preserve sectionLabel and desktop nav,
// replace the always-visible controls with:
<div className="hidden items-center gap-4 sm:flex">
  <ThemeToggle />
  <LogoutButton />
</div>
<MobilePortalMenu nav={nav} sectionLabel={sectionLabel} />

Keep the existing desktop <nav className="hidden sm:flex ..."> unchanged. Use px-4 sm:px-6 lg:px-12 on the header row so the mobile trigger and logo fit at 320 pixels without altering tablet/desktop spacing.

  • Step 4: Run component tests and verify GREEN

Run:

./node_modules/.bin/vitest run src/components/layout/mobile-portal-menu.test.tsx src/components/brand/logo.test.tsx

Expected: 2 files and all tests PASS.

  • Step 5: Verify admin and editorial route catalogues remain unchanged

Run:

rg -n 'Dashboard|Redaktionen|Abrechnungen|Audit' src/app/admin/layout.tsx
rg -n 'Alben|Merkzettel|Nutzungen|Profil' src/app/redaktion/layout.tsx

Expected: all four role-specific destinations remain present in their existing layout and no duplicate catalogue exists in mobile-portal-menu.tsx.

  • Step 6: Commit shell integration
git add src/components/layout/portal-shell.tsx src/components/brand/logo.test.tsx
git commit -m "feat: expose portal navigation on mobile"

Task 3: Full verification and production handoff

Files:

  • Verify only; no production files are added by this task.

Interfaces:

  • Consumes: completed component and shared-shell integration from Tasks 1–2.

  • Produces: verified Git history ready for push and container rebuild.

  • Step 1: Run the complete deterministic suite

./node_modules/.bin/vitest run src
./node_modules/.bin/tsc --noEmit
./node_modules/.bin/eslint .
./node_modules/.bin/drizzle-kit check
git diff --check

Expected: all commands exit 0, with no failed tests or lint/type errors.

  • Step 2: Run the production build with non-secret verification values
env \
  DATABASE_URL=postgres://portal:change-me@portal-db:5432/portal \
  BETTER_AUTH_SECRET=replace-with-a-long-random-secret \
  BETTER_AUTH_URL=https://redaktionen.leon-tonhaeuser.de \
  IMMICH_BASE_URL=http://immich-server:2283 \
  IMMICH_API_KEY=replace-with-a-restricted-immich-api-key \
  SMTP_HOST=smtp.example.com SMTP_PORT=587 \
  SMTP_USER=portal@example.com SMTP_PASSWORD=replace-with-an-smtp-password \
  SMTP_FROM=portal@example.com \
  LEGAL_IMPRINT_URL=https://leon-tonhaeuser.de/impressum \
  LEGAL_PRIVACY_URL=https://leon-tonhaeuser.de/datenschutz \
  LEGAL_TERMS_URL=https://leon-tonhaeuser.de/agb \
  NEXT_DISABLE_TURBOPACK=1 \
  ./node_modules/.bin/next build --webpack

Expected: optimized production build exits 0 and lists the authenticated admin and editorial routes.

  • Step 3: Inspect final scope and repository state
git status --short
git log -4 --oneline

Expected: no uncommitted production changes; the design, component and shell integration commits are visible.

  • Step 4: Push after user-authorized integration choice
git push origin-https main

Expected: GitLab advances main to the verified shell integration commit.