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): update raise hand styles #1925

Merged
merged 1 commit into from
May 10, 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,10 +1,11 @@
import "./style.less";

import React, { useCallback, useEffect, useMemo, useState } from "react";
import React, { useCallback, useMemo, useState } from "react";
import classNames from "classnames";
import { isInteger } from "lodash-es";
import { useTranslate } from "@netless/flat-i18n";
import { SVGHandUp } from "../../FlatIcons";
import { useIsUnMounted } from "../../../utils/hooks";

export interface RaiseHandProps {
isRaiseHand?: boolean;
Expand All @@ -18,30 +19,31 @@ export const RaiseHand: React.FC<RaiseHandProps> = ({
onRaiseHandChange,
}) => {
const t = useTranslate();
const [active, setActive] = useState(false);
const isUnmounted = useIsUnMounted();
// if temp is not null, use temp, otherwise use isRaiseHand
const [temp, setTemp] = useState<boolean | null>(null);

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

const onClick = useCallback(() => {
onRaiseHandChange();
setActive(true);
}, [onRaiseHandChange]);

useEffect(() => {
if (active) {
const timer = setTimeout(() => setActive(false), 3000);
return () => clearTimeout(timer);
}
return;
}, [active]);
setTemp(!active);
setTimeout(() => {
if (!isUnmounted.current) {
setTemp(null);
}
}, 3000);
}, [active, isUnmounted, onRaiseHandChange]);

return disableHandRaising ? null : (
<button
className={classNames("raise-hand-btn", {
"is-active": isRaiseHand || active,
"is-active": active,
})}
title={t("raise-your-hand")}
onClick={onClick}
>
<SVGHandUp active={isRaiseHand || active} />
<SVGHandUp active={active} />
</button>
);
};
Expand Down
8 changes: 6 additions & 2 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,17 @@ export class ClassroomStore {
}

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

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

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

Expand Down