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.
 
 

75 lines
1.9 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 37:
active--;
if (active === -1) {
active = initials.length - 1;
}
this.update();
break;
case 38:
code = initials[active].initial.charCodeAt(0);
code--;
if (code === 64) {
code = 90;
}
initials[active].initial = String.fromCharCode(code);
this.update();
break;
case 39:
active++;
if (active === initials.length) {
active = 0;
}
this.update();
break;
case 40:
code = initials[active].initial.charCodeAt(0);
code++;
if (code === 91) {
code = 65;
}
initials[active].initial = String.fromCharCode(code);
this.update();
break;
}
if (e.keyCode >= 65 && e.keyCode <= 90) {
initials[active].initial = String.fromCharCode(e.keyCode);
if (active < initials.length - 1) {
active++;
}
this.update();
}
},
update: () => {
initials = initials.map((v) => {
v.active = false;
return v;
});
initials[active].active = true;
dispatch(WelcomeActions.updateInitials(initials));
}
};
export default InitialsCtrl;