Skip to content

Commit

Permalink
fix current source edit
Browse files Browse the repository at this point in the history
  • Loading branch information
juandjara committed Oct 13, 2023
1 parent 23bd548 commit 0d4077d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 7 additions & 6 deletions app/components/source-files/FileDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Form, Link, useLoaderData, useNavigation, useParams } from '@remix-run/
import { buttonCN } from '@/lib/styles'
import { getBasename, getDirname } from '@/lib/pathUtils'
import clsx from 'clsx'
import { FolderOpenIcon } from '@heroicons/react/20/solid'
import { DocumentIcon } from '@heroicons/react/24/outline'
import FileActionsMenu from '../file-actions/FileActionsMenu'
import type { FileModalData } from '../file-actions/FileActionsModal'
import FileActionsModal from '../file-actions/FileActionsModal'
Expand Down Expand Up @@ -37,7 +37,7 @@ function FileContents({ file }: { file?: ParsedFile }) {
if (!file || file.isMarkdown) {
return (
<FileEditor
name="markdown"
name="body"
isMarkdown={file ? file.isMarkdown : true}
initialValue={tempContent || file?.content || ''}
onChange={setTempContent}
Expand Down Expand Up @@ -70,7 +70,7 @@ function FileContents({ file }: { file?: ParsedFile }) {

return (
<FileEditor
name="markdown"
name="body"
isMarkdown={file?.isMarkdown}
initialValue={tempContent || file?.content || ''}
onChange={setTempContent}
Expand Down Expand Up @@ -99,6 +99,8 @@ export default function FileDetails() {
redirectTarget="source"
/>
)}
<input type="hidden" name="sha" value={file?.sha} />
<input type="hidden" name="path" value={file?.path} />
<header className='relative flex items-center justify-start gap-2'>
<Link
className={clsx(buttonCN.cancel, buttonCN.small, buttonCN.iconSmall)}
Expand All @@ -107,8 +109,8 @@ export default function FileDetails() {
<BackIcon />
</Link>
<div className='bg-white dark:bg-slate-700 text-slate-500 dark:text-slate-200 flex-grow min-w-0 py-1 px-2 rounded-md flex items-center gap-2'>
<FolderOpenIcon className="w-5 h-5" />
<span className='truncate'>
<DocumentIcon className="w-5 h-5" />
<span className='truncate'>
{folder && (
<span className='text-slate-400 dark:text-slate-500'>{folder}/</span>
)}
Expand All @@ -131,7 +133,6 @@ export default function FileDetails() {
/>
</header>
<div className='my-4'>
<input type="hidden" name="sha" value={file?.sha} />
<p className='mb-4'>
Want to edit this file with the advanced markdown editor?
Add the file to a <Link className='underline' to={`../settings`}>collection</Link> and edit it there.
Expand Down
14 changes: 5 additions & 9 deletions app/routes/p/$project/source/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ export async function action({ request, params }: ActionArgs) {
const { token } = await requireUserSession(request)
const { branch, repo } = await getProject(Number(params.project))
const formData = await request.formData()
const name = formData.get('filename') as string
const body = formData.get('markdown') as string
const body = formData.get('body') as string
const name = formData.get('name') as string
const path = formData.get('path') as string
const sha = formData.get('sha') as string | undefined

if (!name) {
throw new Response(`"filename" param is required in form data`, { status: 400, statusText: 'Bad Request' })
}

const isNew = !sha
const message = isNew
? `Create file ${path + name}`
: `Update file ${path + name}`
const fullPath = (path || '') + name
const message = isNew
? `Create file ${fullPath}`
: `Update file ${fullPath}`

try {
await saveFile(token, {
Expand Down

0 comments on commit 0d4077d

Please sign in to comment.