mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-17 19:51:42 +00:00
Refactoring assignment of unique key to tags
This commit is contained in:
@@ -44,10 +44,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
const folderNoteSet = getOrInitItem(state.folderNoteMap, folderKey)
|
const folderNoteSet = getOrInitItem(state.folderNoteMap, folderKey)
|
||||||
folderNoteSet.add(uniqueKey)
|
folderNoteSet.add(uniqueKey)
|
||||||
|
|
||||||
note.tags.forEach((tag) => {
|
assignToTags(note.tags, state, uniqueKey)
|
||||||
const tagNoteList = getOrInitItem(state.tagNoteMap, tag)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
return state
|
return state
|
||||||
case 'UPDATE_NOTE':
|
case 'UPDATE_NOTE':
|
||||||
@@ -87,14 +84,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
} else {
|
} else {
|
||||||
state.trashedSet.delete(uniqueKey)
|
state.trashedSet.delete(uniqueKey)
|
||||||
|
|
||||||
note.tags.forEach(tag => {
|
assignToTags(note.tags, state, uniqueKey)
|
||||||
let tagNoteList = state.tagNoteMap.get(tag)
|
|
||||||
if (tagNoteList != null) {
|
|
||||||
tagNoteList = new Set(tagNoteList)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
state.tagNoteMap.set(tag, tagNoteList)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (note.isStarred) {
|
if (note.isStarred) {
|
||||||
state.starredSet.add(uniqueKey)
|
state.starredSet.add(uniqueKey)
|
||||||
@@ -131,11 +121,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
if (oldNote != null) {
|
if (oldNote != null) {
|
||||||
updateTagChanges(oldNote, note, state, uniqueKey)
|
updateTagChanges(oldNote, note, state, uniqueKey)
|
||||||
} else {
|
} else {
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
assignToTags(note.tags, state, uniqueKey)
|
||||||
note.tags.forEach((tag) => {
|
|
||||||
const tagNoteList = getOrInitItem(state.tagNoteMap, tag)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state
|
return state
|
||||||
@@ -243,11 +229,7 @@ function data (state = defaultDataMap(), action) {
|
|||||||
if (oldNote != null) {
|
if (oldNote != null) {
|
||||||
updateTagChanges(oldNote, note, state, uniqueKey)
|
updateTagChanges(oldNote, note, state, uniqueKey)
|
||||||
} else {
|
} else {
|
||||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
assignToTags(note.tags, state, uniqueKey)
|
||||||
note.tags.forEach((tag) => {
|
|
||||||
const tagNoteList = getOrInitItem(state.tagNoteMap, tag)
|
|
||||||
tagNoteList.add(uniqueKey)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state
|
return state
|
||||||
@@ -502,11 +484,16 @@ function updateTagChanges (oldNote, note, state, uniqueKey) {
|
|||||||
state.tagNoteMap.set(tag, tagNoteList)
|
state.tagNoteMap.set(tag, tagNoteList)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
addedTags.forEach((tag) => {
|
assignToTags(addedTags, state, uniqueKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assignToTags (tags, state, uniqueKey) {
|
||||||
|
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||||
|
tags.forEach((tag) => {
|
||||||
const tagNoteList = getOrInitItem(state.tagNoteMap, tag)
|
const tagNoteList = getOrInitItem(state.tagNoteMap, tag)
|
||||||
tagNoteList.add(uniqueKey)
|
tagNoteList.add(uniqueKey)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrInitItem (target, key) {
|
function getOrInitItem (target, key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user