You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
export function selectSeedWord (word, shuffledIndex) {
|
|
return function update (state) {
|
|
const { selectedSeedWords, selectedSeedWordsHash } = state
|
|
const nextSelectedIndex = selectedSeedWords.length
|
|
|
|
return {
|
|
selectedSeedWords: [ ...selectedSeedWords, word ],
|
|
selectedSeedWordsHash: { ...selectedSeedWordsHash, [shuffledIndex]: nextSelectedIndex },
|
|
}
|
|
}
|
|
}
|
|
|
|
export function deselectSeedWord (shuffledIndex) {
|
|
return function update (state) {
|
|
const {
|
|
selectedSeedWords: prevSelectedSeedWords,
|
|
selectedSeedWordsHash: prevSelectedSeedWordsHash,
|
|
} = state
|
|
|
|
const selectedSeedWords = [...prevSelectedSeedWords]
|
|
const indexToRemove = prevSelectedSeedWordsHash[shuffledIndex]
|
|
selectedSeedWords.splice(indexToRemove, 1)
|
|
const selectedSeedWordsHash = Object.keys(prevSelectedSeedWordsHash).reduce((acc, index) => {
|
|
const output = { ...acc }
|
|
const selectedSeedWordIndex = prevSelectedSeedWordsHash[index]
|
|
|
|
if (selectedSeedWordIndex < indexToRemove) {
|
|
output[index] = selectedSeedWordIndex
|
|
} else if (selectedSeedWordIndex > indexToRemove) {
|
|
output[index] = selectedSeedWordIndex - 1
|
|
}
|
|
|
|
return output
|
|
}, {})
|
|
|
|
return {
|
|
selectedSeedWords,
|
|
selectedSeedWordsHash,
|
|
}
|
|
}
|
|
}
|
|
|