Skip to content

Commit

Permalink
feat(flat-pages): add option to hide small class top row (#1918)
Browse files Browse the repository at this point in the history
* feat(flat-pages): add option to hide small class top row

* refactor: add top center info about this
  • Loading branch information
hyrious authored May 10, 2023
1 parent f113eff commit 14c4976
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
margin: 0 (@topbar-content-right-cell-gap / 2) 0 auto;
}

.topbar-content-dimmed {
color: var(--text-weaker);
}

.flat-color-scheme-dark {
.topbar-box {
border-color: var(--grey-8);
Expand All @@ -56,4 +60,8 @@
.topbar-content-divider {
background-color: var(--grey-8);
}

.topbar-content-dimmed {
color: var(--text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AppearancePicker: React.FC<AppearancePickerProps> = ({ value, chang
const t = useTranslate();
return (
<div className="appearance-picker-container">
<Radio.Group value={value} onChange={changeAppearance}>
<Radio.Group name="theme" value={value} onChange={changeAppearance}>
<Radio value={"light"}>
<div className="appearance-picker-option">
<img src={lightSVG} />
Expand Down
6 changes: 5 additions & 1 deletion packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"boot-up-and-run-automatically": "Automatically run on startup",
"chinese": "Chinese",
"general-settings": "General settings",
"general-settings-avatars": "Avatars",
"language": "Language",
"language-settings": "Language settings",
"shortcut-settings": "Shortcut settings",
Expand Down Expand Up @@ -658,5 +659,8 @@
"year": "Last Year"
},
"reward": "reward",
"restore-windows": "restore windows"
"restore-windows": "restore windows",
"show": "Show",
"hide": "Hide",
"avatars-hidden": "Avatars are hidden"
}
6 changes: 5 additions & 1 deletion packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
"switch-to-lecture-mode": "切换为讲课模式",
"recording-completed-tips": "录制完成,可到历史记录查看",
"general-settings": "常规设置",
"general-settings-avatars": "视频\n区域",
"shortcut-settings": "热键设置",
"about-us": "关于我们",
"boot-up-and-run-automatically": "开机自动运行",
Expand Down Expand Up @@ -658,5 +659,8 @@
"year": "最近一年"
},
"reward": "奖杯",
"restore-windows": "复位"
"restore-windows": "复位",
"show": "显示",
"hide": "隐藏",
"avatars-hidden": "视频区域已隐藏"
}
22 changes: 14 additions & 8 deletions packages/flat-pages/src/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ export const SmallClassPage = withClassroomStore<SmallClassPageProps>(
<div className="small-class-realtime-box">
{windowsBtn ? (
<TopBar
// center={renderTopBarCenter()}
center={renderTopBarCenter()}
left={renderTopBarLeft()}
right={renderTopBarRight()}
showWindowsSystemBtn={windowsBtn.showWindowsBtn}
onClickWindowsSystemBtn={windowsBtn.onClickWindowsSystemBtn}
onDoubleClick={windowsBtn.clickWindowMaximize}
/>
) : (
<TopBar left={renderTopBarLeft()} right={renderTopBarRight()} />
<TopBar
center={renderTopBarCenter()}
left={renderTopBarLeft()}
right={renderTopBarRight()}
/>
)}
{renderAvatars()}
<div className="small-class-realtime-content">
Expand Down Expand Up @@ -123,6 +127,7 @@ export const SmallClassPage = withClassroomStore<SmallClassPageProps>(
<div
className="small-class-realtime-avatars"
data-user-uuid="[object Object]"
hidden={!classroomStore.isAvatarsVisible()}
>
<RTCAvatar
avatarUser={classroomStore.users.creator}
Expand Down Expand Up @@ -227,12 +232,13 @@ export const SmallClassPage = withClassroomStore<SmallClassPageProps>(
// );
// }

// function renderTopBarCenter(): React.ReactNode {
// if (!classroomStore.isCreator) {
// return null;
// }
// return renderClassMode();
// }
function renderTopBarCenter(): React.ReactNode {
if (classroomStore.isAvatarsVisible()) {
return null;
} else {
return <div className="topbar-content-dimmed">{t("avatars-hidden")}</div>;
}
}

function renderTopBarRight(): React.ReactNode {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import showAvatarsJPG from "./assets/show-avatars.jpg?url";
import hideAvatarsJPG from "./assets/hide-avatars.jpg?url";

import type { PreferencesButtonProps } from "./index";

import React, { useCallback, useContext } from "react";
import { observer } from "mobx-react-lite";
import { Radio } from "antd";
import { FlatI18n, useLanguage, useTranslate } from "@netless/flat-i18n";
import { RoomType } from "@netless/flat-server-api";
import { AppearancePicker } from "flat-components";
import { PreferencesStoreContext } from "../StoreProvider";

export interface GeneralSettingsProps extends PreferencesButtonProps {}

export const GeneralSettings = observer<GeneralSettingsProps>(function GeneralSettings() {
export const GeneralSettings = observer<GeneralSettingsProps>(function GeneralSettings({
classroom,
}) {
const t = useTranslate();

const language = useLanguage();
Expand All @@ -21,6 +27,8 @@ export const GeneralSettings = observer<GeneralSettingsProps>(function GeneralSe
[preferences],
);

const isSmallClass = classroom.roomType === RoomType.SmallClass;

return (
<div className="preferences-modal-section" id="preferences-0">
<h3 className="preferences-modal-section-title">{t("general-settings")}</h3>
Expand All @@ -31,16 +39,40 @@ export const GeneralSettings = observer<GeneralSettingsProps>(function GeneralSe
<Radio.Group
className="preferences-modal-section-grid-content"
id="language"
name="language"
value={language}
onChange={changeLanguage}
>
<Radio value="zh-CN">
<span className="radio-item-inner">{t("chinese")}</span>
<span>{t("chinese")}</span>
</Radio>
<Radio value="en">
<span className="radio-item-inner">English</span>
<span>English</span>
</Radio>
</Radio.Group>
{isSmallClass && (
<>
<label className="preferences-modal-section-grid-label" htmlFor="avatars">
{t("general-settings-avatars")}
</label>
<Radio.Group
className="preferences-modal-section-grid-content"
id="avatars"
name="avatars"
value={classroom.isAvatarsVisible()}
onChange={classroom.toggleAvatars}
>
<Radio className="preferences-modal-section-radio" value={true}>
<img src={showAvatarsJPG} />
<span>{t("show")}</span>
</Radio>
<Radio className="preferences-modal-section-radio" value={false}>
<img src={hideAvatarsJPG} />
<span>{t("hide")}</span>
</Radio>
</Radio.Group>
</>
)}
<label className="preferences-modal-section-grid-label" htmlFor="theme">
{t("theme")}
</label>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions packages/flat-pages/src/components/PreferencesButton/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,63 @@
align-items: center;
}

.preferences-modal-section-grid-label {
white-space: pre-wrap;
}

.preferences-modal-section-control {
max-width: 320px;
}

.preferences-modal-section-radio {
width: 160px;
height: 120px;
padding: 90px 0 12px 16px;
margin-right: 16px;
border-radius: 6px;
border: 1px solid var(--grey-1);
overflow: hidden;

&::before {
content: '';
position: absolute;
left: 0;
bottom: 0;
display: block;
width: 100%;
height: 38px;
border-top: 1px solid var(--grey-1);
z-index: 200;
}

&::after {
position: absolute;
left: 0;
bottom: 0;
display: block;
width: 100%;
height: 40px;
transition: background-color 0.3s ease;
}

&.ant-radio-wrapper-checked::after {
background-color: var(--blue-1);
}

.ant-radio,
.ant-radio+span {
z-index: 100;
}

.ant-radio+span>img {
position: absolute;
top: 0;
left: 0;
width: 160px;
pointer-events: none;
}
}

.preferences-modal-section-button {
position: relative;
display: flex;
Expand Down Expand Up @@ -248,6 +301,22 @@
border-bottom-color: var(--grey-9);
}

.preferences-modal-section-radio {
border-color: var(--grey-7);

&::before {
border-color: var(--grey-7);
}

&.ant-radio-wrapper-checked::after {
background-color: var(--grey-9);
}

.ant-radio+span>img {
filter: brightness(0.8);
}
}

.preferences-modal-hotkey-setting-content {
.ant-table-header tr>th {
border: none;
Expand Down
8 changes: 8 additions & 0 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,14 @@ export class ClassroomStore {
}
}

public isAvatarsVisible(): boolean {
return globalStore.isAvatarsVisible(this.roomUUID);
}

public toggleAvatars = (): void => {
globalStore.toggleAvatars(this.roomUUID, !this.isAvatarsVisible());
};

private async switchRoomStatus(roomStatus: RoomStatus): Promise<void> {
if (!this.isCreator || this.roomStatusLoading !== RoomStatusLoadingType.Null) {
return;
Expand Down
23 changes: 23 additions & 0 deletions packages/flat-stores/src/global-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class GlobalStore {
* This array holds the rooms that this behavior has been done.
*/
public onStageRoomUUIDs: string[] | undefined = undefined;
/**
* Users can hide avatars (top row) in small class mode.
* This array holds the rooms that its avatars have been hidden.
*/
public hideAvatarsRoomUUIDs: string[] | undefined = undefined;

public get userUUID(): string | undefined {
return this.userInfo?.userUUID;
Expand Down Expand Up @@ -93,6 +98,24 @@ export class GlobalStore {
return this.onStageRoomUUIDs?.includes(roomUUID) ?? false;
};

public isAvatarsVisible = (roomUUID: string): boolean => {
return !this.hideAvatarsRoomUUIDs?.includes(roomUUID);
};

public toggleAvatars = (roomUUID: string, show: boolean): void => {
this.hideAvatarsRoomUUIDs ||= [];
if (show) {
this.hideAvatarsRoomUUIDs = this.hideAvatarsRoomUUIDs.filter(uuid => uuid !== roomUUID);
} else {
if (!this.hideAvatarsRoomUUIDs.includes(roomUUID)) {
this.hideAvatarsRoomUUIDs.push(roomUUID);
}
while (this.hideAvatarsRoomUUIDs.length > 10) {
this.hideAvatarsRoomUUIDs.shift();
}
}
};

public updateToken = (
config: Partial<
Pick<
Expand Down

0 comments on commit 14c4976

Please sign in to comment.