mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-04 21:47:43 +00:00
fix(code-editor): handle missing project identifier in useCodeEditorDocument
This commit is contained in:
@@ -15,13 +15,13 @@ const getErrorMessage = (error: unknown) => {
|
||||
return String(error);
|
||||
};
|
||||
|
||||
export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) => {
|
||||
export const useCodeEditorDocument = ({ file, projectPath }: UseCodeEditorDocumentParams) => {
|
||||
const [content, setContent] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saveSuccess, setSaveSuccess] = useState(false);
|
||||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
const fileProjectName = file.projectName;
|
||||
const fileProjectName = file.projectName ?? projectPath;
|
||||
const filePath = file.path;
|
||||
const fileName = file.name;
|
||||
const fileDiffNewString = file.diffInfo?.new_string;
|
||||
@@ -39,6 +39,10 @@ export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) =>
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fileProjectName) {
|
||||
throw new Error('Missing project identifier');
|
||||
}
|
||||
|
||||
const response = await api.readFile(fileProjectName, filePath);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load file: ${response.status} ${response.statusText}`);
|
||||
@@ -63,6 +67,10 @@ export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) =>
|
||||
setSaveError(null);
|
||||
|
||||
try {
|
||||
if (!fileProjectName) {
|
||||
throw new Error('Missing project identifier');
|
||||
}
|
||||
|
||||
const response = await api.saveFile(fileProjectName, filePath, content);
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user