~sirn/fanboi2

ref: 5b482cfc1bfb0bb1e89715cb57c7bac864391768 fanboi2/assets/app/javascripts/views/board_selector_view.ts -rw-r--r-- 1.1 KiB
5b482cfcKridsada Thanabulpong 0.30.0 3 years ago
                                                                                
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
import {VNode, h} from 'virtual-dom';
import {Board} from '../models/board';
import {BoardView} from './board_view';


export class BoardSelectorView {
    boardListNode: VNode[];

    constructor(boards: Board[]) {
        this.boardListNode = BoardSelectorView.renderBoards(boards);
    }

    render(args: any = {}): VNode {
        return h('div', BoardSelectorView.getViewClassName(args), [
            h('div', {className: 'js-board-selector-inner'},
                this.boardListNode
            )
        ]);
    }

    private static renderBoards(boards: Board[]): VNode[] {
        return boards.map((board: Board): VNode => {
            return new BoardView(board).render();
        })
    }

    private static getViewClassName(args: any): any {
        const className = 'js-board-selector';

        if (args.className) {
            let classNames = args.className.split(' ');
            classNames.push(className);
            args.className = classNames.join(' ');
        } else {
            args.className = className;
        }

        return args;
    }
}