summaryrefslogtreecommitdiffstats
path: root/history.mjs
blob: e09073aa6ebf0b033f9d65b96690c1de8a2e2768 (plain)
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
export default class extends HTMLElement {
    static name = 'x-chords-history'
    static register() {
        console.debug('Registering Element', this.name, this);
        customElements.define(this.name, this);
    }

    delayMs = 1000;
    #list

    oldList = [
        'GCEGCE',
        'EBEGBE'
    ];

    constructor() {
        super();

        console.debug('History#constructor', this);
        this.onClick = e => console.debug('history click', e);
    }

    connectedCallback() {
        console.debug('History#connectedCallback', this);
        this.template = this.querySelector('template');
        this.list = this.querySelector('ol');

        // mess around with custom states
        this._internals = this.attachInternals();
    }

    add(fretboard) {
        console.debug('History#add', this, fretboard);
        this._internals.states.add('fresh');
        setTimeout(_ => this._internals.states.delete('fresh'),
            this.delayMs);

        const item = this.template.content.cloneNode(true);
        // TODO: i don't think this is how slots are supposed to work,
        // but maybe they're not really for this at all?
        item.querySelectorAll('[name="fretboard"]')
            .forEach(s => s.textContent = fretboard.notes.join(' '));
        this.list.appendChild(item);
    }
}