aboutsummaryrefslogtreecommitdiff
path: root/static/pages/main/index.js
blob: 9bf0aaeecf7a83b37d500a21f206f7242d7040c7 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as sfw from 'sfw';
const { Div, Input } = sfw.element.native;

import icons from '/icons/index.js';

const css = await sfw.css(import.meta.url, './index.css');

export default class MainView extends sfw.element.Container {
	#active_kind
	#active_button
	#active_view
	#bar

	static Kind = Object.freeze({
		'upload': 0,
		'home': 1,
	});

	constructor() {
		super({ css });

		this.onsearch = () => {}
		this.onmonth = () => {}
		this.onupload = () => {}
		this.onshuffle = () => {}
		this.onhome = () => {}

		this.body.append(
			this.#active_view = Div.new({ id: 'main' }),

			this.#bar = Div.new({
				id: 'bar',
				children: [
					Div.new({
						className: 'menu-button',
						children: [ icons.search ],
						onclick: (e) => {
							e.stopPropagation();
							this.onsearch();
						}
					}),

					Div.new({
						className: 'menu-button',
						children: [ icons.calendar ],
						onclick: () => this.onmonth(),
					}),

					this.#active_button = Div.new({
						className: 'menu-button add',
						children: [ icons.add ],
						onclick: () => this.onupload()
					}),

					Div.new({
						className: 'menu-button',
						children: [ icons.shuffle ],
						onclick: () => this.onshuffle(),
					}),

					Div.new({
						className: 'menu-button',
						children: [ icons.settings ],
						onclick: () => this.onsettings(),
					}),
				],
			}),
		);
	}

	hide() {
		this.#bar.classList.add('hidden');
	}

	show() {
		this.#bar.classList.remove('hidden');
	}

	set active_view(element) {
		this.#active_view.innerHTML = '';
		this.#active_view.append(element);
	}

	set active_kind(kind) {
		if (kind == MainView.Kind.home) {
			this.#active_button.innerHTML = '';
			this.#active_button.append(icons.home);
			this.#active_button.onclick = () => this.onhome();
		} else if (kind == MainView.Kind.upload) {
			this.#active_button.innerHTML = '';
			this.#active_button.append(icons.add);
			this.#active_button.onclick = () => this.onupload();
		} else {
			console.error(`invalid kind ${kind}`);
		}
	}
}