mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
beta
- add error alert(folder editing) - debug clear button of search input
This commit is contained in:
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user