Skip to content

Commit

Permalink
update draft types (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet authored Jul 11, 2018
1 parent 5b93020 commit e5be8ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/client/components/Sidebar/LastDrafts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage, FormattedRelative } from 'react-intl';
import { Link } from 'react-router-dom';
import { draftType, draftArrayType } from '../../types/drafts';
import Loading from '../../components/Icon/Loading';
import './LastDrafts.less';
import './SidebarContentBlock.less';
Expand All @@ -21,7 +22,7 @@ const Draft = ({ draft }) => (
</div>
);
Draft.propTypes = {
draft: PropTypes.shape().isRequired,
draft: draftType.isRequired,
};

const LastDrafts = ({ drafts, loaded }) => {
Expand Down Expand Up @@ -55,7 +56,7 @@ const LastDrafts = ({ drafts, loaded }) => {
};

LastDrafts.propTypes = {
drafts: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string, title: PropTypes.string })),
drafts: draftArrayType,
loaded: PropTypes.bool,
};

Expand Down
9 changes: 5 additions & 4 deletions src/client/post/Write/DraftRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import _ from 'lodash';
import { FormattedMessage, FormattedRelative } from 'react-intl';
import { Link } from 'react-router-dom';
import { Checkbox } from 'antd';
import { draftType } from '../../types/drafts';
import DeleteDraftModal from './DeleteDraftModal';
import './DraftRow.less';

class DraftRow extends React.Component {
static propTypes = {
id: PropTypes.string.isRequired,
data: PropTypes.shape().isRequired,
draft: draftType.isRequired,
selected: PropTypes.bool,
onCheck: PropTypes.func,
};
Expand Down Expand Up @@ -46,10 +47,10 @@ class DraftRow extends React.Component {
}

render() {
const { id, data, selected } = this.props;
const { lastUpdated } = data;
const { id, draft, selected } = this.props;
const { lastUpdated } = draft;
const hasLastUpdated = !_.isUndefined(lastUpdated);
let { title = '', body = '' } = data;
let { title = '', body = '' } = draft;
title = title.trim();
body = body.replace(/\r?\n|\r|[\u200B-\u200D\uFEFF]/g, ' ').substring(0, 50);
let draftTitle = title.length ? title : body;
Expand Down
2 changes: 1 addition & 1 deletion src/client/post/Write/Drafts.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Drafts extends React.Component {
_.map(sortedDraftPosts, draft => (
<DraftRow
key={draft.id}
data={draft}
draft={draft}
id={draft.id}
selected={selectedDrafts.includes(draft.id)}
pending={pendingDrafts.includes(draft.id)}
Expand Down
10 changes: 10 additions & 0 deletions src/client/types/drafts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import PropTypes from 'prop-types';

export const draftType = PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
lastUpdated: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
title: PropTypes.string,
body: PropTypes.string,
});

export const draftArrayType = PropTypes.arrayOf(draftType);

0 comments on commit e5be8ce

Please sign in to comment.