1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 04:04:58 +03:00

feat(web app): render widget

This commit is contained in:
louistiti 2023-05-15 21:25:20 +08:00
parent 34aa188643
commit 63573083fa
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
3 changed files with 18 additions and 2 deletions

View File

@ -60,6 +60,9 @@ export default class Chatbot {
}
loadFeed() {
/**
* TODO: widget: load widget from local storage
*/
return new Promise((resolve) => {
if (this.parsedBubbles === null || this.parsedBubbles.length === 0) {
this.noBubbleMessage.classList.remove('hide')

View File

@ -1,5 +1,8 @@
import { io } from 'socket.io-client'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { Button } from './aurora/button'
import Chatbot from './chatbot'
export default class Client {
@ -64,8 +67,19 @@ export default class Client {
})
this.socket.on('widget', (data) => {
/**
* TODO: widget: widget handler to core/skill; dynamic component rendering
*/
console.log('data', data)
// TODO: render widget via React
const container = document.createElement('div')
container.className = 'widget'
this.chatbot.feed.appendChild(container)
const root = createRoot(container)
// TODO: widget: pass props and dynamic component loading according to type
root.render(Button({ children: 'OK' }))
})
this.socket.on('audio-forwarded', (data, cb) => {

View File

@ -198,7 +198,6 @@ export default class Brain {
LogHelper.title(`${this.skillFriendlyName} skill (on data)`)
LogHelper.info(data.toString())
// TODO: widget
if (obj.output.widget) {
SOCKET_SERVER.socket?.emit('widget', obj.output.widget)
}