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

fix: fix problem when new user comes in, modal pops up #25

Merged
merged 1 commit into from
Nov 12, 2024
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
Expand Up @@ -6,7 +6,7 @@ import { ActionButtonDropdownManagerProps } from './types';

function ActionButtonDropdownManager(props: ActionButtonDropdownManagerProps): React.ReactNode {
const {
pickedUser,
pickedUserWithEntryId,
currentUser,
pluginApi,
setShowModal,
Expand All @@ -27,7 +27,7 @@ function ActionButtonDropdownManager(props: ActionButtonDropdownManagerProps): R
},
}),
]);
} else if (!currentUser?.presenter && pickedUser) {
} else if (!currentUser?.presenter && pickedUserWithEntryId) {
pluginApi.setActionButtonDropdownItems([
new ActionButtonDropdownSeparator(),
new ActionButtonDropdownOption({
Expand All @@ -43,7 +43,7 @@ function ActionButtonDropdownManager(props: ActionButtonDropdownManagerProps): R
} else {
pluginApi.setActionButtonDropdownItems([]);
}
}, [currentUserInfo, pickedUser]);
}, [currentUserInfo, pickedUserWithEntryId]);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CurrentUserData, GraphqlResponseWrapper, PluginApi } from 'bigbluebutton-html-plugin-sdk';
import { PickedUser } from '../../pick-random-user/types';
import { PickedUserWithEntryId } from '../../pick-random-user/types';

