Skip to content

Commit

Permalink
fixed counter for new props schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Medesan committed Dec 29, 2020
1 parent 06a5b74 commit 6005d82
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/components/manage/Blocks/Group/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Icon } from '@plone/volto/components';
import delightedSVG from '@plone/volto/icons/delighted.svg';
import dissatisfiedSVG from '@plone/volto/icons/dissatisfied.svg';
import { isEmpty } from 'lodash';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import './editor.less';

Expand Down Expand Up @@ -46,7 +47,8 @@ const Edit = (props) => {
if (props.data?.data?.blocks) {
Object.keys(props.data?.data?.blocks).forEach((blockId) => {
charCount =
charCount + props.data.data.blocks[blockId]?.plaintext?.length || 0;
charCount +
(props.data.data.blocks[blockId]?.text?.blocks[0]?.text?.length || 0);
});
}
};
Expand All @@ -62,26 +64,23 @@ const Edit = (props) => {
: colors.danger,
textAlign: 'end',
};

const counterComponent = props.data.maxChars ? (
<p style={counterStyle} className="counter">
{props.data.maxChars ? (
props.data.maxChars - charCount < 0 ? (
<>
<span>{`${
charCount - props.data.maxChars
} characters over the limit`}</span>
<Icon name={dissatisfiedSVG} size="24px" />
</>
) : (
<>
<span>{`${
props.data.maxChars - charCount
} characters remaining out of ${props.data.maxChars}`}</span>
<Icon name={delightedSVG} size="24px" />
</>
)
{props.data.maxChars - charCount < 0 ? (
<>
<span>{`${
charCount - props.data.maxChars
} characters over the limit`}</span>
<Icon name={dissatisfiedSVG} size="24px" />
</>
) : (
charCount
<>
<span>{`${
props.data.maxChars - charCount
} characters remaining out of ${props.data.maxChars}`}</span>
<Icon name={delightedSVG} size="24px" />
</>
)}
</p>
) : null;
Expand Down Expand Up @@ -123,4 +122,13 @@ const Edit = (props) => {
);
};

Edit.propTypes = {
block: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
onChangeBlock: PropTypes.func.isRequired,
pathname: PropTypes.string.isRequired,
selected: PropTypes.bool.isRequired,
manage: PropTypes.bool.isRequired,
};

export default Edit;

0 comments on commit 6005d82

Please sign in to comment.