Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(flat-components): hide raise hand button if creator left #1928

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./style.less";

import React, { useCallback, useMemo, useState } from "react";
import React, { useCallback, useMemo, useRef, useState } from "react";
import classNames from "classnames";
import { isInteger } from "lodash-es";
import { useTranslate } from "@netless/flat-i18n";
Expand All @@ -10,7 +10,7 @@ import { useIsUnMounted } from "../../../utils/hooks";
export interface RaiseHandProps {
isRaiseHand?: boolean;
disableHandRaising?: boolean;
onRaiseHandChange: () => void;
onRaiseHandChange: (raise: boolean) => void;
}

export const RaiseHand: React.FC<RaiseHandProps> = ({
Expand All @@ -21,14 +21,16 @@ export const RaiseHand: React.FC<RaiseHandProps> = ({
const t = useTranslate();
const isUnmounted = useIsUnMounted();
// if temp is not null, use temp, otherwise use isRaiseHand
const timerRef = useRef(0);
const [temp, setTemp] = useState<boolean | null>(null);

const active = temp === null ? isRaiseHand : temp;

const onClick = useCallback(() => {
onRaiseHandChange();
onRaiseHandChange(!active);
setTemp(!active);
setTimeout(() => {
clearTimeout(timerRef.current);
timerRef.current = window.setTimeout(() => {
if (!isUnmounted.current) {
setTemp(null);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/flat-pages/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { UserWindows } from "./UserWindows";
export interface WhiteboardProps {
whiteboardStore: WhiteboardStore;
classRoomStore: ClassroomStore;
disableHandRaising?: boolean;
}

const noop = (): void => {
Expand All @@ -38,7 +37,6 @@ const noop = (): void => {
export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({
whiteboardStore,
classRoomStore,
disableHandRaising,
}) {
const t = useTranslate();
const { room, windowManager, phase, whiteboard } = whiteboardStore;
Expand All @@ -55,6 +53,7 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({

const isReconnecting = phase === RoomPhase.Reconnecting;
const handRaisingCount = classRoomStore.users.handRaisingJoiners.length;
const creatorHasLeft = !classRoomStore.users.creator || classRoomStore.users.creator.hasLeft;

useEffect(() => {
return whiteboard.events.on("exportAnnotations", () => showSaveAnnotation(true));
Expand Down Expand Up @@ -213,7 +212,7 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({
!classRoomStore.users.currentUser.isSpeak && (
<div className="raise-hand-container">
<RaiseHand
disableHandRaising={disableHandRaising}
disableHandRaising={creatorHasLeft}
isRaiseHand={classRoomStore.users.currentUser?.isRaiseHand}
onRaiseHandChange={classRoomStore.onToggleHandRaising}
/>
Expand Down
8 changes: 4 additions & 4 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,21 +1050,21 @@ export class ClassroomStore {
};

/** When current user (who is a joiner) raises hand */
public onToggleHandRaising = (): void => {
public onToggleHandRaising = (raise?: boolean): void => {
if (this.isCreator || this.users.currentUser?.isSpeak) {
return;
}

if (this.users.currentUser) {
const nextState = !this.users.currentUser.isRaiseHand;
raise ??= !this.users.currentUser.isRaiseHand;

void this.rtm.sendPeerCommand(
"raise-hand",
{ roomUUID: this.roomUUID, raiseHand: nextState },
{ roomUUID: this.roomUUID, raiseHand: raise },
this.ownerUUID,
);

if (nextState) {
if (raise) {
message.info(FlatI18n.t("have-raised-hand"));
}
}
Expand Down