Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icons in NumbersBlock and Sidebar Widget not updating #402

Merged
merged 9 commits into from
Nov 14, 2023
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@

- Aggiunta la possibilità di selezionare la dimensione dell'immagine nel blocco Alert, inoltre è stato aggiornato anche il widget per la selezione del colore di sfondo.

### Fix

- Le icone del Blocco Numeri e della Sidebar si aggiornano istantaneamente quando vengono cambiate

## Versione 10.3.0 (08/11/2023)

### Fix
Expand Down
47 changes: 38 additions & 9 deletions src/components/ItaliaTheme/Blocks/NumbersBlock/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,33 @@ class Edit extends SubblocksEdit {
constructor(props) {
super(props);
this.state.selectedField = 'title';

this.state = {
...this.state,
icon1: '',
icon2: '',
icon3: '',
};
pnicolli marked this conversation as resolved.
Show resolved Hide resolved
}

componentDidMount() {
this.setIconValues(this.props.data);
}

componentDidUpdate(prevProps) {
if (prevProps.data !== this.props.data) {
this.setIconValues(this.props.data);
}
}

setIconValues(data) {
this.setState({
icon1: data.icon1,
icon2: data.icon2,
icon3: data.icon3,
});
}

/**
* Render method.
* @method render
Expand Down Expand Up @@ -89,15 +115,18 @@ class Edit extends SubblocksEdit {
this.props.data.icon2 ||
this.props.data.icon3 ? (
<div className="icons">
{this.props.data.icon1?.length > 0 && (
<Icon icon={this.props.data.icon1} />
)}
{this.props.data.icon2?.length > 0 && (
<Icon icon={this.props.data.icon2} />
)}
{this.props.data.icon3?.length > 0 && (
<Icon icon={this.props.data.icon3} />
)}
{this.state.icon1?.length > 0 &&
this.state.icon1 === this.props.data.icon1 && (
<Icon icon={this.state.icon1} />
)}
{this.state.icon2?.length > 0 &&
this.state.icon2 === this.props.data.icon2 && (
<Icon icon={this.state.icon2} />
)}
{this.state.icon3?.length > 0 &&
this.state.icon3 === this.props.data.icon3 && (
<Icon icon={this.state.icon3} />
)}
</div>
) : (
<div className="icons placeholder">
Expand Down
41 changes: 24 additions & 17 deletions src/components/ItaliaTheme/manage/Widgets/IconPreviewWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { FontAwesomeIcon } from 'design-comuni-plone-theme/components/ItaliaTheme';
import { defineMessages, useIntl } from 'react-intl';
Expand All @@ -14,6 +14,12 @@ const messages = defineMessages({
const IconPreviewWidget = ({ icon, onEdit, title, description, children }) => {
const intl = useIntl();
const parts = icon?.split(' ') ?? [];
const [iconValue, setIconValue] = useState('');

useEffect(() => {
setIconValue(icon);
}, [icon]);

return (
<Form.Field inline className="help" id="icon-preview-widget-id">
<Grid>
Expand All @@ -26,22 +32,23 @@ const IconPreviewWidget = ({ icon, onEdit, title, description, children }) => {
<Grid.Column width={8}>
<div className="ui input flex-center">
<p className="help">
{icon ? (
<>
{parts.length > 1 ? (
<FontAwesomeIcon
icon={[parts[0], parts[1]]}
className="show-icon"
/>
) : (
<FontAwesomeIcon icon={icon} className="show-icon" />
)}
</>
) : (
<span>
{intl.formatMessage(messages.previewIconSelected)}
</span>
)}
{icon === iconValue &&
(icon ? (
<>
{parts.length > 1 ? (
<FontAwesomeIcon
icon={[parts[0], parts[1]]}
className="show-icon"
/>
) : (
<FontAwesomeIcon icon={icon} className="show-icon" />
)}
</>
) : (
<span>
{intl.formatMessage(messages.previewIconSelected)}
</span>
))}
</p>
</div>
</Grid.Column>
Expand Down