Skip to content

Commit

Permalink
✨(front) add a badge on viewers list button
Browse files Browse the repository at this point in the history
This badge indicates how many students are actually requesting to go on stage.
  • Loading branch information
roro-lv committed Mar 30, 2022
1 parent 108ab95 commit 13147ed
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 47 deletions.
10 changes: 9 additions & 1 deletion src/frontend/components/Button/ButtonLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const IconBox = styled(Box)`
text-align: center;
`;

const BadgeBox = styled(Box)`
bottom: 15px;
left: 25px;
position: relative;
`;

const TextBox = styled(Box)`
display: flex;
margin-top: 6px;
Expand Down Expand Up @@ -77,7 +83,9 @@ export const ButtonLayout = ({
{Icon && (
<IconBox screenSize={size}>
<Icon iconColor={iconColor} focusColor={rectColor} height="100%" />
{badge}
<BadgeBox direction="row" align="start">
{badge}
</BadgeBox>
</IconBox>
)}

Expand Down
33 changes: 33 additions & 0 deletions src/frontend/components/LiveControls/BadgeNotification/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box, Text } from 'grommet';
import React from 'react';
import styled from 'styled-components';

const StyledText = styled(Text)`
font-family: 'Roboto-Bold';
`;

interface BadgeNotificationProps {
color: string;
nbrOfNotifications: number;
}
export const BadgeNotification = ({
color,
nbrOfNotifications,
}: BadgeNotificationProps) => {
return (
<Box
align="center"
background="white"
border={{
color,
size: 'xsmall',
}}
pad={{ horizontal: '3px', vertical: '1px' }}
round="6px"
>
<StyledText color={color} size="0.688rem">
{nbrOfNotifications}
</StyledText>
</Box>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { defineMessages, useIntl } from 'react-intl';

import { Button } from 'components/Button';
import { BadgeNotification } from 'components/LiveControls/BadgeNotification';
import { ViewersSVG } from 'components/SVGIcons/ViewersSVG';
import { useLivePanelState } from 'data/stores/useLivePanelState';

Expand All @@ -18,7 +19,13 @@ const messages = defineMessages({
},
});

export const StudentHideViewersButton = () => {
interface StudentHideViewersButtonProps {
nbrOfOnStageRequests?: number;
}

export const StudentHideViewersButton = ({
nbrOfOnStageRequests,
}: StudentHideViewersButtonProps) => {
const intl = useIntl();
const { setPanelVisibility } = useLivePanelState((state) => ({
setPanelVisibility: state.setPanelVisibility,
Expand All @@ -27,6 +34,14 @@ export const StudentHideViewersButton = () => {
return (
<Button
label={intl.formatMessage(messages.viewers)}
badge={
nbrOfOnStageRequests ? (
<BadgeNotification
color="blue-focus"
nbrOfNotifications={nbrOfOnStageRequests}
/>
) : undefined
}
Icon={ViewersSVG}
onClick={() => {
setPanelVisibility(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { defineMessages, useIntl } from 'react-intl';

import { Button } from 'components/Button';
import { BadgeNotification } from 'components/LiveControls/BadgeNotification';
import { ViewersSVG } from 'components/SVGIcons/ViewersSVG';
import {
LivePanelItem,
Expand All @@ -21,14 +22,27 @@ const messages = defineMessages({
},
});

export const StudentShowViewersButton = () => {
interface StudentShowViewersButtonProps {
nbrOfOnStageRequests?: number;
}
export const StudentShowViewersButton = ({
nbrOfOnStageRequests,
}: StudentShowViewersButtonProps) => {
const intl = useIntl();
const { setPanelVisibility } = useLivePanelState((state) => ({
setPanelVisibility: state.setPanelVisibility,
}));

return (
<Button
badge={
nbrOfOnStageRequests ? (
<BadgeNotification
color="blue-active"
nbrOfNotifications={nbrOfOnStageRequests}
/>
) : undefined
}
label={intl.formatMessage(messages.viewers)}
Icon={ViewersSVG}
onClick={() => {
Expand Down
19 changes: 15 additions & 4 deletions src/frontend/components/LiveControls/ViewersWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ import {
LivePanelItem,
useLivePanelState,
} from 'data/stores/useLivePanelState';

import { Video } from 'types/tracks';
import { StudentHideViewersButton } from './StudentHideViewersButton';
import { StudentShowViewersButton } from './StudentShowViewersButton';

export const ViewersWrapper = () => {
interface ViewersWrapperProps {
video?: Video;
}

export const ViewersWrapper = ({ video }: ViewersWrapperProps) => {
const { currentItem, isPanelVisible } = useLivePanelState((state) => ({
currentItem: state.currentItem,
isPanelVisible: state.isPanelVisible,
}));

const nbrOfOnStageRequests =
video && video.participants_asking_to_join.length;

if (currentItem === LivePanelItem.VIEWERS_LIST && isPanelVisible) {
return <StudentHideViewersButton />;
return (
<StudentHideViewersButton nbrOfOnStageRequests={nbrOfOnStageRequests} />
);
} else {
return <StudentShowViewersButton />;
return (
<StudentShowViewersButton nbrOfOnStageRequests={nbrOfOnStageRequests} />
);
}
};
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/frontend/components/TeacherLiveControlBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const TeacherLiveControlBar = ({

{availableItems.includes(LivePanelItem.VIEWERS_LIST) && (
<Box height="100%" style={{ minWidth: '60px' }}>
<ViewersWrapper />
<ViewersWrapper video={video} />
</Box>
)}

Expand Down
76 changes: 37 additions & 39 deletions src/frontend/components/ViewersList/InstructorViewersList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,46 +80,44 @@ export const InstructorViewersList = ({
pad={{ bottom: '20px', top: '30px' }}
>
{video.participants_asking_to_join.length !== 0 && (
<React.Fragment>
<ViewersListHeader
margin={{ left: '20px', bottom: '6px' }}
text={intl.formatMessage(messages.demands)}
/>
<List
border={false}
data={video.participants_asking_to_join.sort(
(participantA, participantB) =>
participantA.name.localeCompare(participantB.name),
)}
pad="none"
>
{(item: ParticipantType, index: number) => (
<ViewersListItemContainer key={index}>
<ViewersListItem
isInstructor={item.isInstructor}
name={item.name}
<React.Fragment>
<ViewersListHeader
margin={{ left: '20px', bottom: '6px' }}
text={intl.formatMessage(messages.demands)}
/>
<List
border={false}
data={video.participants_asking_to_join.sort(
(participantA, participantB) =>
participantA.name.localeCompare(participantB.name),
)}
pad="none"
>
{(item: ParticipantType, index: number) => (
<ViewersListItemContainer key={index}>
<ViewersListItem
isInstructor={item.isInstructor}
name={item.name}
/>
<Box direction="row" align="center" gap="10px">
<Button
icon={<AddCircle color="red-active" size="20px" />}
onClick={() => converse.rejectParticipantToJoin(item)}
plain
style={{ padding: '0px', transform: 'rotate(45deg)' }}
/>
<ViewersListTextButton
onClick={() =>
converse.acceptParticipantToJoin(item, video)
}
text={intl.formatMessage(messages.acceptButton)}
/>
<Box direction="row" align="center" gap="10px">
<Button
icon={<AddCircle color="red-active" size="20px" />}
onClick={() =>
converse.rejectParticipantToJoin(item)
}
plain
style={{ padding: '0px', transform: 'rotate(45deg)' }}
/>
<ViewersListTextButton
onClick={() =>
converse.acceptParticipantToJoin(item, video)
}
text={intl.formatMessage(messages.acceptButton)}
/>
</Box>
</ViewersListItemContainer>
)}
</List>
</React.Fragment>
)}
</Box>
</ViewersListItemContainer>
)}
</List>
</React.Fragment>
)}

{participantsOnStage.length !== 0 && (
<React.Fragment>
Expand Down

0 comments on commit 13147ed

Please sign in to comment.