Commit ·
bf3c5a1
1
Parent(s): fd23539
feature(#137): created module for getting data from real time database of firebase...
Browse files
Extension/src/pages/Panel/Panel.jsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import React, {useEffect, useRef, useState} from 'react';
|
| 2 |
import {Divider, Input, Layout} from 'antd';
|
| 3 |
import {SendOutlined} from '@ant-design/icons';
|
| 4 |
-
import { onValue, ref } from "firebase/database";
|
| 5 |
|
| 6 |
import Message from './Message'
|
| 7 |
import './Panel.css';
|
| 8 |
-
import
|
| 9 |
|
| 10 |
const {Footer, Content} = Layout;
|
| 11 |
const confs = {
|
|
@@ -55,7 +55,6 @@ const Panel = () => {
|
|
| 55 |
if (message === "") return;
|
| 56 |
|
| 57 |
if (!type && !isLoading) {
|
| 58 |
-
console.log("delete loading")
|
| 59 |
messages.pop()
|
| 60 |
}
|
| 61 |
|
|
@@ -235,12 +234,43 @@ const Panel = () => {
|
|
| 235 |
}
|
| 236 |
|
| 237 |
const autoTask = (referenceUrl) => {
|
| 238 |
-
|
| 239 |
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
}, (error) => {
|
| 245 |
console.error(error);
|
| 246 |
})
|
|
|
|
| 1 |
import React, {useEffect, useRef, useState} from 'react';
|
| 2 |
import {Divider, Input, Layout} from 'antd';
|
| 3 |
import {SendOutlined} from '@ant-design/icons';
|
| 4 |
+
import { getDatabase, onValue, ref } from "firebase/database";
|
| 5 |
|
| 6 |
import Message from './Message'
|
| 7 |
import './Panel.css';
|
| 8 |
+
import app from '../../configs/firebase-config'
|
| 9 |
|
| 10 |
const {Footer, Content} = Layout;
|
| 11 |
const confs = {
|
|
|
|
| 55 |
if (message === "") return;
|
| 56 |
|
| 57 |
if (!type && !isLoading) {
|
|
|
|
| 58 |
messages.pop()
|
| 59 |
}
|
| 60 |
|
|
|
|
| 234 |
}
|
| 235 |
|
| 236 |
const autoTask = (referenceUrl) => {
|
| 237 |
+
const refUrl = referenceUrl.slice(1)
|
| 238 |
|
| 239 |
+
// getting real time database
|
| 240 |
+
const db = getDatabase(app)
|
| 241 |
+
const dbRef = ref(db, refUrl);
|
| 242 |
+
|
| 243 |
+
// listen for data changes
|
| 244 |
+
onValue(dbRef, (snapshot) => {
|
| 245 |
+
let data = []
|
| 246 |
+
let result = []
|
| 247 |
+
let resultToStr = ""
|
| 248 |
+
|
| 249 |
+
// getting data object from real time database
|
| 250 |
+
if (snapshot.val() !== null && snapshot.val() !== undefined) {
|
| 251 |
+
data = Object.values(snapshot.val())
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
if (typeof data[data.length - 1] !== 'undefined' && data[data.length-1].hasOwnProperty('thoughts')) {
|
| 255 |
+
result.push(data[data.length-1].thoughts)
|
| 256 |
+
} else if (typeof data[data.length - 1] !== 'undefined' && data[data.length-1].hasOwnProperty('result')) {
|
| 257 |
+
result.push(data[data.length-1])
|
| 258 |
+
}
|
| 259 |
|
| 260 |
+
// convert json object to string
|
| 261 |
+
result?.map(item => {
|
| 262 |
+
if (item.hasOwnProperty('result')) {
|
| 263 |
+
resultToStr += "result:" + item.result + "\n\n\n\n"
|
| 264 |
+
} else if (item.hasOwnProperty('criticism')) {
|
| 265 |
+
resultToStr += "criticism:" + item.criticism + "\n" +
|
| 266 |
+
"plan" + item.plan + "\n" +
|
| 267 |
+
"reasoning" + item.reasoning + "\n" +
|
| 268 |
+
"speak" + item.speak + "\n" +
|
| 269 |
+
"text" + item.text + "\n\n"
|
| 270 |
+
}
|
| 271 |
+
})
|
| 272 |
+
|
| 273 |
+
addMessage(resultToStr, false)
|
| 274 |
}, (error) => {
|
| 275 |
console.error(error);
|
| 276 |
})
|