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

feat: storybook hooks docs #1010

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
7b56f48
fix: remove unused @param peerId from jsdoc
zakybilfagih Oct 12, 2022
26c42a8
fix: export pagination component from story
zakybilfagih Oct 12, 2022
98e22e3
fix: role should be roleName
zakybilfagih Oct 12, 2022
c2585cc
feat: add fake role on fake store
zakybilfagih Oct 12, 2022
86b5b26
feat: add more stub on storybooksdk reactsdk stub
zakybilfagih Oct 12, 2022
d0b9e72
feat: useAVToggle hook example
zakybilfagih Oct 12, 2022
8ad1b1c
feat: useCustomEvent example
zakybilfagih Oct 12, 2022
3611ad5
feat: useRemoteAVToggle example
zakybilfagih Oct 12, 2022
2b9148c
feat: useVideo example
zakybilfagih Oct 12, 2022
48703b7
feat: useVideoList example
zakybilfagih Oct 12, 2022
0c9ac1f
fix: useState dependency array errors
zakybilfagih Oct 12, 2022
2337b7c
fix: add type to custom event message
zakybilfagih Oct 12, 2022
8a37720
fix: remove unused block statement
zakybilfagih Oct 12, 2022
5e2049f
fix: move hooks stories to seperate folder
zakybilfagih Oct 17, 2022
233a82b
fix: move mdx file
zakybilfagih Oct 18, 2022
eec1050
feat: add useDevices hook
zakybilfagih Oct 18, 2022
e405300
feat: add useScreenShare hook
zakybilfagih Oct 18, 2022
6c619b0
feat: docs for av toogle
amar-1995 Oct 18, 2022
aaf15cd
fix: try to resolve hooks error (still not working)
zakybilfagih Oct 18, 2022
7b8fe39
feat: av toggle updated docs
amar-1995 Oct 18, 2022
3f80c31
fix: minor fixes
zakybilfagih Oct 18, 2022
7160974
fix: change text variant screenshare story
zakybilfagih Oct 18, 2022
e8ed15b
feat: add useParticipants hook
zakybilfagih Oct 18, 2022
6fe8627
fix: merge with latest remote
zakybilfagih Oct 18, 2022
32d9cd4
feat: add useVideo docs
zakybilfagih Oct 18, 2022
4ae95f3
feat: added interface to useAVToggle hook
zakybilfagih Oct 18, 2022
76026fe
feat: add useVideoList mdx
zakybilfagih Oct 18, 2022
db509e3
fix: move example above code snippet
zakybilfagih Oct 18, 2022
6478dae
feat: add useScreenShare mdx
zakybilfagih Oct 18, 2022
5d04c96
feat: add useDevices mdx
zakybilfagih Oct 18, 2022
19cefb0
feat: add useCustomEvent mdx
zakybilfagih Oct 18, 2022
7dabc0f
fix: updated and revert useAVToggle mdx
zakybilfagih Oct 18, 2022
ec71727
feat: stub foir useAutoPlayError hook
zakybilfagih Oct 18, 2022
254d4c4
feat: added docs of use participants
amar-1995 Oct 18, 2022
513de1a
feat: added docs block in stories
amar-1995 Oct 18, 2022
6432ff2
feat: added story for useautoplayError
amar-1995 Oct 18, 2022
23ddb19
feat: lint fix story for useautoplayError
amar-1995 Oct 18, 2022
d7c5b45
feat: docs update for remote av
amar-1995 Oct 19, 2022
180cbb3
feat: added stub storybook notification
zakybilfagih Oct 19, 2022
b3fb00e
feat: useAutoplayError
zakybilfagih Oct 19, 2022
0b0a4ec
fix: minor changes
zakybilfagih Oct 19, 2022
fd7eb53
fix: make icon name uniform
zakybilfagih Oct 19, 2022
8db3ace
fix: prettier error
zakybilfagih Oct 19, 2022
4cbfa39
fix: remove ts-ignore
zakybilfagih Oct 19, 2022
6546dbc
fix: av toogle docs update
amar-1995 Oct 20, 2022
d1e5edd
feat: added docs for useaudioLevelStyles
amar-1995 Oct 20, 2022
f9de301
feat: added docs for usePreviewjoin
amar-1995 Oct 20, 2022
ad9ab67
fix: minor style changes
zakybilfagih Oct 20, 2022
dd18ecf
feat: added stub for useAudioLevelStyles
zakybilfagih Oct 20, 2022
f6a7002
feat: added stub for usePreviewJoin
zakybilfagih Oct 20, 2022
6abffc5
fix: update mdx to current example
zakybilfagih Oct 20, 2022
984f7d6
fix: add the definition of DialogContent
zakybilfagih Oct 21, 2022
4641223
fix: wrap function in useCallback
zakybilfagih Oct 24, 2022
51a9d30
feat: added css reset on storybook entry file
zakybilfagih Oct 24, 2022
233cd62
fix: remove previous css on pagination
zakybilfagih Oct 24, 2022
bbd08cb
fix: added default font on select component
zakybilfagih Oct 24, 2022
d5956a5
fix: move pagination, center story
zakybilfagih Oct 24, 2022
0721770
fix: video list remove overflow
zakybilfagih Oct 26, 2022
91289df
fix: theme map merging
zakybilfagih Oct 26, 2022
0ff2f24
fix: remove value from effect deps
zakybilfagih Oct 26, 2022
89bfbd7
fix: fix not adding className
zakybilfagih Oct 26, 2022
0f31e86
Merge branch 'main' into feat/storybook-hooks
zakybilfagih Oct 26, 2022
4ebeb83
fix: dark mode styling issue
zakybilfagih Oct 26, 2022
7369a18
fix: eslint rule and prettier error
zakybilfagih Oct 26, 2022
a74dd6e
fix: try removing base css
zakybilfagih Oct 26, 2022
e8cb426
fix: change merging strategy
zakybilfagih Oct 26, 2022
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
1 change: 0 additions & 1 deletion packages/react-sdk/src/hooks/useRemoteAVToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const toggleTrackEnabled = async (

/**
* This hook can be used to implement remote mute/unmute + audio volume changer on tile level.
* @param peerId of the peer whose tracks need to be managed
* @param audioTrackId of the peer whose tracks need to be managed
* @param videoTrackId of the peer whose tracks need to be managed
* @param handleError to handle any error during toggle of audio/video
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/src/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function CheckboxWithLabelComponent({ label, checked = true, css, onCheckedChang

useEffect(() => {
handleOnCheckedChange(checked);
}, [checked]);
}, [checked, handleOnCheckedChange]);

function handleOnCheckedChange(checked: boolean) {
setInternalChecked(checked);
Expand Down
32 changes: 32 additions & 0 deletions packages/react-ui/src/Hooks/UseAVToggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { selectLocalVideoTrackID, useAVToggle, useHMSStore } from '@100mslive/react-sdk';
import Video, { StyledVideo } from '../Video/Video';
import React from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's follow the order of imports.

  1. react.
  2. third party react libs
  3. other third party libs
  4. local imports

import { ComponentStory } from '@storybook/react';

const VideoHook: ComponentStory<typeof StyledVideo> = () => {
const localVideoTrackID = useHMSStore(selectLocalVideoTrackID);
const { isLocalVideoEnabled, isLocalAudioEnabled, toggleVideo, toggleAudio } = useAVToggle();

return (
<div>
<button onClick={() => toggleVideo && toggleVideo()}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use IconButton here. It should be closer to the actual usage.

{isLocalVideoEnabled ? 'Disable video' : 'Enable video'}
</button>
<button onClick={() => toggleAudio && toggleAudio()}>
{isLocalAudioEnabled ? 'Disable audio' : 'Enable audio'}
</button>
<Video css={{ bg: '$backgroundDark' }} trackId={localVideoTrackID} />
</div>
);
};

const VideoStories = {
title: 'Hooks/useAVToggle',
component: VideoHook,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
};

export default VideoStories;

export const UseVideoHook = VideoHook.bind({});
UseVideoHook.storyName = 'useAVToggle';
46 changes: 46 additions & 0 deletions packages/react-ui/src/Hooks/UseCustomEvent.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { StyledVideo } from '../Video/Video';
import { ComponentStory } from '@storybook/react';
import { useCustomEvent } from '@100mslive/react-sdk';
import { useCallback, useState } from 'react';
import { Toast } from '../Toast/Toast';

const VideoHook: ComponentStory<typeof StyledVideo> = () => {
const [open, setOpen] = useState(false);
const [data, setData] = useState<{ emoji: string }>();

const handleEmojiReaction = useCallback((data: { emoji: string }) => {
setOpen(true);
setData(data);
}, []);

const { sendEvent } = useCustomEvent({
type: 'EMOJI_REACTION',
onEvent: handleEmojiReaction,
});

return (
<Toast.Provider>
<button onClick={() => sendEvent({ emoji: '🚀' })}>Rockets</button>
<Toast.HMSToast
title="EMOJI_REACTION"
description={JSON.stringify(data)}
open={open}
isClosable={true}
onOpenChange={o => setOpen(o)}
/>
<Toast.Viewport css={{ bottom: '$24' }} />
</Toast.Provider>
);
};

const VideoStories = {
title: 'Hooks/useCustomEvent',
component: VideoHook,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
};

export default VideoStories;

export const UseVideoHook = VideoHook.bind({});
UseVideoHook.storyName = 'useCustomEvent';
28 changes: 28 additions & 0 deletions packages/react-ui/src/Hooks/UseRemoteAVToggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useRemoteAVToggle } from '@100mslive/react-sdk';
import Video, { StyledVideo } from './Video';
import React from 'react';
import { ComponentStory } from '@storybook/react';

const VideoHook: ComponentStory<typeof StyledVideo> = () => {
const videoTrackId = '104';
const { isVideoEnabled, isAudioEnabled, toggleVideo, toggleAudio } = useRemoteAVToggle('1', videoTrackId);

return (
<div>
<button onClick={() => toggleVideo && toggleVideo()}>{isVideoEnabled ? 'Disable video' : 'Enable video'}</button>
<button onClick={() => toggleAudio && toggleAudio()}>{isAudioEnabled ? 'Disable audio' : 'Enable audio'}</button>
<Video css={{ bg: '$backgroundDark' }} trackId={videoTrackId} />
</div>
);
};

const VideoStories = {
title: 'Hooks/useRemoteAVToggle',
component: VideoHook,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
};

export default VideoStories;

export const UseVideoHook = VideoHook.bind({});
UseVideoHook.storyName = 'useRemoteAVToggle';
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useVideo } from '@100mslive/react-sdk';
import { StyledVideo } from './Video';
import { StyledVideo } from '../Video/Video';
import UseVideoDocs from './UseVideo.mdx';
import React from 'react';
import { ComponentStory } from '@storybook/react';

const VideoHook = () => {
const VideoHook: ComponentStory<typeof StyledVideo> = () => {
const { videoRef } = useVideo({
trackId: '1',
});
return <StyledVideo ref={videoRef} autoPlay playsInline muted />;

return <StyledVideo css={{ bg: '$backgroundDark' }} ref={videoRef} autoPlay muted />;
};

const VideoStories = {
title: 'Rendering Video/useVideo hook',
title: 'Hooks/useVideo',
component: VideoHook,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
parameters: {
Expand All @@ -24,3 +26,4 @@ const VideoStories = {
export default VideoStories;

export const UseVideoHook = VideoHook.bind({});
UseVideoHook.storyName = 'useVideo';
4 changes: 2 additions & 2 deletions packages/react-ui/src/Pagination/StyledPagination.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type PaginationProps = {
numPages: number;
};

const PaginationComponent = ({ page: propsPage, setPage: propsSetPage, numPages }: PaginationProps) => {
export const PaginationComponent = ({ page: propsPage, setPage: propsSetPage, numPages }: PaginationProps) => {
const [page, setPage] = useState(propsPage);

const disableLeft = page === 0;
Expand All @@ -31,7 +31,7 @@ const PaginationComponent = ({ page: propsPage, setPage: propsSetPage, numPages

useEffect(() => {
handlePageChange(propsPage);
}, [propsPage]);
}, [propsPage, handlePageChange]);

return (
<StyledPagination.Root>
Expand Down
21 changes: 12 additions & 9 deletions packages/react-ui/src/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';

import { Tabs } from '.';
Expand All @@ -22,19 +22,22 @@ const Template: ComponentStory<typeof Tabs.Root> = ({
}) => {
const [value, setValue] = useState('tab1');

function handleOnValueChange(value: string) {
setValue(value);
if (propOnValueChange) {
propOnValueChange(value);
}
}
const handleOnValueChange = useCallback(
(value: string) => {
setValue(value);
if (propOnValueChange) {
propOnValueChange(value);
}
},
[setValue, propOnValueChange],
);

useEffect(() => {
handleOnValueChange(propValue);
if (propOnValueChange) {
propOnValueChange(value);
}
}, [propValue]);
}, [propValue, handleOnValueChange, propOnValueChange, value]);

return (
<Tabs.Root
Expand Down Expand Up @@ -72,4 +75,4 @@ const Template: ComponentStory<typeof Tabs.Root> = ({
};

export const Example = Template.bind({});
Example.storyName = 'Tabs'
Example.storyName = 'Tabs';
20 changes: 16 additions & 4 deletions packages/react-ui/src/VideoList/VideoList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, { useState } from 'react';
import { MicOffIcon } from '@100mslive/react-icons';
import { selectPeers, useHMSStore, useVideoList } from '@100mslive/react-sdk';
import {
selectPeers,
useHMSStore,
useVideoList,
} from '@100mslive/react-sdk';
import { StyledVideoList } from './StyledVideoList';
import { StyledVideoTile } from '../VideoTile';
import Video from '../Video/Video';
import { getLeft } from './videoListUtils';
import { ComponentStory } from '@storybook/react';
import { PaginationComponent as Pagination } from '../Pagination/StyledPagination.stories';

const VideoListMeta = {
title: 'Video/VideoList',
title: 'Hooks/useVideoList',
};

export default VideoListMeta;
Expand Down Expand Up @@ -42,13 +47,14 @@ interface VideoListProps {

const VideoListStory: React.FC<VideoListProps> = ({ maxTileCount, aspectRatio }) => {
const peers = useHMSStore(selectPeers);
const [page] = useState(0);
const [page, setPage] = useState(0);
const { ref, pagesWithTiles } = useVideoList({
peers,
offsetY: 50,
maxTileCount,
aspectRatio,
});

return (
<StyledVideoList.Root css={{ height: '100vh', width: '100%' }} ref={ref}>
<StyledVideoList.Container>
Expand All @@ -63,7 +69,7 @@ const VideoListStory: React.FC<VideoListProps> = ({ maxTileCount, aspectRatio })
{tiles.map((tile, i) =>
tile.track?.source === 'screen' ? null : (
<VideoTile
key={tile.track?.id || tile.peer.id + i}
key={i}
width={tile.width}
height={tile.height}
trackId={tile.track?.id || ''}
Expand All @@ -75,13 +81,19 @@ const VideoListStory: React.FC<VideoListProps> = ({ maxTileCount, aspectRatio })
))
: null}
</StyledVideoList.Container>
<div>
{pagesWithTiles.length > 1 ? (
<Pagination page={page} setPage={setPage} numPages={pagesWithTiles.length} />
) : null}
</div>
</StyledVideoList.Root>
);
};

const Template: ComponentStory<typeof VideoListStory> = args => <VideoListStory {...args} />;

export const Example = Template.bind({});
Example.storyName = 'useVideoList';

Example.args = {
maxTileCount: 2,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/src/fixtures/peers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HMSPeerWithMuteStatus } from '@100mslive/hms-video-store';

let counter = 1;
let counter = 0;
export const makeFakeParticipant = (name: string, role = 'Student') => {
return {
peer: {
id: String(counter++),
name,
role: role,
roleName: role,
auxiliaryTracks: [],
isLocal: counter === 1,
},
Expand Down
10 changes: 9 additions & 1 deletion packages/react-ui/src/store/SetupFakeStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HMSReactiveStore, HMSStore, createDefaultStoreState } from '@100mslive/react-sdk';
import { HMSReactiveStore, HMSStore, createDefaultStoreState, HMSRole } from '@100mslive/react-sdk';
import create from 'zustand';
import { fakeMessages } from '../fixtures/chats';
import { fakeParticipants } from '../fixtures/peers';
Expand Down Expand Up @@ -29,4 +29,12 @@ export function setUpFakeStore() {
fakeMessages.forEach(msg => {
storyBookSDK.sendBroadcastMessage(msg.message);
});
storyBookSDK.setRoles({
Teacher: {
name: 'Teacher',
publishParams: { allowed: ['audio', 'video', 'screen'] },
subscribeParams: {},
permissions: { changeRole: true, unmute: true, mute: true },
} as HMSRole,
});
}
Loading