2020-10-24 10:35:12 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react'
|
|
|
|
import {injectIntl, IntlShape, FormattedMessage} from 'react-intl'
|
|
|
|
|
|
|
|
import {BlockIcons} from '../blockIcons'
|
|
|
|
import {Board} from '../blocks/board'
|
|
|
|
import mutator from '../mutator'
|
|
|
|
import Menu from '../widgets/menu'
|
|
|
|
import MenuWrapper from '../widgets/menuWrapper'
|
2020-10-26 17:42:05 +01:00
|
|
|
import Editable from '../widgets/editable'
|
2020-10-24 10:35:12 +02:00
|
|
|
|
|
|
|
import Button from './button'
|
|
|
|
|
2020-10-27 16:30:15 +01:00
|
|
|
import './viewTitle.scss'
|
|
|
|
|
2020-10-24 10:35:12 +02:00
|
|
|
type Props = {
|
|
|
|
board: Board
|
|
|
|
intl: IntlShape
|
|
|
|
}
|
|
|
|
|
|
|
|
type State = {
|
2020-10-26 17:42:05 +01:00
|
|
|
title: string
|
2020-10-24 10:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ViewTitle extends React.Component<Props, State> {
|
2020-10-26 17:42:05 +01:00
|
|
|
private titleEditor = React.createRef<Editable>()
|
2020-10-24 10:35:12 +02:00
|
|
|
shouldComponentUpdate(): boolean {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-27 21:59:37 +01:00
|
|
|
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
|
|
|
|
if (prevState.title !== nextProps.board.title) {
|
|
|
|
return {
|
|
|
|
title: nextProps.board.title,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2020-10-24 10:35:12 +02:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props)
|
2020-10-27 16:30:15 +01:00
|
|
|
this.state = {title: props.board.title}
|
2020-10-24 10:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
2020-10-24 10:42:16 +02:00
|
|
|
const {board, intl} = this.props
|
2020-10-24 10:35:12 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-10-27 16:30:15 +01:00
|
|
|
<div className={'ViewTitle octo-hovercontrols ' + (board.icon ? '' : 'add-visible')}>
|
2020-10-24 10:35:12 +02:00
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
const newIcon = BlockIcons.shared.randomIcon()
|
|
|
|
mutator.changeIcon(board, newIcon)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<FormattedMessage
|
|
|
|
id='TableComponent.add-icon'
|
|
|
|
defaultMessage='Add Icon'
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
|
2020-10-27 16:30:15 +01:00
|
|
|
<div className='ViewTitle octo-icontitle'>
|
2020-10-24 10:35:12 +02:00
|
|
|
{board.icon &&
|
|
|
|
<MenuWrapper>
|
|
|
|
<div className='octo-button octo-icon'>{board.icon}</div>
|
|
|
|
<Menu>
|
2020-10-24 10:42:16 +02:00
|
|
|
<Menu.Text
|
|
|
|
id='random'
|
|
|
|
name={intl.formatMessage({id: 'ViewTitle.random-icon', defaultMessage: 'Random'})}
|
|
|
|
onClick={() => mutator.changeIcon(board, BlockIcons.shared.randomIcon())}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='remove'
|
|
|
|
name={intl.formatMessage({id: 'ViewTitle.remove-icon', defaultMessage: 'Remove Icon'})}
|
|
|
|
onClick={() => mutator.changeIcon(board, undefined, 'remove icon')}
|
|
|
|
/>
|
2020-10-24 10:35:12 +02:00
|
|
|
</Menu>
|
|
|
|
</MenuWrapper>}
|
2020-10-24 10:42:16 +02:00
|
|
|
<Editable
|
2020-10-26 17:42:05 +01:00
|
|
|
ref={this.titleEditor}
|
2020-10-24 10:42:16 +02:00
|
|
|
className='title'
|
2020-10-26 17:42:05 +01:00
|
|
|
value={this.state.title}
|
2020-10-24 10:42:16 +02:00
|
|
|
placeholderText={intl.formatMessage({id: 'ViewTitle.untitled-board', defaultMessage: 'Untitled Board'})}
|
2020-10-26 17:42:05 +01:00
|
|
|
onChange={(title) => this.setState({title})}
|
2020-10-26 20:30:32 +01:00
|
|
|
onSave={() => mutator.changeTitle(board, this.state.title)}
|
|
|
|
onCancel={() => this.setState({title: this.props.board.title})}
|
2020-10-24 10:42:16 +02:00
|
|
|
/>
|
2020-10-24 10:35:12 +02:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(ViewTitle)
|