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 Apr 5, 2022
1 parent 86f5b7e commit fcb1a53
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 81 deletions.
12 changes: 6 additions & 6 deletions src/frontend/components/Button/ButtonLayout/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, screen } from '@testing-library/react';
import { ButtonLayout } from '.';

const Icon = jest.fn(() => <span>icon</span>);
const Badge = () => <span>badge</span>;
const badge = 'badge';

describe('<ButtonLayout />', () => {
afterEach(() => {
Expand All @@ -29,7 +29,7 @@ describe('<ButtonLayout />', () => {
it('does not render the badge if there is no Icon set', () => {
render(
<ButtonLayout
badge={<Badge />}
badge={badge}
label="Button"
reversedColor={'reversed-color'}
tintColor={'int-color'}
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('<ButtonLayout />', () => {
it('renders the icon and the badge and the title', () => {
render(
<ButtonLayout
badge={<Badge />}
badge={badge}
Icon={() => <span>icon</span>}
label="Button"
reversedColor={'reversed-color'}
Expand All @@ -78,7 +78,7 @@ describe('<ButtonLayout />', () => {
it('renders the Button component with default style', () => {
render(
<ButtonLayout
badge={<Badge />}
badge={badge}
Icon={Icon}
label="Button"
reversedColor={'#ffffff'}
Expand All @@ -96,7 +96,7 @@ describe('<ButtonLayout />', () => {
{
height: '100%',
iconColor: '#0a67de',
focusColor: 'none',
focusColor: undefined,
},
{},
);
Expand All @@ -107,7 +107,7 @@ describe('<ButtonLayout />', () => {
it('renders the Button component with reversed style', () => {
render(
<ButtonLayout
badge={<Badge />}
badge={badge}
Icon={Icon}
label="Button"
reversed
Expand Down
44 changes: 27 additions & 17 deletions src/frontend/components/Button/ButtonLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const IconBox = styled(Box)`

const TextBox = styled(Box)`
display: flex;
margin-top: 6px;
text-align: center;
`;

Expand All @@ -34,11 +33,14 @@ const StyledText = styled(Text)`
screenSize === 'small' ? '-0.3px' : '-0.13px'};
line-height: ${({ screenSize }: ResponsiveProps) =>
screenSize === 'small' ? '0.8rem' : '0.9rem'};
margin: auto;
`;

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

export interface ButtonLayoutSubComponentProps {
badge?: JSX.Element;
badge?: string;
Icon?: React.FC<SvgProps>;
label?: string;
}
Expand All @@ -61,29 +63,37 @@ export const ButtonLayout = ({
}: ButtonLayoutProps) => {
const size = useContext(ResponsiveContext);

let iconColor;
let rectColor;

if (!reversed) {
iconColor = tintColor;
rectColor = 'none';
} else {
iconColor = reversedColor;
rectColor = tintColor;
}
const iconColor = reversed ? reversedColor : tintColor;
const rectColor = reversed ? tintColor : undefined;

return (
<Box align="center" fill>
<Box align="center" flex height="100%">
{Icon && (
<IconBox screenSize={size}>
<Icon iconColor={iconColor} focusColor={rectColor} height="100%" />
{badge}
{badge && (
<Box
align="center"
background="white"
border={{
color: tintColor,
size: 'xsmall',
}}
pad={{ horizontal: '3px', vertical: '1px' }}
round="6px"
style={{ position: 'absolute', bottom: '0px', right: '0px' }}
>
<StyledTextBadge color={tintColor} size="0.688rem">
{badge}
</StyledTextBadge>
</Box>
)}
</IconBox>
)}

{label && (
<TextBox>
<StyledText color={textColor} screenSize={size} size=".8rem">
<TextBox align="center" margin={{ top: '6px' }}>
<StyledText color={textColor} screenSize={size}>
{label}
</StyledText>
</TextBox>
Expand Down
24 changes: 12 additions & 12 deletions src/frontend/components/Button/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { Button } from '.';

const Icon = jest.fn(() => <span>icon</span>);
const Badge = () => <span>badge</span>;
const badge = 'badge';

describe('<Button />', () => {
afterEach(() => {
Expand All @@ -28,14 +28,14 @@ describe('<Button />', () => {
});

it('does not render the badge if there is no Icon set', () => {
render(<Button label="Button" badge={<Badge />} />);
render(<Button label="Button" badge={badge} />);

screen.getByRole('button', { name: /Button/i });
expect(screen.queryByText('badge')).not.toBeInTheDocument();
});

it('renders the Button component with default style', () => {
render(<Button label="Button" Icon={Icon} badge={<Badge />} />);
render(<Button label="Button" Icon={Icon} badge={badge} />);

screen.getByRole('button', { name: /Button/i });

Expand All @@ -45,7 +45,7 @@ describe('<Button />', () => {
{
height: '100%',
iconColor: '#055fd2',
focusColor: 'none',
focusColor: undefined,
},
{},
);
Expand All @@ -54,7 +54,7 @@ describe('<Button />', () => {
});

it('renders the Button component with default style disabled', () => {
render(<Button label="Button" Icon={Icon} badge={<Badge />} disabled />);
render(<Button label="Button" Icon={Icon} badge={badge} disabled />);

screen.getByRole('button', { name: /Button/i });

Expand All @@ -64,7 +64,7 @@ describe('<Button />', () => {
{
height: '100%',
iconColor: '#81ade6',
focusColor: 'none',
focusColor: undefined,
},
{},
);
Expand All @@ -73,7 +73,7 @@ describe('<Button />', () => {
});

it('renders the Button component with default style hovered', () => {
render(<Button label="Button" Icon={Icon} badge={<Badge />} />);
render(<Button label="Button" Icon={Icon} badge={badge} />);

fireEvent.mouseEnter(screen.getByRole('button', { name: /Button/i }));

Expand All @@ -84,7 +84,7 @@ describe('<Button />', () => {
{
height: '100%',
iconColor: '#055fd2',
focusColor: 'none',
focusColor: undefined,
},
{},
);
Expand All @@ -102,7 +102,7 @@ describe('<Button />', () => {
});

it('renders the Button component with reversed style', () => {
render(<Button label="Button" Icon={Icon} badge={<Badge />} reversed />);
render(<Button label="Button" Icon={Icon} badge={badge} reversed />);

screen.getByRole('button', { name: /Button/i });

Expand All @@ -122,7 +122,7 @@ describe('<Button />', () => {

it('renders the Button component with reversed style disabled', () => {
render(
<Button label="Button" Icon={Icon} badge={<Badge />} disabled reversed />,
<Button label="Button" Icon={Icon} badge={badge} disabled reversed />,
);

screen.getByRole('button', { name: /Button/i });
Expand All @@ -142,7 +142,7 @@ describe('<Button />', () => {
});

it('renders the Button component with reversed style hovered', () => {
render(<Button label="Button" Icon={Icon} badge={<Badge />} reversed />);
render(<Button label="Button" Icon={Icon} badge={badge} reversed />);

fireEvent.mouseEnter(screen.getByRole('button'));

Expand All @@ -164,7 +164,7 @@ describe('<Button />', () => {
{
height: '100%',
iconColor: '#055fd2',
focusColor: 'none',
focusColor: undefined,
},
{},
);
Expand Down
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 @@ -18,7 +18,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 +33,11 @@ export const StudentHideViewersButton = () => {
return (
<Button
label={intl.formatMessage(messages.viewers)}
badge={
nbrOfOnStageRequests !== 0
? nbrOfOnStageRequests?.toString()
: undefined
}
Icon={ViewersSVG}
onClick={() => {
setPanelVisibility(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ 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 !== 0
? nbrOfOnStageRequests?.toString()
: 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
Loading

0 comments on commit fcb1a53

Please sign in to comment.