Spaces:
Running
Running
File size: 3,323 Bytes
f2bee8a |
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 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
import analytics from '../lib/analytics';
import decks from '../lib/libraries/decks/index.jsx';
const CLOSE_CARDS = 'scratch-gui/cards/CLOSE_CARDS';
const SHRINK_EXPAND_CARDS = 'scratch-gui/cards/SHRINK_EXPAND_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,
x: 0,
y: 0,
expanded: true,
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 SHRINK_EXPAND_CARDS:
return Object.assign({}, state, {
expanded: !state.expanded
});
case VIEW_CARDS:
return Object.assign({}, state, {
visible: true
});
case ACTIVATE_DECK:
return Object.assign({}, state, {
activeDeckId: action.activeDeckId,
step: 0,
x: 0,
y: 0,
expanded: true,
visible: true
});
case NEXT_STEP:
if (state.activeDeckId !== null) {
analytics.event({
category: 'how-to',
action: 'next step',
label: `${state.activeDeckId} - ${state.step}`
});
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 shrinkExpandCards = function () {
return {type: SHRINK_EXPAND_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,
initialState as cardsInitialState,
activateDeck,
viewCards,
closeCards,
shrinkExpandCards,
nextStep,
prevStep,
dragCard,
startDrag,
endDrag
};
|