Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

2.9 KB
Raw Blame
import { ArrowLeft, ArrowRight, House } from "lucide-react";

import { useT } from "@/i18n";
import { useEventStore } from "@/store/events";
import { useSectionHistory } from "@/hooks/useSectionHistory";
import { startNewTextChat } from "@/lib/newChat";

/**
 * One shape for every caption control in this group.
 *
 * Theme tokens only, so the buttons read in light and dark mode alike. A
 * disabled direction goes quiet (no hover lift, low opacity) but keeps its
 * tooltip — a forward button that cannot explain itself teaches nothing.
 */
const NAV_BUTTON =
  "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground " +
  "transition-colors hover:bg-secondary hover:text-foreground " +
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring " +
  "disabled:cursor-default disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-muted-foreground";

/**
 * The caption's leading navigation: home, back and forward.
 *
 * Rendered at the far left of the window caption (see TopBar), so it is on
 * screen for EVERY section — chat, agents, voice, settings — with no second
 * bar per view. Back/forward walk the visited-section history
 * (`useSectionHistory`): back returns to the previously visited section, and
 * forward only re-applies an undone step, staying disabled until one exists.
 * Home is always live: it opens the front page with a fresh chat, the same
 * screen Jarvis starts on, from wherever the window is.
 * A detached solo window is pinned to one view, so the group stays out of it.
 */
export function SectionNavButtons() {
  const t = useT();
  const solo = useEventStore((s) => s.solo);
  const { canGoBack, canGoForward, goBack, goForward } = useSectionHistory();

  if (solo) return null;

  const backLabel = t("topbar.nav_back");
  const forwardLabel = t("topbar.nav_forward");
  const homeLabel = t("topbar.nav_home");

  return (
    <div
      className="flex shrink-0 items-center"
      data-testid="section-nav-buttons"
      role="group"
      aria-label={t("sidebar.sections")}
    >
      <button
        type="button"
        data-testid="section-nav-home"
        onClick={() => startNewTextChat()}
        aria-label={homeLabel}
        title={homeLabel}
        className={NAV_BUTTON}
      >
        <House className="h-4 w-4" aria-hidden />
      </button>
      <button
        type="button"
        data-testid="section-nav-back"
        onClick={() => goBack()}
        disabled={!canGoBack}
        aria-label={backLabel}
        title={backLabel}
        className={NAV_BUTTON}
      >
        <ArrowLeft className="h-4 w-4" aria-hidden />
      </button>
      <button
        type="button"
        data-testid="section-nav-forward"
        onClick={() => goForward()}
        disabled={!canGoForward}
        aria-label={forwardLabel}
        title={forwardLabel}
        className={NAV_BUTTON}
      >
        <ArrowRight className="h-4 w-4" aria-hidden />
      </button>
    </div>
  );
}