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

REMOVE_STORAGE redux action

fix typo storageNoteMap
This commit is contained in:
Dick Choi
2016-09-08 16:33:16 +09:00
parent 34ae3cd704
commit 7132e9ff24
3 changed files with 56 additions and 17 deletions

View File

@@ -171,7 +171,7 @@ class NoteList extends React.Component {
let folder = _.find(storage.folders, {key: folderKey}) let folder = _.find(storage.folders, {key: folderKey})
if (folder == null) { if (folder == null) {
return data.storeageNoteMap return data.storageNoteMap
.get(storage.key) .get(storage.key)
.map((uniqueKey) => data.noteMap.get(uniqueKey)) .map((uniqueKey) => data.noteMap.get(uniqueKey))
} }

View File

@@ -278,11 +278,11 @@ class StorageItem extends React.Component {
.then(() => { .then(() => {
store.dispatch({ store.dispatch({
type: 'REMOVE_STORAGE', type: 'REMOVE_STORAGE',
key: storage.key storageKey: storage.key
}) })
}) })
.catch((err) => { .catch((err) => {
console.error(err) throw err
}) })
} }

View File

@@ -9,7 +9,7 @@ function defaultDataMap () {
storageMap: new Map(), storageMap: new Map(),
noteMap: new Map(), noteMap: new Map(),
starredSet: new Set(), starredSet: new Set(),
storeageNoteMap: new Map(), storageNoteMap: new Map(),
folderNoteMap: new Map(), folderNoteMap: new Map(),
tagNoteMap: new Map() tagNoteMap: new Map()
} }
@@ -33,10 +33,10 @@ function data (state = defaultDataMap(), action) {
state.starredSet.add(uniqueKey) state.starredSet.add(uniqueKey)
} }
let storageNoteList = state.storeageNoteMap.get(note.storage) let storageNoteList = state.storageNoteMap.get(note.storage)
if (storageNoteList == null) { if (storageNoteList == null) {
storageNoteList = new Set(storageNoteList) storageNoteList = new Set(storageNoteList)
state.storeageNoteMap.set(note.storage, storageNoteList) state.storageNoteMap.set(note.storage, storageNoteList)
} }
storageNoteList.add(uniqueKey) storageNoteList.add(uniqueKey)
@@ -79,11 +79,11 @@ function data (state = defaultDataMap(), action) {
// Update storageNoteMap if oldNote doesn't exist // Update storageNoteMap if oldNote doesn't exist
if (oldNote == null) { if (oldNote == null) {
state.storeageNoteMap = new Map(state.storeageNoteMap) state.storageNoteMap = new Map(state.storageNoteMap)
let storageNoteSet = state.storeageNoteMap.get(note.storage) let storageNoteSet = state.storageNoteMap.get(note.storage)
storageNoteSet = new Set(storageNoteSet) storageNoteSet = new Set(storageNoteSet)
storageNoteSet.add(uniqueKey) storageNoteSet.add(uniqueKey)
state.storeageNoteMap.set(note.storage, storageNoteSet) state.storageNoteMap.set(note.storage, storageNoteSet)
} }
// Update foldermap if folder changed or post created // Update foldermap if folder changed or post created
@@ -163,11 +163,11 @@ function data (state = defaultDataMap(), action) {
} }
// From storageNoteMap // From storageNoteMap
state.storeageNoteMap = new Map(state.storeageNoteMap) state.storageNoteMap = new Map(state.storageNoteMap)
let noteSet = state.storeageNoteMap.get(originNote.storage) let noteSet = state.storageNoteMap.get(originNote.storage)
noteSet = new Set(noteSet) noteSet = new Set(noteSet)
noteSet.delete(originKey) noteSet.delete(originKey)
state.storeageNoteMap.set(originNote.storage, noteSet) state.storageNoteMap.set(originNote.storage, noteSet)
// From folderNoteMap // From folderNoteMap
state.folderNoteMap = new Map(state.folderNoteMap) state.folderNoteMap = new Map(state.folderNoteMap)
@@ -200,8 +200,8 @@ function data (state = defaultDataMap(), action) {
// Update storageNoteMap if oldNote doesn't exist // Update storageNoteMap if oldNote doesn't exist
if (oldNote == null) { if (oldNote == null) {
state.storeageNoteMap = new Map(state.storeageNoteMap) state.storageNoteMap = new Map(state.storageNoteMap)
let noteSet = state.storeageNoteMap.get(note.storage) let noteSet = state.storageNoteMap.get(note.storage)
noteSet = new Set(noteSet) noteSet = new Set(noteSet)
noteSet.add(uniqueKey) noteSet.add(uniqueKey)
state.folderNoteMap.set(folderKey, noteSet) state.folderNoteMap.set(folderKey, noteSet)
@@ -269,11 +269,11 @@ function data (state = defaultDataMap(), action) {
state = Object.assign({}, state) state = Object.assign({}, state)
// From storageNoteMap // From storageNoteMap
state.storeageNoteMap = new Map(state.storeageNoteMap) state.storageNoteMap = new Map(state.storageNoteMap)
let noteSet = state.storeageNoteMap.get(targetNote.storage) let noteSet = state.storageNoteMap.get(targetNote.storage)
noteSet = new Set(noteSet) noteSet = new Set(noteSet)
noteSet.delete(uniqueKey) noteSet.delete(uniqueKey)
state.storeageNoteMap.set(targetNote.storage, noteSet) state.storageNoteMap.set(targetNote.storage, noteSet)
if (targetNote != null) { if (targetNote != null) {
// From isStarred // From isStarred
@@ -357,6 +357,45 @@ function data (state = defaultDataMap(), action) {
}) })
} }
return state return state
case 'REMOVE_STORAGE':
state = Object.assign({}, state)
let storage = state.storageMap.get(action.storageKey)
state.storageMap = new Map(state.storageMap)
state.storageMap.delete(action.storageKey)
// Remove folders from folderMap
if (storage != null) {
state.folderMap = new Map(state.folderMap)
storage.folders.forEach((folder) => {
let folderKey = storage.key + '-' + folder.key
state.folderMap.delete(folderKey)
})
}
// Remove notes from noteMap and tagNoteMap
let storageNoteSet = state.storageNoteMap.get(action.storageKey)
state.storageNoteMap = new Map(state.storageNoteMap)
state.storageNoteMap.delete(action.storageKey)
if (storageNoteSet != null) {
let notes = storageNoteSet
.map((noteKey) => state.noteMap.get(noteKey))
.filter((note) => note != null)
state.noteMap = new Map(state.noteMap)
state.tagNoteMap = new Map(state.tagNoteMap)
state.starredSet = new Set(state.starredSet)
notes.forEach((note) => {
let noteKey = storage.key + '-' + note.key
state.noteMap.delete(noteKey)
state.starredSet.delete(noteKey)
note.tags.forEach((tag) => {
let tagNoteSet = state.tagNoteMap.get(tag)
tagNoteSet = new Set(tagNoteSet)
tagNoteSet.delete(noteKey)
})
})
}
return state
} }
return state return state
} }