Skip to content

Commit

Permalink
[feat]: update add file
Browse files Browse the repository at this point in the history
  • Loading branch information
pizn committed Jan 19, 2016
1 parent 662a5ba commit c0a590a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
27 changes: 23 additions & 4 deletions src/components/Desktop/AddFile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CreateFileForm extends Component {
]}>
<Form horizontal>
<FormItem
label="文件名:"
label="URL:"
labelCol={{span: 6}}
wrapperCol={{span: 14}}
validateStatus={getFieldError('name') ? 'error' : 'success'}
Expand All @@ -32,7 +32,7 @@ class CreateFileForm extends Component {
type: "string",
required: true,
pattern: /^(((?:19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-)+([a-zA-Z0-9-_])+(\.md|\.markdown|\.mdown|\.mkd|\.mkdown|\.ron|\.txt)$/,
message: "请输入文章 URL例如: 2016-01-18-hello-world.md"
message: "请输入 URL, 例如: 2016-01-18-hello-world.md"
},
]})}
/>
Expand All @@ -41,12 +41,12 @@ class CreateFileForm extends Component {
</Col>
</FormItem>
<FormItem
label="文章标题:"
label="标题:"
labelCol={{span: 6}}
wrapperCol={{span: 14}}
validateStatus={getFieldError('title') ? 'error' : 'success'}
>
<Input type="text" name="title" autoComplete="off"
<Input type="text" name="title" autoComplete="off" placeholder="文章标题"
{...getFieldProps('title', {
rules: [{
type: "string",
Expand All @@ -59,6 +59,25 @@ class CreateFileForm extends Component {
<p className="ant-form-explain">{getFieldError('title') ? getFieldError('title').join('') : ''}</p>
</Col>
</FormItem>
<FormItem
label="描述:"
labelCol={{span: 6}}
wrapperCol={{span: 14}}
validateStatus={getFieldError('description') ? 'error' : 'success'}
>
<Input type="textarea" name="description" autoComplete="off" rows="5" placeholder="这是一篇关于...的文章"
{...getFieldProps('description', {
rules: [{
type: "string",
required: true,
message: "请输入文章描述"
},
]})}
/>
<Col span="24">
<p className="ant-form-explain">{getFieldError('description') ? getFieldError('description').join('') : ''}</p>
</Col>
</FormItem>
</Form>
</Modal>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Post/Head.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Head extends Component {
<Icon type="ellipsis" />
</div>
<ul className="action-list-dropdown">
<li className="item"><a href={blob.data.html_url} target="_blank"><Icon type="file-text" /> 源文件</a></li>
<li className="item"><a href={blob.data.html_url} target="_blank"><Icon type="code" /> 源文件</a></li>
<li className="item"><a onClick={this.remove.bind(this)}><Icon type="delete" /> 删除</a></li>
</ul>
</div>
Expand Down
10 changes: 9 additions & 1 deletion src/containers/Desktop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ class Desktop extends Component {
handleAddFile(file) {
event.preventDefault();
const { dispatch, user, history, repoInfo } = this.props;

const content = '---\n' +
'layout: post\n' +
'title: ' + file.title + '\n' +
'description: ' + file.description + '\n' +
'---\n' +
'# ';

const repo = {
username: user.data.login,
email: user.data.email,
reponame: repoInfo.data.name,
path: '_posts/' + file.name,
content: '',
content: content,
}
this.setState({
addFile: false
Expand Down
7 changes: 2 additions & 5 deletions src/services/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ const Repo = {
author: {name: data.username, email: data.email},
committer: {name: data.username, email: data.email},
}
const content = '---\n' +
'layout: post\n' +
'title: new post\n' +
'description: description\n\n---\n\n# title';


return new Promise((resolve, reject) => {
repo.write('master', data.path, content, '[Leafeon]: Add post', options, (err, file) => {
repo.write('master', data.path, data.content, '[Leafeon]: Add post', options, (err, file) => {
if (err) {
reject(err);
} else {
Expand Down

0 comments on commit c0a590a

Please sign in to comment.