Files
snapcad-studio/apps/web/src/components/snapcad/EnterpriseTopBar.tsx
T
Enes Yakıştır 060f334426
Build and Push Docker Images / build (push) Canceled after 0s
CI / Typecheck and unit tests (push) Canceled after 0s
fix: ekran okuyucuda tekrarlanan rol adlarini ve menubar ARIA yapisini duzelt
2026-11-10 19:47:24 +03:00

457 lines
15 KiB
TypeScript

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import {
Activity,
ArrowLeft,
Blocks,
Box,
CheckCircle2,
ChevronDown,
Cpu,
Download,
FileCode,
FileDown,
FileUp,
FolderOpen,
GraduationCap,
Layers,
Mic,
MoveRight,
Pencil,
Redo2,
RotateCcw,
Ruler,
Settings,
Smartphone,
Sparkles,
Trophy,
Undo2,
SlidersHorizontal,
} from "lucide-react";
import { useEffect, useRef, useState, type ChangeEvent, type KeyboardEvent, type ReactNode } from "react";
import type { AppThemePreference } from "@/lib/appTheme";
export type EnterpriseStudioMode = "3d-solid" | "push-pull" | "drawing" | "circuits" | "codeblocks" | "challenges";
interface EnterpriseTopBarProps {
projectName: string;
onProjectNameChange?: (name: string) => void;
activeStudio: EnterpriseStudioMode;
onStudioChange: (studio: EnterpriseStudioMode) => void;
onBackToDashboard?: () => void;
canUndo?: boolean;
canRedo?: boolean;
onUndo?: () => void;
onRedo?: () => void;
onImport?: () => void;
onExport?: () => void;
onOpenAR?: () => void;
onStructuralTest?: () => void;
onCelebration?: () => void;
onOpenTutorial?: () => void;
onOpenDailyChallenges?: () => void;
onOpenSettings?: () => void;
onOpenA11y?: () => void;
onOpenAudit?: () => void;
onOpenVoiceCad?: () => void;
cloudBarSlot?: ReactNode;
cloudSyncStatus?: "synced" | "syncing" | "offline" | "error";
lastSyncedText?: string;
isDashboard?: boolean;
}
export function EnterpriseTopBar({
projectName,
onProjectNameChange,
activeStudio,
onStudioChange,
onBackToDashboard,
canUndo = false,
canRedo = false,
onUndo,
onRedo,
onImport,
onExport,
onOpenAR,
onStructuralTest,
onCelebration,
onOpenTutorial,
onOpenDailyChallenges,
onOpenSettings,
onOpenA11y,
onOpenAudit,
onOpenVoiceCad,
cloudBarSlot,
cloudSyncStatus = "synced",
lastSyncedText = "Az önce eşitlendi",
isDashboard = false,
}: EnterpriseTopBarProps) {
const [editingTitle, setEditingTitle] = useState(false);
const [titleDraft, setTitleDraft] = useState(projectName);
const titleInputRef = useRef<HTMLInputElement | null>(null);
useEffect(() => {
setTitleDraft(projectName);
}, [projectName]);
const handleStartTitleEdit = () => {
setEditingTitle(true);
setTimeout(() => titleInputRef.current?.focus(), 50);
};
const handleCommitTitle = () => {
setEditingTitle(false);
const trimmed = titleDraft.trim();
if (trimmed && trimmed !== projectName) {
onProjectNameChange?.(trimmed);
} else {
setTitleDraft(projectName);
}
};
const handleTitleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
handleCommitTitle();
} else if (e.key === "Escape") {
setEditingTitle(false);
setTitleDraft(projectName);
}
};
return (
<header className="enterprise-topbar" role="banner" aria-label="SnapCAD Studio Üst Alanı">
{/* 1. Sol: Marka ve Proje Başlığı */}
<div className="topbar-section left-section">
{onBackToDashboard ? (
<button
type="button"
className="topbar-icon-btn back-btn"
onClick={onBackToDashboard}
title="Ana Sayfaya Dön"
aria-label="SnapCAD Studio Paneline Dön"
>
<ArrowLeft size={18} aria-hidden="true" />
</button>
) : null}
<a href="./" className="enterprise-brand" aria-label="SnapCAD Studio">
<div className="brand-logo-gem" aria-hidden="true">
<Box size={18} className="text-white" />
</div>
<div className="brand-text-col">
<span className="brand-title">
SnapCAD <span className="text-sky-400 font-bold">Studio</span>
</span>
<span className="brand-subtitle uppercase">YakHub Kurumsal Tasarım Platformu</span>
</div>
</a>
{!isDashboard ? (
<div className="project-title-cluster">
<div className="divider-vert" />
{editingTitle ? (
<input
ref={titleInputRef}
type="text"
className="project-title-input font-semibold"
value={titleDraft}
onChange={(e) => setTitleDraft(e.target.value)}
onBlur={handleCommitTitle}
onKeyDown={handleTitleKeyDown}
maxLength={80}
aria-label="Proje Adını Düzenle"
/>
) : (
<button
type="button"
className="project-title-display-btn"
onClick={handleStartTitleEdit}
title="Proje Adını Değiştirmek İçin Tıklayın"
aria-label={`Proje Adı: ${projectName}. Düzenlemek için tıklayın`}
>
<span className="title-text truncate max-w-[180px] sm:max-w-[260px]">{projectName}</span>
<Pencil size={12} className="edit-icon text-slate-400 opacity-60" aria-hidden="true" />
</button>
)}
{/* Bulut Durumu İndikatörü */}
<div
className={`cloud-sync-badge ${cloudSyncStatus}`}
title="Bulut Senkronizasyonu: Güncel"
role="status"
aria-label="Bulut Senkronizasyonu Güncel"
>
<span className="sync-pulse" aria-hidden="true" />
<span className="sync-label hidden lg:inline">Eşitlendi</span>
</div>
</div>
) : null}
</div>
{/* 2. Orta: Stüdyo Değiştirici (Studio Switcher Pills) */}
<nav className="topbar-section center-section" aria-label="SnapCAD Studio Stüdyoları">
<div className="studio-switcher-pills" role="tablist" aria-label="Stüdyolar">
<button
type="button"
role="tab"
aria-selected={activeStudio === "3d-solid"}
className={`studio-pill ${activeStudio === "3d-solid" ? "active" : ""}`}
onClick={() => onStudioChange("3d-solid")}
title="3D Katı CAD"
>
<Box size={14} aria-hidden="true" />
<span>3D Katı CAD</span>
</button>
<button
type="button"
role="tab"
aria-selected={activeStudio === "push-pull"}
className={`studio-pill highlight-sketchup ${activeStudio === "push-pull" ? "active" : ""}`}
onClick={() => onStudioChange("push-pull")}
title="İt / Çek (Push/Pull)"
>
<MoveRight size={14} aria-hidden="true" />
<span>İt / Çek</span>
</button>
<button
type="button"
role="tab"
aria-selected={activeStudio === "drawing"}
className={`studio-pill ${activeStudio === "drawing" ? "active" : ""}`}
onClick={() => onStudioChange("drawing")}
title="Teknik Resim"
>
<Ruler size={14} aria-hidden="true" />
<span>Teknik Resim</span>
</button>
<button
type="button"
role="tab"
aria-selected={activeStudio === "circuits"}
className={`studio-pill ${activeStudio === "circuits" ? "active" : ""}`}
onClick={() => onStudioChange("circuits")}
title="Elektronik Devreler"
>
<Cpu size={14} aria-hidden="true" />
<span>Devreler</span>
</button>
<button
type="button"
role="tab"
aria-selected={activeStudio === "codeblocks"}
className={`studio-pill ${activeStudio === "codeblocks" ? "active" : ""}`}
onClick={() => onStudioChange("codeblocks")}
title="Kod Blokları"
>
<Blocks size={14} aria-hidden="true" />
<span>Kod Blokları</span>
</button>
</div>
</nav>
{/* 3. Sağ: Hızlı Eylemler, YakNet SSO Menüsü ve Erişilebilirlik */}
<div className="topbar-section right-section">
{!isDashboard ? (
<div className="quick-actions-cluster">
{/* Geri Al / İleri Al */}
<div className="history-btn-group">
<button
type="button"
className="topbar-icon-btn"
disabled={!canUndo}
onClick={onUndo}
title="Geri Al (Ctrl+Z)"
aria-label="Geri Al"
>
<Undo2 size={16} aria-hidden="true" />
</button>
<button
type="button"
className="topbar-icon-btn"
disabled={!canRedo}
onClick={onRedo}
title="İleri Al (Ctrl+Y)"
aria-label="İleri Al"
>
<Redo2 size={16} aria-hidden="true" />
</button>
</div>
<div className="divider-vert" />
{/* İçe Aktar & Dışa Aktar */}
<button
type="button"
className="topbar-action-btn import-btn"
onClick={onImport}
title="3B veya 2B Model İçe Aktar (STL, OBJ, STEP, SVG, DXF, GLB, SKF)"
aria-label="Dosya İçe Aktar"
>
<FileUp size={14} aria-hidden="true" />
<span className="hidden xl:inline">İçe Aktar</span>
</button>
<button
type="button"
className="topbar-action-btn export-btn"
onClick={onExport}
title="Modeli Dışa Aktar (STL, OBJ, STEP, DXF, SVG, GLB, SKF)"
aria-label="Dosyayı Dışa Aktar"
>
<FileDown size={14} aria-hidden="true" />
<span>Dışa Aktar</span>
</button>
{onOpenAR ? (
<button
type="button"
className="topbar-action-btn ar-btn"
onClick={onOpenAR}
title="Masa Üstünde Gör (Mobil AR & WebXR Kamera Önizleme)"
aria-label="Artırılmış Gerçeklik Masada Gör"
style={{
background: "linear-gradient(135deg, #0ea5e9, #0284c7)",
color: "#ffffff",
borderColor: "rgba(14, 165, 233, 0.4)",
fontWeight: 600,
boxShadow: "0 2px 6px rgba(14, 165, 233, 0.25)",
}}
>
<Smartphone size={14} aria-hidden="true" />
<span className="hidden lg:inline">Masamda Gör (AR)</span>
</button>
) : null}
{onStructuralTest ? (
<button
type="button"
className="topbar-action-btn structural-test-btn"
onClick={onStructuralTest}
title="Bina Statik Dayanım & Deprem Simülasyonu (Yıkım & Güvenlik Analizi)"
aria-label="Statik Dayanım ve Deprem Testi"
style={{
background: "linear-gradient(135deg, #0284c7, #4f46e5)",
color: "#ffffff",
borderColor: "rgba(56, 189, 248, 0.4)",
fontWeight: 600,
boxShadow: "0 2px 6px rgba(2, 132, 199, 0.25)",
}}
>
<Activity size={14} aria-hidden="true" />
<span className="hidden lg:inline">Statik & Deprem Testi</span>
</button>
) : null}
{onCelebration ? (
<button
type="button"
className="topbar-action-btn celebration-btn"
onClick={onCelebration}
title="Tebrik & Başarı Konfetisi Patlat (🎉)"
aria-label="Tebrik Konfetisi"
style={{
background: "linear-gradient(135deg, #10b981, #059669)",
color: "#ffffff",
borderColor: "rgba(52, 211, 153, 0.4)",
fontWeight: 600,
}}
>
<Sparkles size={14} aria-hidden="true" />
<span className="hidden xl:inline">Tebrik</span>
</button>
) : null}
{onOpenDailyChallenges ? (
<button
type="button"
className="topbar-action-btn daily-challenges-btn"
onClick={onOpenDailyChallenges}
title="Günün 3D Görevleri & XP Başarımları (Mimarlık & Bilişim)"
aria-label="Günün Görevleri"
style={{
background: "linear-gradient(135deg, #f59e0b, #ef4444)",
color: "#ffffff",
borderColor: "rgba(245, 158, 11, 0.4)",
fontWeight: 700,
boxShadow: "0 2px 6px rgba(245, 158, 11, 0.25)",
}}
>
<Trophy size={14} aria-hidden="true" />
<span className="hidden sm:inline">Günün Görevleri</span>
</button>
) : null}
{onOpenTutorial ? (
<button
type="button"
className="topbar-action-btn tutorial-btn"
onClick={onOpenTutorial}
title="SnapCAD Akademi — Detaylı ve Uygulamalı Mimari Eğitim Modülü"
aria-label="Uygulamalı Eğitim Modülü"
style={{
background: "linear-gradient(135deg, #6366f1, #8b5cf6)",
color: "#ffffff",
borderColor: "rgba(168, 85, 247, 0.4)",
fontWeight: 600,
boxShadow: "0 2px 6px rgba(99, 102, 241, 0.25)",
}}
>
<GraduationCap size={15} aria-hidden="true" />
<span className="hidden sm:inline">Uygulamalı Eğitim</span>
</button>
) : null}
</div>
) : null}
{/* YakNet Account Widget & Cloud Bar */}
<div className="yaknet-cloud-slot">{cloudBarSlot}</div>
{/* Erişilebilirlik ve Ayarlar Butonu */}
{onOpenA11y ? (
<button
type="button"
className="topbar-icon-btn a11y-trigger-btn"
onClick={onOpenA11y}
title="Erişilebilirlik, Tema ve Kılavuz Merkezi (Alt+A)"
aria-label="Erişilebilirlik ve Kılavuz Merkezi"
>
<SlidersHorizontal size={16} aria-hidden="true" />
</button>
) : null}
{/* Görme Engelli & Ekran Okuyucu Dostu İşitsel Sahne Denetçisi */}
{onOpenAudit ? (
<button
type="button"
className="topbar-icon-btn a11y-audit-btn"
onClick={onOpenAudit}
title="Görme Engelli ve Ekran Okuyucu Dostu Sahne Denetçisi (İ tuşu veya F2)"
aria-label="İşitsel & Metinsel Sahne Denetim Raporu (İ tuşu veya F2)"
style={{ color: "#38bdf8", borderColor: "rgba(56, 189, 248, 0.4)" }}
>
<Activity size={16} aria-hidden="true" />
</button>
) : null}
{/* SnapVoice — Sesli ve Komutlu CAD Asistanı */}
{onOpenVoiceCad ? (
<button
type="button"
className="topbar-icon-btn voice-cad-trigger-btn"
onClick={onOpenVoiceCad}
title="SnapVoice — Sesli ve Komutlu CAD Asistanı (V tuşu veya F4)"
aria-label="Sesli ve Komutlu CAD Asistanı (V tuşu veya F4)"
style={{ color: "#34d399", borderColor: "rgba(52, 211, 153, 0.4)" }}
>
<Mic size={16} aria-hidden="true" />
</button>
) : null}
</div>
</header>
);
}