mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-17 03:31:52 +00:00
Refactoring update of tag changes
This commit is contained in:
@@ -142,27 +142,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldNote != null) {
|
if (oldNote != null) {
|
||||||
const discardedTags = _.difference(oldNote.tags, note.tags)
|
updateTagChanges(oldNote, note, state, uniqueKey)
|
||||||
const addedTags = _.difference(note.tags, oldNote.tags)
|
|
||||||
if (discardedTags.length + addedTags.length > 0) {
|
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
|
||||||
|
|
||||||
discardedTags.forEach((tag) => {
|
|
||||||
let tagNoteList = state.tagNoteMap.get(tag)
|
|
||||||
if (tagNoteList != null) {
|
|
||||||
tagNoteList = new Set(tagNoteList)
|
|
||||||
tagNoteList.delete(uniqueKey)
|
|
||||||
state.tagNoteMap.set(tag, tagNoteList)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
addedTags.forEach((tag) => {
|
|
||||||
let tagNoteList = state.tagNoteMap.get(tag)
|
|
||||||
tagNoteList = new Set(tagNoteList)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
|
|
||||||
state.tagNoteMap.set(tag, tagNoteList)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||||
note.tags.forEach((tag) => {
|
note.tags.forEach((tag) => {
|
||||||
@@ -278,27 +258,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
|
|
||||||
// Remove from old folder map
|
// Remove from old folder map
|
||||||
if (oldNote != null) {
|
if (oldNote != null) {
|
||||||
const discardedTags = _.difference(oldNote.tags, note.tags)
|
updateTagChanges(oldNote, note, state, uniqueKey)
|
||||||
const addedTags = _.difference(note.tags, oldNote.tags)
|
|
||||||
if (discardedTags.length + addedTags.length > 0) {
|
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
|
||||||
|
|
||||||
discardedTags.forEach((tag) => {
|
|
||||||
let tagNoteList = state.tagNoteMap.get(tag)
|
|
||||||
if (tagNoteList != null) {
|
|
||||||
tagNoteList = new Set(tagNoteList)
|
|
||||||
tagNoteList.delete(uniqueKey)
|
|
||||||
state.tagNoteMap.set(tag, tagNoteList)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
addedTags.forEach((tag) => {
|
|
||||||
let tagNoteList = state.tagNoteMap.get(tag)
|
|
||||||
tagNoteList = new Set(tagNoteList)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
|
|
||||||
state.tagNoteMap.set(tag, tagNoteList)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||||
note.tags.forEach((tag) => {
|
note.tags.forEach((tag) => {
|
||||||
@@ -559,6 +519,30 @@ function status (state = defaultStatus, action) {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateTagChanges (oldNote, note, state, uniqueKey) {
|
||||||
|
const discardedTags = _.difference(oldNote.tags, note.tags)
|
||||||
|
const addedTags = _.difference(note.tags, oldNote.tags)
|
||||||
|
if (discardedTags.length + addedTags.length > 0) {
|
||||||
|
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||||
|
|
||||||
|
discardedTags.forEach((tag) => {
|
||||||
|
let tagNoteList = state.tagNoteMap.get(tag)
|
||||||
|
if (tagNoteList != null) {
|
||||||
|
tagNoteList = new Set(tagNoteList)
|
||||||
|
tagNoteList.delete(uniqueKey)
|
||||||
|
state.tagNoteMap.set(tag, tagNoteList)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
addedTags.forEach((tag) => {
|
||||||
|
let tagNoteList = state.tagNoteMap.get(tag)
|
||||||
|
tagNoteList = new Set(tagNoteList)
|
||||||
|
tagNoteList.add(uniqueKey)
|
||||||
|
|
||||||
|
state.tagNoteMap.set(tag, tagNoteList)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const reducer = combineReducers({
|
const reducer = combineReducers({
|
||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
|
|||||||
Reference in New Issue
Block a user