mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Also color-code editor pane titles with their git state
This commit is contained in:
1 parent
a46b3deeb8
commit
ae0dc50b02
2 files changed
+32
-2
No files matched your search
@@ -4,18 +4,21 @@ import { Textarea } from '@/components/ui/textarea';
|
|||||||
import { CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Save, Loader2 } from 'lucide-react';
|
import { Save, Loader2 } from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
|
|
||||||
interface FileEditorProps {
|
interface FileEditorProps {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
content: string;
|
content: string;
|
||||||
onSave: (content: string) => void;
|
onSave: (content: string) => void;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
projectId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FileEditor({ filePath, content, onSave, isLoading }: FileEditorProps) {
|
export function FileEditor({ filePath, content, onSave, isLoading, projectId }: FileEditorProps) {
|
||||||
const [editedContent, setEditedContent] = useState(content);
|
const [editedContent, setEditedContent] = useState(content);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
const [hasChanges, setHasChanges] = useState(false);
|
const [hasChanges, setHasChanges] = useState(false);
|
||||||
|
const { data: gitStatus } = useGitStatus(projectId || null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEditedContent(content);
|
setEditedContent(content);
|
||||||
@@ -64,11 +67,36 @@ export function FileEditor({ filePath, content, onSave, isLoading }: FileEditorP
|
|||||||
return 'font-mono text-sm';
|
return 'font-mono text-sm';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to get git status for the current file
|
||||||
|
const getFileGitStatus = (filePath: string) => {
|
||||||
|
if (!gitStatus?.changedFiles) return null;
|
||||||
|
const fileChange = gitStatus.changedFiles.find(change => change.filepath === filePath);
|
||||||
|
return fileChange?.status || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to get styling classes based on git status
|
||||||
|
const getGitStatusClasses = (status: string | null) => {
|
||||||
|
switch (status) {
|
||||||
|
case 'added':
|
||||||
|
case 'untracked':
|
||||||
|
return 'text-green-600 dark:text-green-400';
|
||||||
|
case 'modified':
|
||||||
|
case 'staged':
|
||||||
|
return 'text-yellow-600 dark:text-yellow-400';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get git status for the current file
|
||||||
|
const currentFileGitStatus = getFileGitStatus(filePath);
|
||||||
|
const gitStatusClasses = getGitStatusClasses(currentFileGitStatus);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col">
|
<div className="h-full flex flex-col">
|
||||||
<CardHeader className="border-b py-2 sm:py-3">
|
<CardHeader className="border-b py-2 sm:py-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<CardTitle className="text-sm sm:text-base truncate flex-1 mr-2">{filePath}</CardTitle>
|
<CardTitle className={cn("text-sm sm:text-base truncate flex-1 mr-2", gitStatusClasses)}>{filePath}</CardTitle>
|
||||||
<div className="flex items-center space-x-1 sm:space-x-2">
|
<div className="flex items-center space-x-1 sm:space-x-2">
|
||||||
{hasChanges && (
|
{hasChanges && (
|
||||||
<span className="text-xs sm:text-sm text-muted-foreground hidden sm:inline">Unsaved changes</span>
|
<span className="text-xs sm:text-sm text-muted-foreground hidden sm:inline">Unsaved changes</span>
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
content={fileContent}
|
content={fileContent}
|
||||||
onSave={handleFileSave}
|
onSave={handleFileSave}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
projectId={projectId}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-full flex items-center justify-center">
|
<div className="h-full flex items-center justify-center">
|
||||||
@@ -430,6 +431,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
content={fileContent}
|
content={fileContent}
|
||||||
onSave={handleFileSave}
|
onSave={handleFileSave}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
projectId={projectId}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-full flex items-center justify-center">
|
<div className="h-full flex items-center justify-center">
|
||||||
|
|||||||
Reference in new issue
Block a user