Skip to content

Commit 71d17ae

Browse files
committed
fix: Fix the path issue when creating files
-取消创建后自动跳转 -修复原本一系列路径拼接问题
1 parent c702cbf commit 71d17ae

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

moon/apps/web/components/CodeView/BlobView/BlobEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export default function BlobEditor({ fileContent, filePath, fileName, onCancel }
324324
className='h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500'
325325
disabled={updateBlobMutation.isPending}
326326
/>
327-
<label htmlFor='skipBuild' className='text-sm font-medium text-gray-700'>
327+
<label htmlFor='skipBuild_editor' className='text-sm font-medium text-gray-700'>
328328
Skip automatic build after commit
329329
</label>
330330
</div>

moon/apps/web/components/CodeView/NewCodeView/NewCodeView.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ const NewCodeView = ({ currentPath = '', onClose, defaultType = 'file' }: NewCod
3030
const { data: currentUser } = useGetCurrentUser()
3131

3232
const handleSubmit = () => {
33+
let entryPath = path
34+
35+
if (entryPath.endsWith('/' + name)) {
36+
entryPath = entryPath.slice(0, -(name.length + 1))
37+
}
38+
entryPath = entryPath || '/'
39+
3340
createEntryHook.mutate(
3441
{
3542
name: name,
36-
path: currentPath,
43+
path: entryPath,
3744
is_directory: fileType === 'folder',
3845
content: fileType === 'file' ? content : '',
3946
author_email: currentUser?.email,
@@ -101,7 +108,6 @@ const NewCodeView = ({ currentPath = '', onClose, defaultType = 'file' }: NewCod
101108
{/*The second parameter of MarkdownEditor is to disable the editor, which is currently hidden directly. */}
102109
{fileType === 'file' && (
103110
<div className='w-full flex-1 overflow-y-auto'>
104-
{/*<MarkdownEditor contentState={[content, setContent]} disabled={fileType === 'folder'} />*/}
105111
<MarkdownEditor contentState={[content, setContent]} disabled={false} />
106112
</div>
107113
)}
@@ -123,7 +129,7 @@ const NewCodeView = ({ currentPath = '', onClose, defaultType = 'file' }: NewCod
123129
className='h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500'
124130
disabled={createEntryHook.isPending}
125131
/>
126-
<label htmlFor='skipBuild' className='text-sm font-medium text-gray-700'>
132+
<label htmlFor='skipBuild_creat' className='text-sm font-medium text-gray-700'>
127133
Skip automatic build after commit
128134
</label>
129135
</div>

moon/apps/web/components/CodeView/NewCodeView/PathInput.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export default function PathInput({ pathState, nameState }: PathInputProps) {
2121
// update pathState
2222
const updatePath = (b: string[], u: string[], c: string) => {
2323
const full = [...b, ...u, c].filter(Boolean).join('/')
24-
const userInput = [...u, c].filter(Boolean).join('/')
2524

2625
setPath(full)
27-
setName(userInput || c)
26+
setName(c) // Update name when path changes
2827
}
2928

3029
useEffect(() => {

moon/apps/web/pages/[org]/code/tree/[version]/[...path]/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,7 @@ function TreeDetailPage() {
174174
</div>
175175
) : (
176176
<div className='pb-18 bg-primary flex-1 overflow-hidden'>
177-
<NewCodeView
178-
currentPath={new_path}
179-
onClose={handleCloseClick}
180-
defaultType={newEntryType}
181-
version={version}
182-
/>
177+
<NewCodeView currentPath={new_path} onClose={handleCloseClick} defaultType={newEntryType} />
183178
</div>
184179
)}
185180
</div>

0 commit comments

Comments
 (0)