Files
openchamber/packages/ui/src/components/layout/RightSidebarTabs.tsx
T

63 lines
2.0 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { ProjectNotesTodoPanel } from '@/components/session/ProjectNotesTodoPanel';
import { useGitStore } from '@/stores/useGitStore';
import { useProjectsStore } from '@/stores/useProjectsStore';
import { useDirectoryStore } from '@/stores/useDirectoryStore';
import { formatDirectoryName } from '@/lib/utils';
export const ProjectContextPanel: React.FC<{
onActionComplete?: () => void;
onOpenPlan?: (plan: { path: string; title: string }) => void;
}> = ({ onActionComplete, onOpenPlan }) => {
const activeProjectId = useProjectsStore((state) => state.activeProjectId);
const projects = useProjectsStore((state) => state.projects);
const homeDirectory = useDirectoryStore((state) => state.homeDirectory);
const gitDirectories = useGitStore((state) => state.directories);
const activeProject = React.useMemo(() => {
if (activeProjectId) {
return projects.find((project) => project.id === activeProjectId) ?? projects[0] ?? null;
}
return projects[0] ?? null;
}, [activeProjectId, projects]);
const projectRef = React.useMemo(() => {
if (!activeProject) {
return null;
}
return {
id: activeProject.id,
path: activeProject.path,
};
}, [activeProject]);
const projectLabel = React.useMemo(() => {
if (!activeProject) {
return null;
}
return activeProject.label?.trim()
|| formatDirectoryName(activeProject.path, homeDirectory)
|| activeProject.path;
}, [activeProject, homeDirectory]);
const canCreateWorktree = React.useMemo(() => {
if (!activeProject) {
return false;
}
return gitDirectories.get(activeProject.path)?.isGitRepo === true;
}, [activeProject, gitDirectories]);
return (
<div className="h-full min-h-0 overflow-auto bg-background">
<ProjectNotesTodoPanel
projectRef={projectRef}
projectLabel={projectLabel}
canCreateWorktree={canCreateWorktree}
onActionComplete={onActionComplete}
onOpenPlan={onOpenPlan}
/>
</div>
);
};