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): show offline on-stage users in users panel #1821

Merged
merged 3 commits into from
Feb 2, 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
9 changes: 8 additions & 1 deletion packages/flat-components/src/components/UsersPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ const Row = /* @__PURE__ */ observer(function Row({
<span className="users-panel-list-avatar">
<img src={user.avatar} />
</span>
<span className="users-panel-list-name">{user.name}</span>
{user.hasLeft ? (
<div className="users-panel-list-name-wrapper">
<span className="users-panel-list-name">{user.name}</span>
<span className="users-panel-list-has-left">{t("offline")}</span>
</div>
) : (
<span className="users-panel-list-name">{user.name}</span>
)}
</span>
</td>
<td>
Expand Down
10 changes: 10 additions & 0 deletions packages/flat-components/src/components/UsersPanel/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@
gap: 8px;
}

.users-panel-list-name-wrapper {
display: flex;
flex-direction: column;
}

.users-panel-list-name {
font-size: 14px;
}

.users-panel-list-has-left {
font-size: 12px;
color: var(--danger);
}

.users-panel-btn-group {
white-space: nowrap;
}
Expand Down
1 change: 1 addition & 0 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"raise-hand": "Raise hand",
"raised-hand": "(Hand raised)",
"has-left": "(Has left)",
"offline": "offline",
"say-something": "Say something...",
"send": "send",
"teacher": "Teacher",
Expand Down
1 change: 1 addition & 0 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"end": "结束",
"raised-hand": "(已举手)",
"has-left": "(已离开)",
"offline": "已离线",
"agree": "通过",
"me": "(我)",
"cancel-hand-raising": "取消举手",
Expand Down
13 changes: 9 additions & 4 deletions packages/flat-pages/src/components/UsersButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ export const UsersButton = observer<UsersButtonProps>(function UsersButton({ cla
const [open, setOpen] = useState(false);

const users = useComputed(() => {
const { creator, speakingJoiners, handRaisingJoiners, otherJoiners } = classroom.users;
return creator
? [...speakingJoiners, ...handRaisingJoiners, creator, ...otherJoiners]
: [...speakingJoiners, ...handRaisingJoiners, ...otherJoiners];
const { creator, speakingJoiners, handRaisingJoiners, otherJoiners, offlineJoiners } =
classroom.users;
return [
...speakingJoiners,
...handRaisingJoiners,
...(creator ? [creator] : []),
...offlineJoiners,
...otherJoiners,
];
}).get();

const getDeviceState = useCallback(
Expand Down
1 change: 1 addition & 0 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ export class ClassroomStore {
user.camera = false;
}
});
this.users.updateOfflineJoiners(onStageUsers);

if (!this.isCreator) {
const isJoinerOnStage = Boolean(onStageUsersStorage.state[this.userUUID]);
Expand Down
12 changes: 12 additions & 0 deletions packages/flat-stores/src/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class UserStore {
public handRaisingJoiners = observable.array<User>([]);
/** the rest joiners */
public otherJoiners = observable.array<User>([]);
/** joiners who have left */
public offlineJoiners = observable.array<User>([]);

public get joiners(): User[] {
return [...this.speakingJoiners, ...this.handRaisingJoiners, ...this.otherJoiners];
Expand Down Expand Up @@ -151,6 +153,16 @@ export class UserStore {
unSortedUsers.forEach(this.sortUser);
};

public updateOfflineJoiners(onStageUserUUIDs: string[]): void {
this.offlineJoiners.clear();
for (const userUUID of onStageUserUUIDs) {
const user = this.cachedUsers.get(userUUID);
if (user && user.hasLeft) {
this.offlineJoiners.push(user);
}
}
}

/**
* Fetch info of users who have left the room.
* For RTM message title.
Expand Down