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

UPDATE_FOLDER & DELETE_FOLDER

fix store bug when creating note
This commit is contained in:
Dick Choi
2016-09-02 09:33:01 +09:00
parent 4ee49d5991
commit a391ac682d
5 changed files with 88 additions and 31 deletions

View File

@@ -58,7 +58,7 @@ class MutableSet {
}
forEach (...args) {
return this._map.forEach(...args)
return this._set.forEach(...args)
}
[Symbol.iterator] () {

View File

@@ -178,8 +178,11 @@ class NoteList extends React.Component {
let folderNoteKeyList = data.folderNoteMap
.get(storage.key + '-' + folder.key)
return folderNoteKeyList
.map((uniqueKey) => data.noteMap.get(uniqueKey))
return folderNoteKeyList != null
? folderNoteKeyList
.map((uniqueKey) => data.noteMap.get(uniqueKey))
: []
}
handleNoteClick (uniqueKey) {

View File

@@ -7,8 +7,7 @@ import dataApi from 'browser/main/lib/dataApi'
import store from 'browser/main/store'
const electron = require('electron')
const { shell, remote } = electron
const { Menu, MenuItem } = remote
const { shell } = electron
import { SketchPicker } from 'react-color'
class UnstyledFolderItem extends React.Component {
@@ -42,10 +41,10 @@ class UnstyledFolderItem extends React.Component {
color: this.state.folder.color,
name: this.state.folder.name
})
.then((storage) => {
.then((data) => {
store.dispatch({
type: 'UPDATE_STORAGE',
storage: storage
type: 'UPDATE_FOLDER',
storage: data.storage
})
this.setState({
status: 'IDLE'
@@ -146,12 +145,12 @@ class UnstyledFolderItem extends React.Component {
handleDeleteConfirmButtonClick (e) {
let { storage, folder } = this.props
dataApi
.removeFolder(storage.key, folder.key)
.then((storage) => {
.deleteFolder(storage.key, folder.key)
.then((data) => {
store.dispatch({
type: 'REMOVE_FOLDER',
key: folder.key,
storage: storage
type: 'DELETE_FOLDER',
storage: data.storage,
folderKey: data.folderKey
})
})
}
@@ -257,10 +256,10 @@ class StorageItem extends React.Component {
}
dataApi.createFolder(storage.key, input)
.then((storage) => {
.then((data) => {
store.dispatch({
type: 'ADD_FOLDER',
storage: storage
type: 'UPDATE_FOLDER',
storage: data.storage
})
})
.catch((err) => {

View File

@@ -51,10 +51,10 @@ class StoragesTab extends React.Component {
}
renderList () {
let { storages, boundingBox } = this.props
let { data, boundingBox } = this.props
if (!boundingBox) { return null }
let storageList = storages.map((storage) => {
let storageList = data.storageMap.map((storage) => {
return <StorageItem
key={storage.key}
storage={storage}

View File

@@ -40,12 +40,12 @@ function data (state = defaultDataMap(), action) {
}
storageNoteList.add(uniqueKey)
let folderNoteList = state.folderNoteMap.get(folderKey)
if (folderNoteList == null) {
folderNoteList = new Set(folderNoteList)
state.folderNoteMap.set(folderKey, folderNoteList)
let folderNoteSet = state.folderNoteMap.get(folderKey)
if (folderNoteSet == null) {
folderNoteSet = new Set(folderNoteSet)
state.folderNoteMap.set(folderKey, folderNoteSet)
}
folderNoteList.add(uniqueKey)
folderNoteSet.add(uniqueKey)
note.tags.forEach((tag) => {
let tagNoteList = state.tagNoteMap.get(tag)
@@ -80,19 +80,19 @@ function data (state = defaultDataMap(), action) {
// Update storageNoteMap if oldNote doesn't exist
if (oldNote == null) {
state.storeageNoteMap = new Map(state.storeageNoteMap)
let noteSet = state.storeageNoteMap.get(note.storage)
noteSet = new Set(noteSet)
noteSet.add(uniqueKey)
state.folderNoteMap.set(folderKey, noteSet)
let storageNoteSet = state.storeageNoteMap.get(note.storage)
storageNoteSet = new Set(storageNoteSet)
storageNoteSet.add(uniqueKey)
state.storeageNoteMap.set(note.storage, storageNoteSet)
}
// Update foldermap if folder changed or post created
if (oldNote == null || oldNote.folder !== note.folder) {
state.folderNoteMap = new Map(state.folderNoteMap)
let folderNoteList = state.folderNoteMap.get(folderKey)
folderNoteList = new Set(folderNoteList)
folderNoteList.add(uniqueKey)
state.folderNoteMap.set(folderKey, folderNoteList)
let folderNoteSet = state.folderNoteMap.get(folderKey)
folderNoteSet = new Set(folderNoteSet)
folderNoteSet.add(uniqueKey)
state.folderNoteMap.set(folderKey, folderNoteSet)
if (oldNote != null) {
let oldFolderKey = oldNote.storage + '-' + oldNote.folder
@@ -305,6 +305,61 @@ function data (state = defaultDataMap(), action) {
state.noteMap.delete(uniqueKey)
return state
}
case 'UPDATE_FOLDER':
{
state = Object.assign({}, state)
state.storageMap = new Map(state.storageMap)
state.storageMap.set(action.storage.key, action.storage)
}
return state
case 'DELETE_FOLDER':
{
state = Object.assign({}, state)
state.storageMap = new Map(state.storageMap)
state.storageMap.set(action.storage.key, action.storage)
// Get note list from folder-note map
// and delete note set from folder-note map
let folderKey = action.storage.key + '-' + action.folderKey
let noteSet = state.folderNoteMap.get(folderKey)
state.folderNoteMap = new Map(state.folderNoteMap)
state.folderNoteMap.delete(folderKey)
state.noteMap = new Map(state.noteMap)
state.storageNoteMap = new Map(state.storageNoteMap)
let storageNoteSet = state.storageNoteMap.get(action.storage.key)
storageNoteSet = new Set(storageNoteSet)
storageNoteSet.delete()
noteSet.forEach(function handleNoteKey (noteKey) {
// Get note from noteMap
let note = state.noteMap.get(noteKey)
if (note != null) {
state.noteMap.delete(noteKey)
// From storageSet
let storageNoteSet = state.storageNoteMap.get(note.storage)
storageNoteSet = new Set(storageNoteSet)
state.storageNoteMap.set(note.storage, storageNoteSet)
storageNoteSet.delete(noteKey)
// From starredSet
if (note.isStarred) {
state.starredSet = new Set(state.starredSet)
state.starredSet.delete(noteKey)
}
// Delete key from tag map
state.tagNoteMap = new Map(state.tagNoteMap)
note.tags.forEach((tag) => {
let tagNoteSet = state.tagNoteMap.get(tag)
tagNoteSet = new Set(tagNoteSet)
state.tagNoteMap.set(tag, tagNoteSet)
tagNoteSet.delete(noteKey)
})
}
})
}
return state
}
return state
}