mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-05 05:57:50 +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);
|
return String(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) => {
|
export const useCodeEditorDocument = ({ file, projectPath }: UseCodeEditorDocumentParams) => {
|
||||||
const [content, setContent] = useState('');
|
const [content, setContent] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [saveSuccess, setSaveSuccess] = useState(false);
|
const [saveSuccess, setSaveSuccess] = useState(false);
|
||||||
const [saveError, setSaveError] = useState<string | null>(null);
|
const [saveError, setSaveError] = useState<string | null>(null);
|
||||||
const fileProjectName = file.projectName;
|
const fileProjectName = file.projectName ?? projectPath;
|
||||||
const filePath = file.path;
|
const filePath = file.path;
|
||||||
const fileName = file.name;
|
const fileName = file.name;
|
||||||
const fileDiffNewString = file.diffInfo?.new_string;
|
const fileDiffNewString = file.diffInfo?.new_string;
|
||||||
@@ -39,6 +39,10 @@ export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) =>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fileProjectName) {
|
||||||
|
throw new Error('Missing project identifier');
|
||||||
|
}
|
||||||
|
|
||||||
const response = await api.readFile(fileProjectName, filePath);
|
const response = await api.readFile(fileProjectName, filePath);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to load file: ${response.status} ${response.statusText}`);
|
throw new Error(`Failed to load file: ${response.status} ${response.statusText}`);
|
||||||
@@ -63,6 +67,10 @@ export const useCodeEditorDocument = ({ file }: UseCodeEditorDocumentParams) =>
|
|||||||
setSaveError(null);
|
setSaveError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!fileProjectName) {
|
||||||
|
throw new Error('Missing project identifier');
|
||||||
|
}
|
||||||
|
|
||||||
const response = await api.saveFile(fileProjectName, filePath, content);
|
const response = await api.saveFile(fileProjectName, filePath, content);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user