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.
91 lines
2.5 KiB
91 lines
2.5 KiB
import * as WelcomeActions from '../../actions/welcome/welcome.actions';
|
|
|
|
let dispatch;
|
|
|
|
let initials = [
|
|
{ initial: 'A', active: true },
|
|
{ initial: 'A', active: false },
|
|
{ initial: 'A', active: false }
|
|
];
|
|
|
|
let active = 0;
|
|
let code;
|
|
|
|
const InitialsCtrl = {
|
|
setDispatch: (d) => dispatch = d,
|
|
|
|
keydown: function(e) {
|
|
switch (e.keyCode) {
|
|
case 13:
|
|
case 32:
|
|
break;
|
|
case 37:
|
|
active--;
|
|
if (active === -1) {
|
|
active = initials.length - 1;
|
|
}
|
|
this.updateInitials();
|
|
break;
|
|
case 38:
|
|
code = initials[active].initial.charCodeAt(0);
|
|
code--;
|
|
if (code === 64) {
|
|
code = 90;
|
|
}
|
|
initials[active].initial = String.fromCharCode(code);
|
|
this.updateInitials();
|
|
break;
|
|
case 39:
|
|
active++;
|
|
if (active === initials.length) {
|
|
active = 0;
|
|
}
|
|
this.updateInitials();
|
|
break;
|
|
case 40:
|
|
code = initials[active].initial.charCodeAt(0);
|
|
code++;
|
|
if (code === 91) {
|
|
code = 65;
|
|
}
|
|
initials[active].initial = String.fromCharCode(code);
|
|
this.updateInitials();
|
|
break;
|
|
}
|
|
|
|
if (e.keyCode >= 65 && e.keyCode <= 90) {
|
|
initials[active].initial = String.fromCharCode(e.keyCode);
|
|
|
|
if (active < initials.length - 1) {
|
|
active++;
|
|
}
|
|
this.updateInitials();
|
|
}
|
|
},
|
|
|
|
updateInitials: () => {
|
|
initials = initials.map((v) => {
|
|
v.active = false;
|
|
return v;
|
|
});
|
|
|
|
initials[active].active = true;
|
|
|
|
dispatch(WelcomeActions.updateInitials(initials));
|
|
},
|
|
|
|
updateScores: (scores) => {
|
|
// [
|
|
// { initials: "ABA", score: "219283", rank: "1" },
|
|
// { initials: "ABA", score: "107112", rank: "2" },
|
|
// { initials: "ABA", score: "81091", rank: "3" },
|
|
// { initials: "ABA", score: "67747", rank: "4" },
|
|
// { initials: "ABA", score: "9283", rank: "5" },
|
|
// { initials: "ABA", score: "928", rank: "6" }
|
|
// ];
|
|
|
|
// localStorage.setItem(SETTINGS.LOCAL_STORAGE_KEY, scores);
|
|
}
|
|
};
|
|
|
|
export default InitialsCtrl;
|
|
|