diff --git a/pkg/interface/chat/src/js/components/settings.js b/pkg/interface/chat/src/js/components/settings.js index 2d8b73a0a7..ec87926fc1 100644 --- a/pkg/interface/chat/src/js/components/settings.js +++ b/pkg/interface/chat/src/js/components/settings.js @@ -31,7 +31,7 @@ export class SettingsScreen extends Component { this.setState({ title: props.association.metadata.title, description: props.association.metadata.description, - color: uxToHex(props.association.metadata.color) + color: `#${uxToHex(props.association.metadata.color)}` }); } } @@ -47,14 +47,48 @@ export class SettingsScreen extends Component { }); } - if ((this.state.title === "") && (prevProps !== this.props)) { + if ((state.title === "") && (prevProps !== props)) { if (props.association && "metadata" in props.association) this.setState({ title: props.association.metadata.title, description: props.association.metadata.description, - color: uxToHex(props.association.metadata.color) + color: `#${uxToHex(props.association.metadata.color)}` }); } + + if (state.color !== prevState.color) { + //submit color if valid + let color = state.color; + if (color.startsWith("#")) { + color = state.color.substr(1); + } + let hexExp = /([0-9A-Fa-f]{6})/ + let hexTest = hexExp.exec(color); + let currentColor = "000000"; + if (props.association && "metadata" in props.association) { + currentColor = uxToHex(props.association.metadata.color); + } + if (hexTest && (hexTest[1] !== currentColor)) { + let chatOwner = (deSig(props.match.params.ship) === window.ship); + let association = + (props.association) && ("metadata" in props.association) + ? props.association : {}; + + if (chatOwner) { + props.api.setSpinner(true); + props.api.metadataAdd( + association['app-path'], + association['group-path'], + association.metadata.title, + association.metadata.description, + association.metadata['date-created'], + color + ).then(() => { + props.api.setSpinner(false); + }) + } + } + } } changeTitle() { @@ -174,28 +208,21 @@ export class SettingsScreen extends Component {
Change color
Give this chat a color when viewing group channels