From 618f951aa23ea9099ec1f69d01c28dcc56b8c228 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Thu, 12 May 2022 15:00:52 +0200 Subject: [PATCH] fetch list of streams --- packages/app/src/pages/streams/index.jsx | 54 ++++++++++++++++++----- packages/app/src/pages/streams/index.less | 49 ++++++++++++++++++++ 2 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 packages/app/src/pages/streams/index.less diff --git a/packages/app/src/pages/streams/index.jsx b/packages/app/src/pages/streams/index.jsx index 59110796..1aafb96b 100644 --- a/packages/app/src/pages/streams/index.jsx +++ b/packages/app/src/pages/streams/index.jsx @@ -1,8 +1,9 @@ -import React from 'react' -import axios from "axios" +import React from "react" import * as antd from "antd" import { SelectableList, ActionsBar } from "components" +import "./index.less" + export default class Streams extends React.Component { state = { list: [], @@ -15,38 +16,69 @@ export default class Streams extends React.Component { } updateStreamsList = async () => { - const streams = await this.api.get.streams().catch(error => { + let streams = await this.api.get.streams().catch(error => { console.error(error) antd.message.error(error) - + return false }) + if (streams && Array.isArray(streams)) { + // resolve user_id with user basic data + streams = streams.map(async (stream) => { + const userData = await this.api.get.user(undefined, { user_id: stream.user_id }).catch((error) => { + console.error(error) + antd.message.error(error) + + return false + }) + + if (userData) { + stream.userData = userData + } + + return stream + }) + + streams = await Promise.all(streams) + } + this.setState({ list: streams }) } - onClickItem = (item) => { window.app.setLocation(`/streams/viewer?key=${item}`) } renderListItem = (stream) => { - stream.StreamPath = stream.StreamPath.replace(/^\/live\//, "") - - return
this.onClickItem(stream.StreamPath)}> -

@{stream.StreamPath} #{stream.id}

+ return
this.onClickItem(stream.username)} + className="streaming-item" + > +
+ {stream.userData.username} +
+
+
+

@{stream.userData.username}

+ + #{stream.id} + +
+
} render() { - return
+ return
Refresh
-