Skip to content

Commit

Permalink
[feat]: update delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
pizn committed Jan 19, 2016
1 parent f77ffcb commit 662a5ba
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/actions/LeafActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function removeRepoBlob(data) {
return {
types: [types.REMOVE_REPO_BLOB, types.REMOVE_REPO_BLOB_SUCCESS, types.REMOVE_REPO_BLOB_FAIL],
promise: repo.removeBlob(data),
data,
}
}

Expand Down
24 changes: 21 additions & 3 deletions src/components/Desktop/AddFile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class CreateFileForm extends Component {
render() {
const { modalVisible, modalHandleOk, modalHandleCancel, form } = this.props;
const { getFieldProps, getFieldError } = form;
const timeNow = new Date();
return (
<Modal ref="modal"
visible={modalVisible}
Expand All @@ -22,7 +21,7 @@ class CreateFileForm extends Component {
]}>
<Form horizontal>
<FormItem
label="名称:"
label="文件名:"
labelCol={{span: 6}}
wrapperCol={{span: 14}}
validateStatus={getFieldError('name') ? 'error' : 'success'}
Expand All @@ -33,14 +32,33 @@ 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: "例子: 2016-01-18-hello-world.md"
message: "请输入文章 URL。例如: 2016-01-18-hello-world.md"
},
]})}
/>
<Col span="24">
<p className="ant-form-explain">{getFieldError('name') ? getFieldError('name').join('') : ''}</p>
</Col>
</FormItem>
<FormItem
label="文章标题:"
labelCol={{span: 6}}
wrapperCol={{span: 14}}
validateStatus={getFieldError('title') ? 'error' : 'success'}
>
<Input type="text" name="title" autoComplete="off"
{...getFieldProps('title', {
rules: [{
type: "string",
required: true,
message: "请输入文章标题"
},
]})}
/>
<Col span="24">
<p className="ant-form-explain">{getFieldError('title') ? getFieldError('title').join('') : ''}</p>
</Col>
</FormItem>
</Form>
</Modal>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Desktop/Aside.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Aside extends Component {
</Col>
<ul className="foot-user-actions">
<li className="item">
<a onClick={this.logout.bind(this)} ><Icon type="logout" /> 登出</a>
<a onClick={this.logout.bind(this)} >登出 <Icon type="logout" /></a>
</li>
</ul>
</Row>
Expand Down
10 changes: 6 additions & 4 deletions src/components/Post/Head.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ class Head extends Component {
{meta && meta.title} <Icon type="caret-down" />
</div>
<div className="meta-card">
<Row className="meta-card-item">
<Col span="4" className="name">描述:</Col>
<Col span="20" className="cnt">{meta.description}</Col>
</Row>
{ meta.description &&
<Row className="meta-card-item">
<Col span="4" className="name">描述:</Col>
<Col span="20" className="cnt">{meta.description}</Col>
</Row>
}
{ meta.categories &&
<Row className="meta-card-item">
<Col span="4" className="name">分类:</Col>
Expand Down
13 changes: 7 additions & 6 deletions src/containers/Desktop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Desktop extends Component {

constructor(props) {
super(props);
const { auth } = props;
this.state = {
addFile: false
}
Expand Down Expand Up @@ -61,12 +60,14 @@ class Desktop extends Component {
dispatch(actions.readRepoTree(repo));
});
} else {
const repo = {
username: this.props.user.data.login,
reponame: this.props.repoInfo.data.name,
path: '_posts',
if (!tree.loaded) {
const repo = {
username: this.props.user.data.login,
reponame: this.props.repoInfo.data.name,
path: '_posts',
}
dispatch(actions.readRepoTree(repo));
}
dispatch(actions.readRepoTree(repo));
}
}
dispatch(actions.clearRepoBlob());
Expand Down
10 changes: 4 additions & 6 deletions src/containers/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ class Post extends Component {
dispatch(actions.updateRepoBlob(repo))
.then(() => {
msg();
//if (this.props.blob.updated) {
// message.success('已更新');
//} else {
// message.error('未更新');
//}
});
}

Expand Down Expand Up @@ -156,9 +151,12 @@ class Post extends Component {
reponame: repoInfo.data.name,
path: '_posts/' + params.name
}
const msg = message.loading('正在删除...', 0);

dispatch(actions.removeRepoBlob(repo))
.then(() => {
message.success('删除成功');
msg();
//message.success('删除成功');
})
.then(() => {
history.pushState(null, '_posts/');
Expand Down
14 changes: 11 additions & 3 deletions src/reducers/Tree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { READ_REPO_TREE, READ_REPO_TREE_SUCCESS, READ_REPO_TREE_FAIL, ADD_REPO_BLOB, ADD_REPO_BLOB_SUCCESS, ADD_REPO_BLOB_FAIL, AUTH_LOGOUT } from '../constants/LeafActionTypes';
import { READ_REPO_TREE, READ_REPO_TREE_SUCCESS, READ_REPO_TREE_FAIL, ADD_REPO_BLOB, ADD_REPO_BLOB_SUCCESS, ADD_REPO_BLOB_FAIL, AUTH_LOGOUT, REMOVE_REPO_BLOB } from '../constants/LeafActionTypes';

const initialState = {
loaded: false,
data: {}
data: []
};

export default function tree(state = initialState, action) {
Expand Down Expand Up @@ -50,7 +50,15 @@ export default function tree(state = initialState, action) {
case AUTH_LOGOUT:
return {
loaded: false,
data: {},
data: [],
}
case REMOVE_REPO_BLOB:
console.log(action.data);
return {
...state,
data: state.data.filter(item => {
return item.path !== action.data.path;
}),
}
default:
return state;
Expand Down
3 changes: 2 additions & 1 deletion src/styles/leaf.less
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
display: inline-block;
height: 48px;
line-height: 48px;
width: auto;
width: 48px;
color: #999;
}

Expand Down Expand Up @@ -506,6 +506,7 @@
display: block;
cursor: pointer;
padding: 8px 32px;
line-height: 24px;
text-align: center;
background: lighten(@primary-color, 34%);
border-top: 1px solid @border-color;
Expand Down

0 comments on commit 662a5ba

Please sign in to comment.