From ac623b5f93db72ec5432b5ee556717629ff19a6d Mon Sep 17 00:00:00 2001 From: Rocka Date: Sat, 14 Dec 2024 14:39:54 +0800 Subject: [PATCH 1/2] feat(web): update ui after login or stream operation --- web/liveman/components/nodes-table.tsx | 15 +++++++-- web/liveman/liveman.tsx | 2 +- web/shared/api.ts | 8 ++--- web/shared/authorization-middleware.ts | 2 +- web/shared/components/dialog-new-stream.tsx | 6 ++-- web/shared/components/page-layout.tsx | 6 ++-- web/shared/components/streams-table.tsx | 34 ++++++++++++++------- 7 files changed, 49 insertions(+), 24 deletions(-) diff --git a/web/liveman/components/nodes-table.tsx b/web/liveman/components/nodes-table.tsx index 1aeb949..ae6d9f5 100644 --- a/web/liveman/components/nodes-table.tsx +++ b/web/liveman/components/nodes-table.tsx @@ -1,6 +1,9 @@ -import { Button, Checkbox, Dropdown, Link, Table } from 'react-daisyui'; +import { useContext, useEffect } from 'preact/hooks'; + +import { Badge, Button, Checkbox, Dropdown, Link, Table } from 'react-daisyui'; import { ArrowPathIcon, EllipsisHorizontalIcon } from '@heroicons/react/24/outline'; +import { TokenContext } from '@/shared/context'; import { useRefreshTimer } from '@/shared/hooks/use-refresh-timer'; import { type Node, getNodes } from '../api'; @@ -12,11 +15,19 @@ async function getNodesSorted() { export function NodesTable() { const nodes = useRefreshTimer([], getNodesSorted); + const tokenContext = useContext(TokenContext); + + useEffect(() => { + if (tokenContext.token.length > 0) { + nodes.updateData(); + } + }, [tokenContext.token]); return ( <>
- Nodes (total: {nodes.data.length}) + Nodes + {nodes.data.length} {props.renderExtraActions?.(i)} - +
) : N/A} @@ -187,7 +199,7 @@ export function StreamsTable(props: StreamTableProps) { onClick={handleNewStream} >New Stream {webStreams.map(s => - + )} @@ -218,7 +230,7 @@ export function StreamsTable(props: StreamTableProps) { /> )} - + {webStreams.map(s => Date: Sat, 14 Dec 2024 16:06:23 +0800 Subject: [PATCH 2/2] feat(web): refresh streams table after kicking clients --- web/liveion/components/login.tsx | 2 +- web/shared/components/dialog-clients.tsx | 8 +++++++- web/shared/components/streams-table.tsx | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/liveion/components/login.tsx b/web/liveion/components/login.tsx index 4c343da..8add54a 100644 --- a/web/liveion/components/login.tsx +++ b/web/liveion/components/login.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef, useState } from 'preact/hooks'; import { TargetedEvent } from 'preact/compat'; -import { Alert, Button, Modal } from 'react-daisyui'; +import { Alert, Button, Loading, Modal } from 'react-daisyui'; import { WretchError } from 'wretch/resolver'; import * as api from '@/shared/api'; diff --git a/web/shared/components/dialog-clients.tsx b/web/shared/components/dialog-clients.tsx index 345f065..929c1dd 100644 --- a/web/shared/components/dialog-clients.tsx +++ b/web/shared/components/dialog-clients.tsx @@ -8,6 +8,7 @@ import { formatTime } from '../utils'; interface Props { id: string sessions: Session[] + onClientKicked: () => void } export interface IClientsDialog { @@ -25,6 +26,11 @@ export const ClientsDialog = forwardRef((props: Props, re }; }); + const handleKickClient = async (streamId: string, clientId: string) => { + await deleteSession(streamId, clientId); + props.onClientKicked(); + }; + return ( @@ -44,7 +50,7 @@ export const ClientsDialog = forwardRef((props: Props, re {c.id + (c.reforward ? '(reforward)' : '')} {c.state} {formatTime(c.createdAt)} - + ): N/A} diff --git a/web/shared/components/streams-table.tsx b/web/shared/components/streams-table.tsx index d883d95..8e6308e 100644 --- a/web/shared/components/streams-table.tsx +++ b/web/shared/components/streams-table.tsx @@ -207,6 +207,7 @@ export function StreamsTable(props: StreamTableProps) { ref={refClients} id={selectedStreamId} sessions={streams.data.find(s => s.id == selectedStreamId)?.subscribe.sessions ?? []} + onClientKicked={streams.updateData} /> {props.showCascade ? (