export interface ActionButtonDropdownManagerProps {
pickedUser: PickedUser;
pickedUserWithEntryId: PickedUserWithEntryId;
currentUser: CurrentUserData;
pluginApi: PluginApi;
setShowModal: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down
17 changes: 10 additions & 7 deletions src/components/modal/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function PickUserModal(props: PickUserModalProps) {
showModal,
handleCloseModal,
users,
pickedUser,
updatePickedRandomUser,
pickedUserWithEntryId,
handlePickRandomUser,
currentUser,
filterOutPresenter,
Expand All @@ -29,16 +30,16 @@ export function PickUserModal(props: PickUserModalProps) {
} else {
userRole = (users?.length !== 1) ? 'users' : 'user';
}
const title = (pickedUser?.userId === currentUser?.userId)
const title = (pickedUserWithEntryId?.pickedUser?.userId === currentUser?.userId)
? 'You have been randomly picked'
: 'Randomly picked user';

const [showPresenterView, setShowPresenterView] = useState<boolean>(
currentUser?.presenter && !pickedUser,
currentUser?.presenter && !pickedUserWithEntryId,
);
useEffect(() => {
setShowPresenterView(currentUser?.presenter && !pickedUser);
}, [currentUser, pickedUser]);
setShowPresenterView(currentUser?.presenter && !pickedUserWithEntryId);
}, [currentUser, pickedUserWithEntryId]);
return (
<ReactModal
className="plugin-modal"
Expand All @@ -57,6 +58,7 @@ export function PickUserModal(props: PickUserModalProps) {
onClick={() => {
handleCloseModal();
}}
aria-label="Close button"
>
<i
className="icon-bbb-close"
Expand All @@ -75,7 +77,7 @@ export function PickUserModal(props: PickUserModalProps) {
deletionFunction,
handlePickRandomUser,
dataChannelPickedUsers,
pickedUser,
pickedUserWithEntryId,
users,
userRole,
dispatcherPickedUser,
Expand All @@ -84,8 +86,9 @@ export function PickUserModal(props: PickUserModalProps) {
) : (
<PickedUserViewComponent
{...{
pickedUser,
pickedUserWithEntryId,
title,
updatePickedRandomUser,
currentUser,
setShowPresenterView,
dispatcherPickedUser,
Expand Down
28 changes: 23 additions & 5 deletions src/components/modal/picked-user-view/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@ import { PickedUserViewComponentProps } from './types';
export function PickedUserViewComponent(props: PickedUserViewComponentProps) {
const {
title,
pickedUser,
pickedUserWithEntryId,
currentUser,
updatePickedRandomUser,
setShowPresenterView,
dispatcherPickedUser,
} = props;

React.useEffect(() => {
if (currentUser?.presenter) {
updatePickedRandomUser(pickedUserWithEntryId.entryId, {
...pickedUserWithEntryId.pickedUser,
isPresenterViewing: true,
});
}
return () => {
if (currentUser?.presenter) {
updatePickedRandomUser(pickedUserWithEntryId.entryId, {
...pickedUserWithEntryId.pickedUser,
isPresenterViewing: false,
});
}
};
}, []);

const handleBackToPresenterView = () => {
if (currentUser?.presenter) {
setShowPresenterView(true);
Expand All @@ -24,15 +42,15 @@ export function PickedUserViewComponent(props: PickedUserViewComponentProps) {
>
<h1 className="title">{title}</h1>
{
(pickedUser) ? (
(pickedUserWithEntryId) ? (
<>
<div
className="modal-avatar"
style={{ backgroundColor: `${pickedUser?.color}` }}
style={{ backgroundColor: `${pickedUserWithEntryId.pickedUser?.color}` }}
>
{pickedUser?.name.slice(0, 2)}
{pickedUserWithEntryId.pickedUser?.name.slice(0, 2)}
</div>
<p className="user-name">{pickedUser?.name}</p>
<p className="user-name">{pickedUserWithEntryId.pickedUser?.name}</p>
</>
) : null
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/modal/picked-user-view/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CurrentUserData } from 'bigbluebutton-html-plugin-sdk';
import { PushEntryFunction } from 'bigbluebutton-html-plugin-sdk/dist/cjs/data-channel/types';
import { PickedUser } from '../../pick-random-user/types';
import { PushEntryFunction, ReplaceEntryFunction } from 'bigbluebutton-html-plugin-sdk/dist/cjs/data-channel/types';
import { PickedUser, PickedUserWithEntryId } from '../../pick-random-user/types';

export interface PickedUserViewComponentProps {
title: string;
pickedUser: PickedUser;
updatePickedRandomUser: ReplaceEntryFunction<PickedUser>;
pickedUserWithEntryId: PickedUserWithEntryId;
currentUser: CurrentUserData;
setShowPresenterView: React.Dispatch<React.SetStateAction<boolean>>;
dispatcherPickedUser: PushEntryFunction
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/presenter-view/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function PresenterViewComponent(props: PresenterViewComponentProps) {
deletionFunction,
handlePickRandomUser,
dataChannelPickedUsers,
pickedUser,
pickedUserWithEntryId,
users,
userRole,
} = props;
Expand Down Expand Up @@ -125,7 +125,7 @@ export function PresenterViewComponent(props: PresenterViewComponentProps) {
}}
>
{
(pickedUser) ? 'Pick again' : `Pick ${userRole}`
(pickedUserWithEntryId) ? 'Pick again' : `Pick ${userRole}`
}
</button>
) : (
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/presenter-view/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataChannelEntryResponseType } from 'bigbluebutton-html-plugin-sdk/dist/cjs/data-channel/types';
import { DeleteEntryFunction } from 'bigbluebutton-html-plugin-sdk';
import { PickedUser } from '../../pick-random-user/types';
import { PickedUser, PickedUserWithEntryId } from '../../pick-random-user/types';

export interface PresenterViewComponentProps {
filterOutPresenter: boolean;
Expand All @@ -10,7 +10,7 @@ export interface PresenterViewComponentProps {
deletionFunction: DeleteEntryFunction;
handlePickRandomUser: () => void;
dataChannelPickedUsers?: DataChannelEntryResponseType<PickedUser>[];
pickedUser: PickedUser;
pickedUserWithEntryId: PickedUserWithEntryId;
users?: PickedUser[];
userRole: string;
}
7 changes: 4 additions & 3 deletions src/components/modal/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { CurrentUserData, DeleteEntryFunction } from 'bigbluebutton-html-plugin-sdk';
import { DataChannelEntryResponseType, PushEntryFunction } from 'bigbluebutton-html-plugin-sdk/dist/cjs/data-channel/types';
import { PickedUser } from '../pick-random-user/types';
import { DataChannelEntryResponseType, PushEntryFunction, ReplaceEntryFunction } from 'bigbluebutton-html-plugin-sdk/dist/cjs/data-channel/types';
import { PickedUser, PickedUserWithEntryId } from '../pick-random-user/types';

export interface PickUserModalProps {
showModal: boolean;
updatePickedRandomUser: ReplaceEntryFunction<PickedUser>;
handleCloseModal: () => void;
users?: PickedUser[];
pickedUser: PickedUser;
pickedUserWithEntryId: PickedUserWithEntryId;
handlePickRandomUser: () => void;
currentUser: CurrentUserData;
filterOutPresenter: boolean,
Expand Down
28 changes: 20 additions & 8 deletions src/components/pick-random-user/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ModalInformationFromPresenter,
PickRandomUserPluginProps,
PickedUser,
PickedUserWithEntryId,
UsersMoreInformationGraphqlResponse,
} from './types';
import { USERS_MORE_INFORMATION } from './queries';
Expand All @@ -16,7 +17,9 @@ import ActionButtonDropdownManager from '../extensible-areas/action-button-dropd
function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
BbbPluginSdk.initialize(uuid);
const [showModal, setShowModal] = useState<boolean>(false);
const [pickedUser, setPickedUser] = useState<PickedUser | undefined>();
const [
pickedUserWithEntryId,
setPickedUserWithEntryId] = useState<PickedUserWithEntryId | undefined>();
const [userFilterViewer, setUserFilterViewer] = useState<boolean>(true);
const [filterOutPresenter, setFilterOutPresenter] = useState<boolean>(true);
const pluginApi: PluginApi = BbbPluginSdk.getPluginApi(uuid);
Expand All @@ -29,6 +32,7 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
const {
data: pickedUserFromDataChannelResponse,
pushEntry: pushPickedUser,
replaceEntry: updatePickedRandomUser,
deleteEntry: deletePickedUser,
} = pluginApi.useDataChannel<PickedUser>('pickRandomUser');
const {
Expand Down Expand Up @@ -94,18 +98,25 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
&& pickedUserFromDataChannel.data?.length > 0) {
const pickedUserToUpdate = pickedUserFromDataChannel
.data[0];
setPickedUser(pickedUserToUpdate?.payloadJson);
if (pickedUserToUpdate?.payloadJson) setShowModal(true);
if (pickedUserToUpdate?.entryId !== pickedUserWithEntryId?.entryId) {
setPickedUserWithEntryId({
pickedUser: pickedUserToUpdate?.payloadJson,
entryId: pickedUserToUpdate.entryId,
});
}
if (pickedUserToUpdate?.payloadJson && pickedUserToUpdate?.payloadJson.isPresenterViewing) {
setShowModal(true);
}
} else if (pickedUserFromDataChannel.data
&& pickedUserFromDataChannel.data?.length === 0) {
setPickedUser(null);
setPickedUserWithEntryId(null);
if (currentUser && !currentUser.presenter) setShowModal(false);
}
}, [pickedUserFromDataChannelResponse]);

useEffect(() => {
if (!pickedUser && !currentUser?.presenter) setShowModal(false);
}, [pickedUser]);
if (!pickedUserWithEntryId && !currentUser?.presenter) setShowModal(false);
}, [pickedUserWithEntryId]);

useEffect(() => {
if (!currentUser?.presenter && dispatchModalInformationFromPresenter) handleCloseModal();
Expand All @@ -117,21 +128,22 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
showModal,
handleCloseModal,
users: usersToBePicked?.user,
pickedUser,
pickedUserWithEntryId,
handlePickRandomUser,
currentUser,
filterOutPresenter,
setFilterOutPresenter,
userFilterViewer,
setUserFilterViewer,
dataChannelPickedUsers: pickedUserFromDataChannel.data,
updatePickedRandomUser,
dispatcherPickedUser: pushPickedUser,
deletionFunction: deletePickedUser,
}}
/>
<ActionButtonDropdownManager
{...{
pickedUser,
pickedUserWithEntryId,
currentUser,
pluginApi,
setShowModal,
Expand Down
6 changes: 6 additions & 0 deletions src/components/pick-random-user/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
export interface PickedUser {
isPresenterViewing: boolean;
presenter: boolean;
userId: string;
name: string;
role: string;
color: string;
}

export interface PickedUserWithEntryId {
pickedUser: PickedUser;
entryId: string;
}

export interface PickRandomUserPluginProps {
pluginName: string,
pluginUuid: string,
Expand Down
12 changes: 5 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ const pluginName = document.currentScript?.getAttribute('pluginName') || 'plugin

const root = ReactDOM.createRoot(document.getElementById(uuid));
root.render(
<React.StrictMode>
<PickRandomUserPlugin {...{
pluginUuid: uuid,
pluginName,
}}
/>
</React.StrictMode>,
<PickRandomUserPlugin {...{
pluginUuid: uuid,
pluginName,
}}
/>,
);