Skip to content

Instantly share code, notes, and snippets.

@mastastealth
Last active October 6, 2020 01:37
Show Gist options
  • Save mastastealth/6de6fb20165f1029a39953af67e324bd to your computer and use it in GitHub Desktop.
Save mastastealth/6de6fb20165f1029a39953af67e324bd to your computer and use it in GitHub Desktop.
Octane Mini Quiz
import Component from '@glimmer/component';
export default class Notes extends Component {
get itemCount() {
return `(${this.items?.length || 0})`;
}
}
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
@tracked inputValue = '';
@tracked items = [
"Ask about this.",
"Ask about that."
]
@action
submit() {
this.items.push(this.inputValue);
this.inputValue = '';
}
}
body {
background: #EEF;
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
h1 { text-align: center; }
ol {
background: #FFE;
border: 1px solid goldenrod;
margin-bottom: 50px;
padding: 15px;
list-style-position: inside;
margin: 0 auto 20px;
max-width: 50%;
}
.note-block {
background: white;
border: 1px solid #333;
border-radius: 4px;
box-shadow: 0 0 4px rgba(255, 0, 255, 0.2);
margin: 0 auto;
padding: 10px;
max-width: 50%;
}
.note-item-empty {
color: #999;
font-style: italic;
}
input { max-width: 100%; }
.note-block hr { margin: 20px 0; }
<h1>Octane Mini-Quiz</h1>
<ol>
<li>Why don't the notes in my controller display?</li>
<li>Why won't the button add a new note to the list?</li>
<li>Why won't the note count update?</li>
</ol>
<Notes
@items={{this.items}}
@inputValue={{this.inputValue}}
@submit={{fn this.submit}}
/>
<div class="note-block">
<h3>My Notes {{this.itemCount}}:</h3>
<div class="note-items">
{{#if this.items.length}}
{{#each this.items as |item|}}
<div class="note-item">{{item}}</div>
{{/each}}
{{else}}
<div class="note-item note-item-empty">No items.</div>
{{/if}}
</div>
<hr />
<Input @placeholder="Add Item" @value={{@inputValue}} />
<button {{on "click" @submit}}>Add Note</button>
</div>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true,
"_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.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment