forked from artsy/eigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualClueModel.ts
60 lines (54 loc) · 1.72 KB
/
VisualClueModel.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { action, Action } from "easy-peasy"
import { LayoutAnimation } from "react-native"
import { VisualClueName, visualClueNames } from "./config/visualClues"
export interface VisualClueModel {
sessionState: {
nextId: number
clues: Array<Omit<string, "positionIndex">>
}
addClue: Action<this, VisualClueName | string>
seenVisualClues: Array<VisualClueName | string>
setVisualClueAsSeen: Action<this, VisualClueName | string>
_removeVisualClueAsSeen: Action<this, VisualClueName | string>
}
/**
* @deprecated use ProgressiveOnboardingModel instead
*/
export const getVisualClueModel = (): VisualClueModel => ({
sessionState: {
nextId: 0,
clues: [],
},
addClue: action((state, clueName) => {
state.sessionState.clues.push(clueName)
state.sessionState.nextId += 1
return
}),
/**
* @deprecated use dismissed from ProgressiveOnboardingModel instead
*/
seenVisualClues: [],
setVisualClueAsSeen: action((state, clueName) => {
const isSessionClue = !visualClueNames.includes(clueName)
if (isSessionClue) {
state.sessionState.clues = state.sessionState.clues.filter((clue) => clue !== clueName)
} else {
if (state.seenVisualClues.includes(clueName)) {
return
}
LayoutAnimation.configureNext({
...LayoutAnimation.Presets.easeInEaseOut,
duration: 500,
})
state.seenVisualClues = [...state.seenVisualClues, clueName]
}
}),
// Method used to clean the store for easier DX
_removeVisualClueAsSeen: action((state, clueName) => {
const index = state.seenVisualClues.indexOf(clueName)
if (index === -1) {
return
}
state.seenVisualClues = state.seenVisualClues.filter((_, i) => i !== index)
}),
})