blob: f2476fc5ce42014be780ca2a476000237d880ccf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
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,
}
}
}
|