Forked from ejuher/components.connection-rater\.js
Created
December 22, 2020 19:13
-
-
Save bjbatten/b4ce37873c7beb71775b25a9a14f3dd5 to your computer and use it in GitHub Desktop.
Connection Rater Interview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
export default class extends Component { | |
downHandler(connections, currentIndex) { | |
connections[currentIndex].active = false; | |
if (currentIndex < connections.length - 1) { | |
currentIndex += 1; | |
} | |
connections[currentIndex].active = true; | |
return currentIndex; | |
} | |
upHandler(connections, currentIndex) { | |
connections[currentIndex].active = false; | |
if (currentIndex > 0) { | |
currentIndex -= 1; | |
} | |
connections[currentIndex].active = true; | |
return currentIndex; | |
} | |
constructor() { | |
super(...arguments); | |
// connections is provided here and is the same as @connections in the hbs file | |
const connections = this.args.connections | |
// 1) Apply the class "alert-info" to the first connection | |
connections[0].active = true; | |
var currentConnectionIndex = 0; | |
const downKey = 40; | |
const upKey = 38; | |
const yKey = 89; | |
const nKey = 78; | |
Ember.$(document).on('keydown', (e) => { | |
console.log(e.keyCode) | |
// 2) Use up/down arrow keys to move the "alert-info" class between connections | |
switch(e.keyCode) { | |
case 40: | |
currentConnectionIndex = this.downHandler(connections, currentConnectionIndex); | |
break; | |
case 38: | |
currentConnectionIndex = this.upHandler(connections, currentConnectionIndex); | |
break; | |
case 89: | |
connections[currentConnectionIndex].positiveRating = true; | |
connections[currentConnectionIndex].negativeRating = null; | |
break; | |
case 78: | |
connections[currentConnectionIndex].positiveRating = null; | |
connections[currentConnectionIndex].negativeRating = true; | |
break; | |
default: | |
console.log('other') | |
} | |
// 3) Use y/n keys to add the"rating-choice" class to Yes/No for the currently selected connection | |
}) | |
} | |
upDownHandler(key, connection, currentIndex){ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { tracked } from '@glimmer/tracking'; | |
import { A } from '@ember/array'; | |
export default class ApplicationController extends Controller { | |
appName = 'ICC Connection Rater'; | |
@tracked connections = A([ | |
new Connection('Amy'), | |
new Connection('Bob'), | |
new Connection('Carrie'), | |
new Connection('Dan') | |
]); | |
// @tracked activeConnections; | |
get activeConnections() { | |
var positives = this.connections.filter((connection) => { | |
return connection.positiveRating == true; | |
}); | |
return positives.length; | |
// return activeConnectionCount; | |
} | |
} | |
class Connection { | |
constructor(name) { | |
this.name = name | |
} | |
@tracked name | |
@tracked active = false | |
@tracked positiveRating | |
@tracked negativeRating | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.16.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment