Newer
Older
import analytics from '../lib/analytics';
import decks from '../lib/libraries/decks/index.jsx';
const CLOSE_CARDS = 'scratch-gui/cards/CLOSE_CARDS';
const VIEW_CARDS = 'scratch-gui/cards/VIEW_CARDS';
const ACTIVATE_DECK = 'scratch-gui/cards/ACTIVATE_DECK';
const NEXT_STEP = 'scratch-gui/cards/NEXT_STEP';
const PREV_STEP = 'scratch-gui/cards/PREV_STEP';
const DRAG_CARD = 'scratch-gui/cards/DRAG_CARD';
const START_DRAG = 'scratch-gui/cards/START_DRAG';
const END_DRAG = 'scratch-gui/cards/END_DRAG';
const initialState = {
visible: false,
content: decks,
activeDeckId: null,
step: 0,
dragging: false
};
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
switch (action.type) {
case CLOSE_CARDS:
return Object.assign({}, state, {
visible: false
});
case VIEW_CARDS:
return Object.assign({}, state, {
visible: true
});
case ACTIVATE_DECK:
return Object.assign({}, state, {
activeDeckId: action.activeDeckId,
step: 0,
visible: true
});
case NEXT_STEP:
if (state.activeDeckId !== null) {
analytics.event({
category: 'how-to',
action: 'next step',
label: `${state.activeDeckId} - ${state.step}`
});
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
return Object.assign({}, state, {
step: state.step + 1
});
}
return state;
case PREV_STEP:
if (state.activeDeckId !== null) {
if (state.step > 0) {
return Object.assign({}, state, {
step: state.step - 1
});
}
}
return state;
case DRAG_CARD:
return Object.assign({}, state, {
x: action.x,
y: action.y
});
case START_DRAG:
return Object.assign({}, state, {
dragging: true
});
case END_DRAG:
return Object.assign({}, state, {
dragging: false
});
default:
return state;
}
};
const activateDeck = function (activeDeckId) {
return {
type: ACTIVATE_DECK,
activeDeckId
};
};
const viewCards = function () {
return {type: VIEW_CARDS};
};
const closeCards = function () {
return {type: CLOSE_CARDS};
};
const nextStep = function () {
return {type: NEXT_STEP};
};
const prevStep = function () {
return {type: PREV_STEP};
};
const dragCard = function (x, y) {
return {type: DRAG_CARD, x, y};
};
const startDrag = function () {
return {type: START_DRAG};
};
const endDrag = function () {
return {type: END_DRAG};
};
export {
reducer as default,