This commit is contained in:
Half-Shot
2024-10-28 12:46:26 +00:00
parent a23d256fb6
commit 43b4fc0a0c
3 changed files with 16 additions and 14 deletions

View File

@@ -15,18 +15,18 @@ configure({
});
describe("RaisedHandIndicator", () => {
test("renders nothing when no hand has been raised", async () => {
test("renders nothing when no hand has been raised", () => {
const { container } = render(<RaisedHandIndicator />);
expect(container.firstChild).toBeNull();
});
test("renders an indicator when a hand has been raised", async () => {
test("renders an indicator when a hand has been raised", () => {
const dateTime = new Date();
const { container } = render(
<RaisedHandIndicator raisedHandTime={dateTime} />,
);
expect(container.firstChild).toMatchSnapshot();
});
test("renders an indicator when a hand has been raised with the expected time", async () => {
test("renders an indicator when a hand has been raised with the expected time", () => {
const dateTime = new Date(new Date().getTime() - 60000);
const { container } = render(
<RaisedHandIndicator raisedHandTime={dateTime} />,

View File

@@ -1,18 +1,26 @@
import { useEffect, useState } from "react";
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
*/
import { ReactNode, useEffect, useState } from "react";
import styles from "./RaisedHandIndicator.module.css";
export function RaisedHandIndicator({
raisedHandTime,
}: {
raisedHandTime?: Date;
}) {
}): ReactNode {
const [raisedHandDuration, setRaisedHandDuration] = useState("");
useEffect(() => {
if (!raisedHandTime) {
return;
}
const calculateTime = () => {
const calculateTime = (): void => {
const totalSeconds = Math.ceil(
(new Date().getTime() - raisedHandTime.getTime()) / 1000,
);
@@ -22,8 +30,8 @@ export function RaisedHandIndicator({
`${minutes < 10 ? "0" : ""}${minutes}:${seconds < 10 ? "0" : ""}${seconds}`,
);
};
const to = setInterval(calculateTime, 1000);
calculateTime();
const to = setInterval(calculateTime, 1000);
return (): void => clearInterval(to);
}, [setRaisedHandDuration, raisedHandTime]);

View File

@@ -8,13 +8,7 @@ Please see LICENSE in the repository root for full details.
import { TrackReferenceOrPlaceholder } from "@livekit/components-core";
import { animated } from "@react-spring/web";
import { RoomMember } from "matrix-js-sdk/src/matrix";
import {
ComponentProps,
ReactNode,
forwardRef,
useEffect,
useState,
} from "react";
import { ComponentProps, ReactNode, forwardRef } from "react";
import { useTranslation } from "react-i18next";
import classNames from "classnames";
import { VideoTrack } from "@livekit/components-react";