You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaer/lib/components/index.ts

54 lines
1.2 KiB
TypeScript

/*
* index.ts
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-10-22 17:51
* Distributed under terms of the GPL license.
*/
import slide from './slide'
import { v } from '../v2dom'
import logic from '../logic'
import bus from '../bus'
export default class {
slide?: slide
frame: HTMLElement
constructor() {
this.frame = v('voa', this.gen_avatar())
}
mount(root: Element) {
root.appendChild(this.frame)
}
gen_avatar() {
let frame_user = v({
class: 'voa-on',
vclass: [() => logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
children: [() => `<img src="${logic.urlwarp(logic.user.icon || logic.token.refresh.icon!)}" />`],
onclick: () => {
logic.getDetailUser()
if (!this.slide) {
this.slide = new slide()
}
this.slide.show()
// logic.logout()
}
})
let frame_login = v({
class: 'voa-off voa-hover-line-b',
vclass: [() => !logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
children: ['Sign in'],
onclick: () => {
console.log('click login')
bus.emit('login')
}
})
return () => {
if (logic.ready) {
return frame_user
} else {
return frame_login
}
}
}
}