Skip to content
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
63 changes: 51 additions & 12 deletions src/components/modal/component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { useEffect, useState } from 'react';
import { PickUserModalProps } from './types';
import { PickedUserViewComponent } from './picked-user-view/component';
import Styled from './styles';
Expand All @@ -13,32 +14,65 @@ export function PickUserModal(props: PickUserModalProps) {
updatePickedRandomUser,
pickedUserWithEntryId,
currentUser,
isBot,
} = props;

const [progress, setProgress] = useState(0);

const isYou = (pickedUserWithEntryId?.pickedUser?.userId === currentUser?.userId);

useEffect(() => {
if (isBot && showModal) {
setProgress(0);
const startTime = Date.now();
const duration = 5000; // Modal will be displayed for 5 seconds

const interval = setInterval(() => {
const elapsed = Date.now() - startTime;
const newProgress = (elapsed / duration) * 100;

if (newProgress >= 100) {
setProgress(100);
clearInterval(interval);
handleCloseModal();
} else {
setProgress(newProgress);
}
}, 30);

return () => clearInterval(interval);
}
return () => {};
}, [isBot, showModal, handleCloseModal]);

const title = isYou
? intl.formatMessage(intlMessages.youWerePicked)
: intl.formatMessage(intlMessages.pickedUser);

if (!showModal) return null;

return (
<Styled.PluginModal
overlayClassName="modal-overlay"
overlayClassName="modalOverlay"
portalClassName="modal-low"
parentSelector={() => document.querySelector('#modals-container') as HTMLElement}
isOpen={showModal}
onRequestClose={handleCloseModal}
>
<Styled.ModalContainer>
<Styled.ButtonClose
type="button"
onClick={() => {
handleCloseModal();
}}
aria-label={intl.formatMessage(intlMessages.closeButton)}
>
<i
className="icon-bbb-close"
/>
</Styled.ButtonClose>
{!isBot && (
<Styled.ButtonClose
type="button"
onClick={() => {
handleCloseModal();
}}
aria-label={intl.formatMessage(intlMessages.closeButton)}
>
<i
className="icon-bbb-close"
/>
</Styled.ButtonClose>
)}
</Styled.ModalContainer>
<PickedUserViewComponent
{...{
Expand All @@ -49,6 +83,11 @@ export function PickUserModal(props: PickUserModalProps) {
isYou,
}}
/>
{isBot && showModal && (
<Styled.ProgressBarContainer>
<Styled.ProgressBarFill progress={progress} />
</Styled.ProgressBarContainer>
)}
</Styled.PluginModal>
);
}
22 changes: 22 additions & 0 deletions src/components/modal/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from 'styled-components';
import ReactModal from 'react-modal';
import { colorGrayLightest, colorPrimary } from '../../styles/pallete';

const PluginModal = styled(ReactModal)`
position: relative;
Expand Down Expand Up @@ -95,9 +96,30 @@ const ButtonClose = styled.button`
}
`;

const ProgressBarContainer = styled.div`
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4px;
background-color: ${colorGrayLightest};
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
overflow: hidden;
`;

const ProgressBarFill = styled.div<{ progress: number }>`
height: 100%;
background-color: ${colorPrimary};
width: ${({ progress }) => `${progress}%`};
transition: width 0.03s linear;
`;

export default {
PluginModal,
ModalOverlay,
ModalContainer,
ButtonClose,
ProgressBarContainer,
ProgressBarFill,
};
1 change: 1 addition & 0 deletions src/components/modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface PickUserModalProps {
handleCloseModal: () => void;
pickedUserWithEntryId: PickedUserWithEntryId;
currentUser: CurrentUserData;
isBot: boolean;
}
2 changes: 1 addition & 1 deletion src/components/pick-random-user-panel/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function PickRandomUserPanelComponent(props: PickRandomUserPanelComponent
includePickedUsers,
]);

const usersToBePicked: PickedUser[] = allUsers?.user
const usersToBePicked: PickedUser[] = (allUsers?.user ?? []).filter((user) => !user.bot)
.filter((user) => {
let roleFilter = true;
if (!includeModerators) roleFilter = user.role === Role.VIEWER;
Expand Down
4 changes: 3 additions & 1 deletion src/components/pick-random-user-panel/queries.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// TODO: Replace this query with the useUsersBasicInfo once it's merged in
export const USERS_MORE_INFORMATION = `
subscription usersMoreInformation {
user {
user(where: { bot: { _eq: false } }) {
color
name
userId
role
presenter
bot
}
}
`;
6 changes: 6 additions & 0 deletions src/components/pick-random-user/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import * as ReactDOM from 'react-dom/client';

import { GenericContentSidekickArea } from 'bigbluebutton-html-plugin-sdk';
import {
BotDataWrapper,
PickRandomUserPluginProps,
PickedUser,
PickedUserWithEntryId,
} from './types';
import { PickUserModal } from '../modal/component';
import { Role } from './enums';
import { BOT_SUBSCRIPTION } from './queries';
import { PickRandomUserPanelComponent } from '../pick-random-user-panel/component';
import { intlMessages } from '../../intlMessages';

Expand All @@ -23,6 +25,9 @@ function PickRandomUserPlugin({ pluginApi, intl }: PickRandomUserPluginProps) {
const shouldPluginUnmount = pluginApi.useShouldUnmountPlugin();
const currentUserInfo = pluginApi.useCurrentUser();
const { data: currentUser } = currentUserInfo;
const { data: botData } = pluginApi
.useCustomSubscription!<BotDataWrapper>(BOT_SUBSCRIPTION) || {};
const isBot = botData?.user_current?.[0]?.bot || false;

const {
data: pickedUserFromDataChannelResponse,
Expand Down Expand Up @@ -105,6 +110,7 @@ function PickRandomUserPlugin({ pluginApi, intl }: PickRandomUserPluginProps) {
if (!pickedUserWithEntryId) return null;
return !shouldPluginUnmount && (
<PickUserModal
isBot={isBot}
{...{
intl,
showModal,
Expand Down
7 changes: 7 additions & 0 deletions src/components/pick-random-user/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const BOT_SUBSCRIPTION = `
subscription BotData {
user_current {
bot
}
}
`;
9 changes: 9 additions & 0 deletions src/components/pick-random-user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface PickedUser {
name: string;
role: string;
color: string;
bot: boolean;
}

export interface PickedUserWithEntryId {
Expand Down Expand Up @@ -41,3 +42,11 @@ export interface DataChannelPickedUserResponse {
export interface DataChannelLastResetTimeResponse {
pluginDataChannelMessage: DataChannelArrayMessages<Date>[];
}

export interface BotData {
bot: boolean
}

export interface BotDataWrapper {
user_current: BotData[];
}
Loading