1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00
- add error alert(folder editing)
- debug clear button of search input
This commit is contained in:
Rokt33r
2015-11-05 09:50:07 +09:00
parent cc0f2c7c7f
commit 8abdedc11d
10 changed files with 126 additions and 77 deletions

View File

@@ -19,6 +19,8 @@ function folders (state = initialFolders, action) {
case FOLDER_CREATE:
{
let newFolder = action.data.folder
if (!_.isString(newFolder.name)) throw new Error('Folder name must be a string')
newFolder.name = newFolder.name.trim().replace(/\s/, '_')
Object.assign(newFolder, {
key: keygen(),
createAt: new Date(),
@@ -27,8 +29,10 @@ function folders (state = initialFolders, action) {
color: Math.round(Math.random() * 7)
})
if (newFolder.length === 0) throw new Error('Folder name is required')
let conflictFolder = _.findWhere(state, {name: newFolder.name})
if (conflictFolder != null) throw new Error('name conflicted!')
if (conflictFolder != null) throw new Error(`${newFolder.name} already exists!`)
state.push(newFolder)
dataStore.setFolders(null, state)
@@ -39,11 +43,18 @@ function folders (state = initialFolders, action) {
let folder = action.data.folder
let targetFolder = _.findWhere(state, {key: folder.key})
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')
// Folder existence check
if (targetFolder == null) throw new Error('Folder doesnt exist')
// Name conflict check
if (targetFolder.name !== folder.name) {
let conflictFolder = _.findWhere(state, {name: folder.name})
let conflictFolder = _.find(state, _folder => {
return folder.name === _folder.name && folder.key !== _folder.key
})
console.log(conflictFolder)
if (conflictFolder != null) throw new Error('Name conflicted')
}
Object.assign(targetFolder, folder, {