Skip to content

Commit

Permalink
minor fixes and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Medesan committed Nov 9, 2020
1 parent b6d8f1d commit e4a5c66
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/components/manage/Blocks/Group/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const Edit = (props) => {
properties.blocks_layout.items[0] !== selectedBlock
) {
setSelectedBlock(properties.blocks_layout.items[0]);
console.log('block', block)
console.log('data', data)
onChangeBlock(block, {
...data,
data: properties,
Expand All @@ -43,19 +45,22 @@ const Edit = (props) => {
let charCount = 0;

const showCharCounter = () => {
Object.keys(props.data.data.blocks).forEach(blockId => {
charCount = charCount + props.data.data.blocks[blockId]?.plaintext?.length || 0
})
if(props.data?.data?.blocks) {
Object.keys(props.data?.data?.blocks).forEach(blockId => {
charCount = charCount + props.data.data.blocks[blockId]?.plaintext?.length || 0
})
}
}
showCharCounter()

const colors = { ok: '#CCC', warning: 'darkorange', danger: 'crimson' };
const counterStyle = {
color: charCount < Math.ceil(props.data.maxChars/1.05) ?
colors.ok :
charCount < props.data.maxChars ?
colors.warning :
colors.danger,
'text-align': 'end'
'textAlign': 'end'
};
const counterComponent =
(props.data.maxChars ?
Expand All @@ -64,12 +69,12 @@ const Edit = (props) => {
props.data.maxChars ?
props.data.maxChars - charCount < 0 ?
(<>
<Icon name={dissatisfiedSVG} size="24px" />
{`${charCount - props.data.maxChars} characters over the limit`}
<Icon name={dissatisfiedSVG} size="24px" />
</>) :
(<>
<Icon name={delightedSVG} size="24px" />
{`${props.data.maxChars - charCount } characters remaining out of ${props.data.maxChars}`}
<Icon name={delightedSVG} size="24px" />
</>) :
charCount
}
Expand Down

0 comments on commit e4a5c66

Please sign in to comment.