import * as api from 'api'; import * as sfw from 'sfw'; import Month from '../../month.js'; const { Div, Img } = sfw.element.native; const css = await sfw.css(import.meta.url, './index.css') export default class Image extends sfw.element.Container { #container #image #menu #id #month #date constructor() { super ({ css }) this.body.append( this.#container = Div.new({ id: 'container', children: [ this.#image = Img.new({ onload: () => this.#container.classList.add('loaded'), }), Div.new({ id: 'loading' }), this.#menu = Div.new({ id: 'menu', children: [ this.#date = Div.new({ id: 'date' }), Div.new({ id: 'delete', innerText: 'Delete', onclick: () => { api.images.remove(this.#id); this.parentNode.removeChild(this); } }), ] }) ], oncontextmenu: (e) => { this.#menu.classList.toggle('open'); e.preventDefault(); }, ondblclick: (e) => { this.#menu.classList.toggle('open'); e.preventDefault(); } }) ); } set metadata(image) { const date = new Date(image.timestamp * 1000); this.#id = image.id; this.#month = Month.from_unix(image.timestamp); this.#container.classList.remove('loaded'); this.#date.innerText = date.toLocaleDateString() } load() { if (!this.#image.src) { this.#image.src = `/api/image/load/${this.#id}`; } } get month() { return this.#month; } }