Initial release of 8BitDo Control Center
Provide a Linux desktop controller configuration app with evdev input, uinput remapping, profiles, calibration, and reconnect recovery. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
31
src/components/layout/AppLayout.tsx
Normal file
31
src/components/layout/AppLayout.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Outlet } from "react-router-dom";
|
||||
|
||||
import { ConfirmDialogHost } from "@/components/feedback/ConfirmDialogHost";
|
||||
import { ToastStack } from "@/components/feedback/ToastStack";
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import { TopBar } from "@/components/layout/TopBar";
|
||||
import { useControllerInit } from "@/hooks/useController";
|
||||
import { useProfileInit } from "@/hooks/useProfileInit";
|
||||
import { useTheme } from "@/hooks/useTheme";
|
||||
import { useUnsavedChangesWarning } from "@/hooks/useUnsavedChanges";
|
||||
|
||||
export function AppLayout() {
|
||||
useTheme();
|
||||
useControllerInit();
|
||||
useProfileInit();
|
||||
useUnsavedChangesWarning();
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-screen bg-app text-fg">
|
||||
<Sidebar />
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<TopBar />
|
||||
<main className="flex-1 overflow-y-auto px-8 py-6">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
<ToastStack />
|
||||
<ConfirmDialogHost />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
24
src/components/layout/PageShell.tsx
Normal file
24
src/components/layout/PageShell.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
interface PageShellProps {
|
||||
title: string;
|
||||
description?: string;
|
||||
actions?: ReactNode;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/** Consistent header + content wrapper reused by every page. */
|
||||
export function PageShell({ title, description, actions, children }: PageShellProps) {
|
||||
return (
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-5">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-fg">{title}</h2>
|
||||
{description && <p className="mt-1 text-sm text-fg-muted">{description}</p>}
|
||||
</div>
|
||||
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
53
src/components/layout/Sidebar.tsx
Normal file
53
src/components/layout/Sidebar.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { clsx } from "clsx";
|
||||
import { Gamepad2 } from "lucide-react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
import { NAV_ITEMS } from "@/constants/navigation";
|
||||
import { confirmDiscardUnsavedChanges } from "@/hooks/useUnsavedChanges";
|
||||
|
||||
export function Sidebar() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
async function handleNavigate(path: string) {
|
||||
if (path === location.pathname) return;
|
||||
const canLeave = await confirmDiscardUnsavedChanges();
|
||||
if (canLeave) navigate(path);
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="flex h-full w-60 shrink-0 flex-col border-r border-border bg-surface">
|
||||
<div className="flex items-center gap-2.5 px-5 py-5">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-accent text-accent-fg">
|
||||
<Gamepad2 size={18} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-fg leading-tight">8BitDo Control Center</p>
|
||||
<p className="text-[11px] text-fg-subtle leading-tight">Ultimate Controller</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 space-y-0.5 overflow-y-auto px-3 pb-4">
|
||||
{NAV_ITEMS.map((item) => {
|
||||
const active = location.pathname === item.path;
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<button
|
||||
key={item.path}
|
||||
onClick={() => handleNavigate(item.path)}
|
||||
className={clsx(
|
||||
"flex w-full cursor-pointer items-center gap-3 rounded-lg px-3 py-2 text-left text-sm transition-colors duration-150",
|
||||
active
|
||||
? "bg-accent/15 text-accent-strong font-medium"
|
||||
: "text-fg-muted hover:bg-surface-2 hover:text-fg",
|
||||
)}
|
||||
>
|
||||
<Icon size={16} className="shrink-0" />
|
||||
{item.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
58
src/components/layout/TopBar.tsx
Normal file
58
src/components/layout/TopBar.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Bluetooth, Cable, Radio, Usb } from "lucide-react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
import { Badge } from "@/components/common/Badge";
|
||||
import { StatusDot } from "@/components/common/StatusDot";
|
||||
import { NAV_ITEMS } from "@/constants/navigation";
|
||||
import { useControllerStore } from "@/stores/controllerStore";
|
||||
import { useProfileStore } from "@/stores/profileStore";
|
||||
import type { ConnectionKind } from "@/types/controller";
|
||||
|
||||
const CONNECTION_ICON: Record<ConnectionKind, typeof Usb> = {
|
||||
usb: Usb,
|
||||
bluetooth: Bluetooth,
|
||||
receiver2_4ghz: Radio,
|
||||
unknown: Cable,
|
||||
};
|
||||
|
||||
const CONNECTION_LABEL: Record<ConnectionKind, string> = {
|
||||
usb: "USB",
|
||||
bluetooth: "Bluetooth",
|
||||
receiver2_4ghz: "2.4GHz Receiver",
|
||||
unknown: "Unknown",
|
||||
};
|
||||
|
||||
export function TopBar() {
|
||||
const location = useLocation();
|
||||
const activeController = useControllerStore((s) => s.activeController());
|
||||
const activeProfile = useProfileStore((s) => s.activeProfile);
|
||||
|
||||
const pageTitle = NAV_ITEMS.find((item) => item.path === location.pathname)?.label ?? "8BitDo Control Center";
|
||||
|
||||
return (
|
||||
<header className="flex h-14 shrink-0 items-center justify-between border-b border-border bg-surface px-6">
|
||||
<h1 className="text-base font-semibold text-fg">{pageTitle}</h1>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
{activeProfile && <Badge tone="accent">Profile: {activeProfile.name}</Badge>}
|
||||
|
||||
{activeController ? (
|
||||
<Badge tone="success">
|
||||
<StatusDot tone="success" pulse />
|
||||
{(() => {
|
||||
const Icon = CONNECTION_ICON[activeController.connection];
|
||||
return <Icon size={12} />;
|
||||
})()}
|
||||
{activeController.name}
|
||||
<span className="text-fg-subtle">· {CONNECTION_LABEL[activeController.connection]}</span>
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge tone="neutral">
|
||||
<StatusDot tone="neutral" />
|
||||
No controller detected
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user