1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Preferenceからもフォルダーの色の選択ができる。

This commit is contained in:
Rokt33r
2015-11-16 01:22:22 +09:00
parent b28b18a19a
commit ff1bffbb55
4 changed files with 107 additions and 20 deletions

View File

@@ -26,7 +26,9 @@ export default class FolderRow extends React.Component {
handleEditButtonClick (e) {
this.setState({
mode: EDIT,
name: this.props.folder.name
name: this.props.folder.name,
color: this.props.folder.color,
isColorEditing: false
})
}
@@ -34,12 +36,28 @@ export default class FolderRow extends React.Component {
this.setState({mode: DELETE})
}
handleColorSelectClick (e) {
this.setState({
isColorEditing: true
})
}
handleColorButtonClick (index) {
return e => {
this.setState({
color: index,
isColorEditing: false
})
}
}
handleSaveButtonClick (e) {
let { folder, setAlert } = this.props
setAlert(null, () => {
let input = {
name: this.state.name
name: this.state.name,
color: this.state.color
}
folder = Object.assign({}, folder, input)
@@ -68,8 +86,38 @@ export default class FolderRow extends React.Component {
switch (this.state.mode) {
case EDIT:
let colorIndexes = []
for (let i = 0; i < 8; i++) {
colorIndexes.push(i)
}
let colorOptions = colorIndexes.map(index => {
let className = this.state.color === index
? 'active'
: null
return (
<button onClick={e => this.handleColorButtonClick(index)(e)} className={className} key={index}>
<FolderMark color={index}/>
</button>
)
})
return (
<div className='FolderRow edit'>
<div className='folderColor'>
<button onClick={e => this.handleColorSelectClick(e)} className='select'>
<FolderMark color={this.state.color}/>
</button>
{this.state.isColorEditing
? (
<div className='options'>
<div className='label'>Color select</div>
{colorOptions}
</div>
)
: null
}
</div>
<div className='folderName'>
<input valueLink={this.linkState('name')} type='text'/>
</div>
@@ -93,7 +141,8 @@ export default class FolderRow extends React.Component {
default:
return (
<div className='FolderRow'>
<div className='folderName'><FolderMark color={folder.color}/> {folder.name}</div>
<div className='folderColor'><FolderMark color={folder.color}/></div>
<div className='folderName'>{folder.name}</div>
<div className='folderControl'>
<button onClick={e => this.handleEditButtonClick(e)}><i className='fa fa-fw fa-edit'/></button>
<button onClick={e => this.handleDeleteButtonClick(e)}><i className='fa fa-fw fa-close'/></button>

View File

@@ -59,7 +59,8 @@ export default class FolderSettingTab extends React.Component {
<div className='sectionTitle'>Manage folder</div>
<div className='folderTable'>
<div className='folderHeader'>
<div className='folderName'>Folder name</div>
<div className='folderColor'></div>
<div className='folderName'>Folder</div>
<div className='folderControl'>Edit/Delete</div>
</div>
{folderElements}

View File

@@ -47,7 +47,8 @@ function folders (state = initialFolders, action) {
if (!_.isString(folder.name)) throw new Error('Folder name must be a string')
folder.name = folder.name.trim().replace(/\s/, '_')
if (folder.length === 0) throw new Error('Folder name is required')
if (folder.name.length === 0) throw new Error('Folder name is required')
if (folder.name.match(/\//)) throw new Error('`/` is not available for folder name')
// Folder existence check
if (targetFolder == null) throw new Error('Folder doesnt exist')