diff options
Diffstat (limited to 'static/pages/settings/index.js')
| -rw-r--r-- | static/pages/settings/index.js | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/static/pages/settings/index.js b/static/pages/settings/index.js index c11a3e9..f316e8e 100644 --- a/static/pages/settings/index.js +++ b/static/pages/settings/index.js @@ -1,6 +1,8 @@ import * as sfw from 'sfw'; const { Div, Img } = sfw.element.native; +import * as api from '../../api/index.js'; + import Editable from '../../widgets/editable/index.js'; import icons from '../../icons/index.js'; @@ -8,6 +10,12 @@ import icons from '../../icons/index.js'; const css = await sfw.css(import.meta.url, './index.css'); export default class SettingsView extends sfw.element.Container { + #profile_image + #name + #birthday + + #profile + constructor() { super({ css }); @@ -23,23 +31,35 @@ export default class SettingsView extends sfw.element.Container { Div.new({ id: 'image-container', children: [ - Img.new(), + this.#profile_image = Img.new(), ] }), Div.new({ id: 'edit', - children: [ icons.edit ] + children: [ icons.edit ], + onclick: async () => { + const uploader = await api.images.upload_to_profile(this.#profile.name); + uploader.ondone = async () => { + const blob = await fetch( + `/api/profile/image/load/${this.#profile.name}`, + {cache: 'reload', mode: 'no-cors'} + ).then(r => r.blob()); + + this.#profile_image.src = URL.createObjectURL(blob); + }; + uploader.send() + } }), ] }), - Editable.new({ + this.#name = Editable.new({ title: 'Name', - value: 'Nathan Reiner' + value: '' }), - Editable.new({ + this.#birthday = Editable.new({ title: 'Birthday', type: 'date', - value: '2002-08-06', + value: '', }), Div.new({ id: 'logout', @@ -57,4 +77,18 @@ export default class SettingsView extends sfw.element.Container { }) ) } + + set profile(profile) { + this.#profile = profile; + + this.#profile_image.src = `/api/profile/image/load/${profile.name}`; + this.#profile_image.onerror = () => this.#profile_image.removeAttribute('src'); + + this.#name.value = profile.full_name; + this.#birthday.value = profile.birthday; + } + + get profile() { + return this.#profile; + } } |